From 777d7383946863cba1c3e67a172648979403e163 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 10 Feb 2018 12:35:31 +0000 Subject: [PATCH] new notes functionality --- modules/report/commands.js | 36 ++++++++++++++++++++++++++++++++++++ modules/warning/warning.js | 20 ++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/modules/report/commands.js b/modules/report/commands.js index fad9843..00e52ac 100644 --- a/modules/report/commands.js +++ b/modules/report/commands.js @@ -131,6 +131,41 @@ var commands = function(dbot) { }); }, + '~notes': function(event) { + var tName = event.params[1], + server = event.server; + + dbot.api.users.resolveUser(server, tName, function(err, target) { + if(target) { + var notes = {}; + this.db.search('warnings', { + 'server': server, + 'warnee': warnee.id + }, function(warning) { + if(warning.reason.match('#note')) { + notes[warning.time] = warning; + } + }, function(err) { + if(_.size(notes) > 0) { + var nTimes = _.keys(notes).sort(function(a, b) { + return parseInt(a) - parseInt(b); + }); + + var n = 0; + _.each(nTimes, function(key) { + event.reply('['+n+'][\u00036note\u000f][' + moment(parseInt(time)).format('DD/MM/YYYY') + '] ' + notes[key].reason); + n++; + }); + } else { + event.reply('No notes found for ' + tName); + } + }); + } else { + event.reply(event.params[1] + ' not found.'); + } + }.bind(this)); + }, + '~sustatus': function(event) { var user = event.input[1]; if(event.channel == '#tripsit.me') { @@ -415,6 +450,7 @@ var commands = function(dbot) { commands['~ustatus'].access = 'power_user'; commands['~sustatus'].access = 'power_user'; commands['~ncount'].access = 'power_user'; + commands['~notes'].access = 'power_user'; return commands; }; diff --git a/modules/warning/warning.js b/modules/warning/warning.js index 87d53eb..aa1d370 100644 --- a/modules/warning/warning.js +++ b/modules/warning/warning.js @@ -62,6 +62,24 @@ var warning = function(dbot) { }); }, + '~addnote': function(event) { + var warner = event.rUser, + server = event.server, + reason = event.input[2]; + + if(!reason.match('#note')) { + reason += ' #note'; + } + + this.api.warn(server, warner, event.input[1], reason, event.channel, function(err) { + if(err) { + event.reply(dbot.t('warnee_not_found', { 'user': event.input[1] })); + } else { + event.reply('Note added!'); + } + }); + }, + '~rmwarning': function(event) { var user = event.params[1], index = parseInt(event.params[2]); @@ -116,6 +134,7 @@ var warning = function(dbot) { }.bind(this)); }.bind(this)); }, + '~warnings': function(event) { var warnee = event.params[1], server = event.server; @@ -152,6 +171,7 @@ var warning = function(dbot) { this.commands['~warn'].access = 'power_user'; this.commands['~rmwarning'].access = 'power_user'; this.commands['~rmlastwarning'].access = 'power_user'; + this.commands['~addnote'].access = 'power_user'; }; exports.fetch = function(dbot) {