diff --git a/config.json.sample b/config.json.sample index 79cc137..043afd6 100644 --- a/config.json.sample +++ b/config.json.sample @@ -8,7 +8,8 @@ "password": "lolturtles", "channels": [ "#realitest" - ] + ], + "admin_channel": "#realitest" } }, "admins": [ "batman" ], diff --git a/modules/admin/commands.js b/modules/admin/commands.js index beb9119..2cef092 100644 --- a/modules/admin/commands.js +++ b/modules/admin/commands.js @@ -8,7 +8,7 @@ var commands = function(dbot) { var commands = { // Join a channel - 'join': function(event) { + '~join': function(event) { var channel = event.params[1]; if(_.has(event.allChannels, channel)) { event.reply(dbot.t('already_in_channel', {'channel': channel})); @@ -19,7 +19,7 @@ var commands = function(dbot) { }, // Leave a channel - 'part': function(event) { + '~part': function(event) { var channel = event.params[1]; if(!_.has(event.allChannels, channel)) { event.reply(dbot.t('not_in_channel', {'channel': channel})); @@ -30,7 +30,7 @@ var commands = function(dbot) { }, // Op admin caller in given channel - 'opme': function(event) { + '~opme': function(event) { var channel = event.params[1]; // If given channel isn't valid just op in current one. @@ -41,12 +41,12 @@ var commands = function(dbot) { }, // Do a git pull and reload - 'greload': function(event) { + '~greload': function(event) { exec("git pull", function (error, stdout, stderr) { exec("git submodule update", function (error, stdout, stderr) { event.reply(dbot.t('gpull')); - commands.reload(event); - event.message = 'version'; + commands['~reload'](event); + event.message = '~version'; event.action = 'PRIVMSG'; event.params = event.message.split(' '); dbot.instance.emit(event); @@ -55,7 +55,7 @@ var commands = function(dbot) { }, // Display commit information for part of dbot - 'version': function(event){ + '~version': function(event){ var cmd = "git log --pretty=format:'%h (%s): %ar' -n 1 -- "; if(event.params[1]){ var input = event.params[1].trim(); @@ -77,7 +77,7 @@ var commands = function(dbot) { }.bind(this)); }, - 'status': function(event) { + '~status': function(event) { var moduleName = event.params[1]; if(_.has(dbot.status, moduleName)) { var status = dbot.status[moduleName]; @@ -98,7 +98,7 @@ var commands = function(dbot) { }, // Reload DB, translations and modules. - 'reload': function(event) { + '~reload': function(event) { dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8')); dbot.reloadModules(); process.nextTick(function() { @@ -107,7 +107,7 @@ var commands = function(dbot) { }, // Say something in a channel - 'say': function(event) { + '~say': function(event) { var channel = event.params[1]; if(event.params[1] === "@") { channel = event.channel.name; @@ -117,7 +117,7 @@ var commands = function(dbot) { }, // Load new module - 'load': function(event) { + '~load': function(event) { var moduleName = event.params[1]; if(!_.include(dbot.config.moduleNames, moduleName)) { dbot.customConfig.moduleNames.push(moduleName); @@ -140,7 +140,7 @@ var commands = function(dbot) { }, // Unload a loaded module - 'unload': function(event) { + '~unload': function(event) { var moduleNames = dbot.config.moduleNames; var moduleName = event.params[1]; if(_.include(moduleNames, moduleName)) { @@ -164,7 +164,7 @@ var commands = function(dbot) { /*** Config options ***/ - 'setconfig': function(event) { + '~setconfig': function(event) { var configPath = event.input[1], newOption = event.input[2]; @@ -198,7 +198,7 @@ var commands = function(dbot) { } }, - 'pushconfig': function(event) { + '~pushconfig': function(event) { var configPath = event.input[1], newOption = event.input[2]; @@ -221,7 +221,7 @@ var commands = function(dbot) { } }, - 'showconfig': function(event) { + '~showconfig': function(event) { var configPath = event.params[1]; if(configPath) { this.internalAPI.getCurrentConfig(configPath, function(config) { @@ -250,7 +250,6 @@ var commands = function(dbot) { this.commands['showconfig'](event); } }.bind(this)); - } else { event.reply(dbot.t("config_keys_location", { "path": "root", @@ -259,7 +258,7 @@ var commands = function(dbot) { } }, - 'savemodules': function(event) { + '~savemodules': function(event) { fs.readFile('config.json', 'utf-8', function(err, config) { config = JSON.parse(config); config.moduleNames = _.keys(dbot.modules); @@ -274,14 +273,14 @@ var commands = function(dbot) { command.access = 'admin'; }); - commands['showconfig'].access = 'moderator'; - commands['join'].access = 'moderator'; - commands['part'].access = 'moderator'; - commands['opme'].access = 'moderator'; - commands['say'].access = 'moderator'; + commands['~showconfig'].access = 'moderator'; + commands['~join'].access = 'moderator'; + commands['~part'].access = 'moderator'; + commands['~opme'].access = 'moderator'; + commands['~say'].access = 'moderator'; - commands['pushconfig'].regex = [/pushconfig ([^ ]+) ([^ ]+)/, 3]; - commands['setconfig'].regex = [/setconfig ([^ ]+) ([^ ]+)/, 3]; + commands['~pushconfig'].regex = [/~pushconfig ([^ ]+) ([^ ]+)/, 3]; + commands['~setconfig'].regex = [/~setconfig ([^ ]+) ([^ ]+)/, 3]; return commands; }; diff --git a/modules/poll/strings.json b/modules/poll/strings.json index 89472bd..497d48c 100644 --- a/modules/poll/strings.json +++ b/modules/poll/strings.json @@ -79,7 +79,7 @@ "na'vi": "{user}: ngaru '{name}' sìpawm sna'o ke lu.", "cy": "{user}: Nid ydech chi'n berchen y pôl '{name}'.", "nl": "{user}: Je bent niet de eigenaar van de poll '{name}'.", - "de": "{user}: "Du darfst die Umfrage '{name}' nicht verändern." + "de": "{user}: Du darfst die Umfrage '{name}' nicht verändern." }, "option_removed": { "en": "{user}: '{option}' removed from '{name}'", diff --git a/modules/warning/config.json b/modules/warning/config.json new file mode 100644 index 0000000..914c1d7 --- /dev/null +++ b/modules/warning/config.json @@ -0,0 +1,4 @@ +{ + "dependencies": [ "report", "users", "web" ], + "dbKeys": [ "warnings" ] +} diff --git a/modules/warning/pages.js b/modules/warning/pages.js new file mode 100644 index 0000000..e60a634 --- /dev/null +++ b/modules/warning/pages.js @@ -0,0 +1,47 @@ +var _ = require('underscore')._; + +var pages = function(dbot) { + this.warnings = dbot.db.warnings; + + return { + '/warning': function(req, res) { + res.render('servers', { + 'name': dbot.config.name, + 'servers': _.keys(this.warnings) + }); + }, + + '/warning/:server': function(req, res) { + var server = req.params.server; + + if(_.has(this.warnings, server)) { + res.render('users', { + 'name': dbot.config.name, + 'server': server, + 'users': _.keys(this.warnings[server]) + }); + } else { + res.render('error'); + } + }, + + '/warning/:server/:user': function(req, res) { + var server = req.params.server, + user = req.params.user; + + if(_.has(this.warnings, server) && _.has(this.warnings[server], user)) { + res.render('warnings', { + 'name': dbot.config.name, + 'server': server, + 'warnings': this.warnings[server][user] + }); + } else { + res.render('error'); + } + } + }; +}; + +exports.fetch = function(dbot) { + return pages(dbot); +}; diff --git a/modules/warning/strings.json b/modules/warning/strings.json new file mode 100644 index 0000000..c4abcab --- /dev/null +++ b/modules/warning/strings.json @@ -0,0 +1,11 @@ +{ + "no_warnings": { + "en": "No warnings found for {user}." + }, + "warning_info": { + "en": "{user} has {num} warnings. More info can be found at {url}" + }, + "warn_notify": { + "en": "Attention: {warner} has issued a warning to {warnee} for \"{reason}.\" More info can be found at {url}" + } +} diff --git a/modules/warning/warning.js b/modules/warning/warning.js new file mode 100644 index 0000000..cbea752 --- /dev/null +++ b/modules/warning/warning.js @@ -0,0 +1,61 @@ +var _ = require('underscore')._; + +var warning = function(dbot) { + this.warnings = dbot.db.warnings; + + this.commands = { + '~warn': function(event) { + var warner = event.user, + server = event.server, + warnee = dbot.api.users.resolveUser(server, event.input[1]), + reason = event.input[2], + adminChannel = dbot.config.servers[server].admin_channel; + + // Store the warn + if(!_.has(this.warnings, server)) this.warnings[server] = {}; + if(!_.has(this.warnings[server], warnee)) this.warnings[server][warnee] = []; + + this.warnings[server][warnee].push({ + 'warner': warner, + 'reason': reason, + 'time': new Date().getTime() + }); + + // Notify interested parties + var notifyString = dbot.t('warn_notify', { + 'warner': warner, + 'warnee': warnee, + 'reason': reason, + 'url': dbot.api.web.getUrl('warning/' + server + '/' + warnee) + }); + if(!_.isUndefined(adminChannel)) { + adminChannel = event.channel.name; + } + dbot.api.report.notify(server, adminChannel, notifyString); + dbot.say(server, adminChannel, notifyString); + dbot.say(server, warnee, notifyString); + }, + + '~warnings': function(event) { + var warnee = event.params[1], + server = event.server; + + if(_.has(this.warnings, server) && _.has(this.warnings[server], warnee)) { + event.reply(dbot.t('warning_info', { + 'user': warnee, + 'num': this.warnings[server][warnee].length, + 'url': dbot.api.web.getUrl('warning/' + server + '/' + warnee) + })); + } else { + event.reply(dbot.t('no_warnings', { 'user': warnee })); + } + } + }; + + this.commands['~warn'].regex = [/~warn ([^ ]+) (.+)/, 3]; + this.commands['~warn'].access = 'moderator'; +}; + +exports.fetch = function(dbot) { + return new warning(dbot); +}; diff --git a/views/users/channels.jade b/views/users/channels.jade index bb3cac4..62911f9 100644 --- a/views/users/channels.jade +++ b/views/users/channels.jade @@ -3,7 +3,7 @@ extends ../layout block content h3 Channels on #{connection} div#backlink - a(href='/connections') « Connection List + a(href='/users') « Connection List ul#quotelist -each channel in channels a(href='/users/'+connection+'/'+encodeURIComponent(channel)) diff --git a/views/warning/servers.jade b/views/warning/servers.jade new file mode 100644 index 0000000..146fe12 --- /dev/null +++ b/views/warning/servers.jade @@ -0,0 +1,10 @@ +extends ../layout + +block content + h3 Servers + div#backlink + a(href='/') « Home + ul#quotelist + -each server in servers + a(href='/warning/'+server) + li.quotes #{server} diff --git a/views/warning/users.jade b/views/warning/users.jade new file mode 100644 index 0000000..2a108f9 --- /dev/null +++ b/views/warning/users.jade @@ -0,0 +1,10 @@ +extends ../layout + +block content + h3 Users with warnings on #{server} + div#backlink + a(href='/warning') « Server List + ul#quotelist + -each user in users + a(href='/warning/'+server+'/'+user) + li.quotes #{user} diff --git a/views/warning/warnings.jade b/views/warning/warnings.jade new file mode 100644 index 0000000..18bfc70 --- /dev/null +++ b/views/warning/warnings.jade @@ -0,0 +1,19 @@ +extends ../layout + +block content + div#backlink + a(href='/warning/'+server) « Server Warnings + p + div#profile_datatable + table.table.table-hover.data + thead + tr + th Date + th Warner + th Reason + tbody + for warning, key in warnings + tr + td #{new Date(warning.time)} + td #{warning.warner} + td #{warning.reason}