From 7d79d2330f842ae1a8f7f0e2aabe85ee78c4bd64 Mon Sep 17 00:00:00 2001 From: reality Date: Wed, 19 Jun 2013 00:06:52 +0000 Subject: [PATCH 1/6] initial support for warnings without web component [#506] --- config.json.sample | 3 +- modules/warning/config.json | 4 +++ modules/warning/pages.js | 43 +++++++++++++++++++++++++ modules/warning/strings.json | 11 +++++++ modules/warning/warning.js | 61 ++++++++++++++++++++++++++++++++++++ 5 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 modules/warning/config.json create mode 100644 modules/warning/pages.js create mode 100644 modules/warning/strings.json create mode 100644 modules/warning/warning.js 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/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..d3bea78 --- /dev/null +++ b/modules/warning/pages.js @@ -0,0 +1,43 @@ +var _ = require('underscore')._; + +var pages = function(dbot) { + return { + '/warnings': function(req, res) { + res.render('warnings_servers', { + 'name': dbot.config.name, + 'servers': _.keys(this.warnings) + }); + }, + + '/warnings/:server': function(req, res) { + var server = req.params.server; + + if(_.has(this.warnings, server)) { + res.render('warnings_users', { + 'name': dbot.config.name, + 'users': _.keys(this.warnings[server]) + }); + } else { + res.render('error'); + } + }, + + '/warnings/: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, + '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..51c48db --- /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('warnings/' + 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('warnings/' + 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); +}; From ce2f3c99d9412460c9eeb15a86df091355ce9635 Mon Sep 17 00:00:00 2001 From: reality Date: Wed, 19 Jun 2013 20:00:35 +0000 Subject: [PATCH 2/6] basic web thing for the warnings module [#506] --- modules/warning/pages.js | 16 ++++++++++------ modules/warning/warning.js | 4 ++-- views/users/channels.jade | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/modules/warning/pages.js b/modules/warning/pages.js index d3bea78..e60a634 100644 --- a/modules/warning/pages.js +++ b/modules/warning/pages.js @@ -1,20 +1,23 @@ var _ = require('underscore')._; var pages = function(dbot) { + this.warnings = dbot.db.warnings; + return { - '/warnings': function(req, res) { - res.render('warnings_servers', { + '/warning': function(req, res) { + res.render('servers', { 'name': dbot.config.name, 'servers': _.keys(this.warnings) }); }, - '/warnings/:server': function(req, res) { + '/warning/:server': function(req, res) { var server = req.params.server; if(_.has(this.warnings, server)) { - res.render('warnings_users', { + res.render('users', { 'name': dbot.config.name, + 'server': server, 'users': _.keys(this.warnings[server]) }); } else { @@ -22,13 +25,14 @@ var pages = function(dbot) { } }, - '/warnings/:server/:user': function(req, res) { + '/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)) { + 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 { diff --git a/modules/warning/warning.js b/modules/warning/warning.js index 51c48db..cbea752 100644 --- a/modules/warning/warning.js +++ b/modules/warning/warning.js @@ -26,7 +26,7 @@ var warning = function(dbot) { 'warner': warner, 'warnee': warnee, 'reason': reason, - 'url': dbot.api.web.getUrl('warnings/' + server + '/' + warnee) + 'url': dbot.api.web.getUrl('warning/' + server + '/' + warnee) }); if(!_.isUndefined(adminChannel)) { adminChannel = event.channel.name; @@ -44,7 +44,7 @@ var warning = function(dbot) { event.reply(dbot.t('warning_info', { 'user': warnee, 'num': this.warnings[server][warnee].length, - 'url': dbot.api.web.getUrl('warnings/' + server + '/' + warnee) + 'url': dbot.api.web.getUrl('warning/' + server + '/' + warnee) })); } else { event.reply(dbot.t('no_warnings', { 'user': warnee })); 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)) From 410eb58c8afe2cd7f4478957b3f7c8cece4ababb Mon Sep 17 00:00:00 2001 From: reality Date: Wed, 19 Jun 2013 20:02:24 +0000 Subject: [PATCH 3/6] whoops forgot to add the views #506 --- views/warning/servers.jade | 10 ++++++++++ views/warning/users.jade | 10 ++++++++++ views/warning/warnings.jade | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 views/warning/servers.jade create mode 100644 views/warning/users.jade create mode 100644 views/warning/warnings.jade 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..30104cc --- /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') + 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..75304a2 --- /dev/null +++ b/views/warning/warnings.jade @@ -0,0 +1,18 @@ +extends ../layout + +block content + div#backlink + a(href='/warning/'+server) + 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} From 710b9bda49dc6e29b14ade80a5d1f7f0efede24e Mon Sep 17 00:00:00 2001 From: reality Date: Wed, 19 Jun 2013 20:09:01 +0000 Subject: [PATCH 4/6] fix backlinks #506 --- views/warning/users.jade | 2 +- views/warning/warnings.jade | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/views/warning/users.jade b/views/warning/users.jade index 30104cc..2a108f9 100644 --- a/views/warning/users.jade +++ b/views/warning/users.jade @@ -3,7 +3,7 @@ extends ../layout block content h3 Users with warnings on #{server} div#backlink - a(href='/warning') + a(href='/warning') « Server List ul#quotelist -each user in users a(href='/warning/'+server+'/'+user) diff --git a/views/warning/warnings.jade b/views/warning/warnings.jade index 75304a2..18bfc70 100644 --- a/views/warning/warnings.jade +++ b/views/warning/warnings.jade @@ -2,7 +2,8 @@ extends ../layout block content div#backlink - a(href='/warning/'+server) + a(href='/warning/'+server) « Server Warnings + p div#profile_datatable table.table.table-hover.data thead From 051b59504aaa48d04b5a4b9faed809659b46ce2d Mon Sep 17 00:00:00 2001 From: reality Date: Wed, 19 Jun 2013 23:07:38 +0000 Subject: [PATCH 5/6] add ~ prefix to admin commands :( [Close #465] --- modules/admin/commands.js | 40 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/modules/admin/commands.js b/modules/admin/commands.js index 00c4185..0aa2ba0 100644 --- a/modules/admin/commands.js +++ b/modules/admin/commands.js @@ -46,7 +46,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})); @@ -57,7 +57,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})); @@ -68,7 +68,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. @@ -79,12 +79,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); @@ -93,7 +93,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(); @@ -115,7 +115,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]; @@ -130,14 +130,14 @@ 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(); event.reply(dbot.t('reload')); }, // Say something in a channel - 'say': function(event) { + '~say': function(event) { var channel = event.params[1]; if(event.params[1] === "@") { channel = event.channel.name; @@ -147,7 +147,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.config.moduleNames.push(moduleName); @@ -167,7 +167,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)) { @@ -187,7 +187,7 @@ var commands = function(dbot) { /*** Config options ***/ - 'setconfig': function(event) { + '~setconfig': function(event) { var configPathString = event.params[1], configKey = _.last(configPathString.split('.')), newOption = event.params[2]; @@ -223,7 +223,7 @@ var commands = function(dbot) { } }, - 'pushconfig': function(event) { + '~pushconfig': function(event) { var configPathString = event.params[1], configKey = _.last(configPathString.split('.')), newOption = event.params[2]; @@ -247,7 +247,7 @@ var commands = function(dbot) { } }, - 'showconfig': function(event) { + '~showconfig': function(event) { var configPathString = event.params[1]; var configPath = getCurrentConfig(configPathString); @@ -275,11 +275,11 @@ 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'; return commands; }; From 210f4936df35d19da8673dc1623a9c47e4cc2e5e Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Fri, 21 Jun 2013 17:38:17 +0000 Subject: [PATCH 6/6] Update strings.json --- modules/poll/strings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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}'",