<commit_before>'use strict';

var co = require('co');
var util = require('util');
var logger = require('winston');
var md = require('../../../markdown');
var message = require('../../../message');

var app = require.main.exports;
var bot = app.bot;
var config = app.config;
var db = app.db;

function exec(cmd) {

    return co(function* () {

        var msg = cmd.msg;
        var args = cmd.args;

        var role;
        var server = msg.server || app.defaultServer;

        if(args.length === 0) {
            // send a list of SARs
            var toSend = ["Current SARs:\n"];

            var rc = db.collection(config.modules.role.collection).find().sort("alias");
            while(yield rc.hasNext()) {
                role = yield rc.next();
                toSend.push("```" +cmd.format + "\n" +
                    "Alias: " + role.alias + "\n" +
                    " Role: " + role.name + "\n" +
                    " Desc: " + (role.desc || "") + "```"
                );
            }

            return message.send(msg, toSend, cmd.isPublic);
        }

        switch (args.shift().toLowerCase()) {
            case 'add':
                args = args.join(" ").split(";");

                if (args.length < 2) {
                    return message.send(msg, "syntax: add role;alias[;description]", cmd.isPublic, 10000);
                }

                role = {
                    name : args[0],
                    alias : args[1],
                    desc : args[2]
                }

                // check if the role exists
                if (!server.roles.get("name", role.name)) {
                    return message.send(msg, "role `" + role.name + "` not found on server: `"+server.name+"`", cmd.isPublic, 10000);
                }

                // add the role alias
                yield db.collection(config.modules.role.collection).updateOne(
                    { name: role.name },{ $set: role },
                    { upsert: true }
                );

                return message.send(msg, "SAR `" + role.alias + "` for role `" + role.name + "` added", isPublic);
            case 'del':
                if (args.length === 0) {
                    // send a list of roles:
                    return message.send(msg, "No alias specified", isPublic, 10000);
                }

                var alias = args[0];

                if(yield db.collection(config.modules.role.collection.deleteOne({ alias : alias }))) {
                    return message.send(msg, "SAR `" + alias + "` deleted", isPublic);
                } else {
                    return message.send(msg, "Cannot find alias `" + alias + "`", isPublic);
                }
        }<commit_msg>Fixed public error in sar<commit_after>'use strict';

var co = require('co');
var util = require('util');
var logger = require('winston');
var md = require('../../../markdown');
var message = require('../../../message');

var app = require.main.exports;
var bot = app.bot;
var config = app.config;
var db = app.db;

function exec(cmd) {

    return co(function* () {

        var msg = cmd.msg;
        var args = cmd.args;

        var role;
        var server = msg.server || app.defaultServer;

        if(args.length === 0) {
            // send a list of SARs
            var toSend = ["Current SARs:\n"];

            var rc = db.collection(config.modules.role.collection).find().sort("alias");
            while(yield rc.hasNext()) {
                role = yield rc.next();
                toSend.push("```" +cmd.format + "\n" +
                    "Alias: " + role.alias + "\n" +
                    " Role: " + role.name + "\n" +
                    " Desc: " + (role.desc || "") + "```"
                );
            }

            return message.send(msg, toSend, cmd.isPublic);
        }

        switch (args.shift().toLowerCase()) {
            case 'add':
                args = args.join(" ").split(";");

                if (args.length < 2) {
                    return message.send(msg, "syntax: add role;alias[;description]", cmd.isPublic, 10000);
                }

                role = {
                    name : args[0],
                    alias : args[1],
                    desc : args[2]
                }

                // check if the role exists
                if (!server.roles.get("name", role.name)) {
                    return message.send(msg, "role `" + role.name + "` not found on server: `"+server.name+"`", cmd.isPublic, 10000);
                }

                // add the role alias
                yield db.collection(config.modules.role.collection).updateOne(
                    { name: role.name },{ $set: role },
                    { upsert: true }
                );

                return message.send(msg, "SAR `" + role.alias + "` for role `" + role.name + "` added", cmd.isPublic);
            case 'del':
                if (args.length === 0) {
                    // send a list of roles:
                    return message.send(msg, "No alias specified", cmd.isPublic, 10000);
                }

                var alias = args[0];

                if(yield db.collection(config.modules.role.collection.deleteOne({ alias : alias }))) {
                    return message.send(msg, "SAR `" + alias + "` deleted", cmd.isPublic);
                } else {
                    return message.send(msg, "Cannot find alias `" + alias + "`", cmd.isPublic);
                }
        }
{'fraction_non_alphanumeric': 0.1526913218601245, 'fraction_numerical': 0.008055657268399853, 'mean_word_length': 1.3436293436293436, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7368892', 'n_tokens_mistral': 1597, 'n_tokens_neox': 1439, 'n_words': 368}