From dc00730168deca118565a0c1c8fa32560b784d7c Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 15 Jan 2016 21:36:24 +0000 Subject: [PATCH] remind-like time periods for nban and quiet --- modules/kick/commands.js | 37 +++++++++++++++++++++++++------------ modules/kick/kick.js | 8 ++++---- modules/kick/strings.json | 6 +++--- modules/remind/remind.js | 35 +++++++++++++++++++++-------------- 4 files changed, 53 insertions(+), 33 deletions(-) diff --git a/modules/kick/commands.js b/modules/kick/commands.js index 80aaab0..8a4baaf 100644 --- a/modules/kick/commands.js +++ b/modules/kick/commands.js @@ -7,7 +7,7 @@ var commands = function(dbot) { '~quiet': function(event) { var server = event.server, quieter = event.user, - minutes = event.input[1], + duration = event.input[1].trim(), channel = (event.input[2] || event.channel.name).trim(), quietee = event.input[3].trim(), reason = event.input[4] || "N/A"; @@ -17,9 +17,16 @@ var commands = function(dbot) { if(host) { this.hosts[server][quietee] = host; - if(!_.isUndefined(minutes)) { - minutes = parseFloat(minutes.trim()); - var msTimeout = new Date(new Date().getTime() + (minutes * 60000)); + if(!_.isUndefined(duration)) { + var msTimeout = new Date(new Date().getTime() + (parseFloat(duration) * 60000)); + if(_.has(dbot.modules, 'remind')) { + msTimeout = dbot.api.remind.parseTime(duration); + event.reply(msTimeout); + duration = duration.replace(/([\d]+)d/, '$1 days').replace(/([\d]+)h/, '$1 hours ').replace(/([\d]+)m/, '$1 minutes ').replace(/([\d]+)s/, '$1 seconds'); + } else { + duration += ' minutes'; + } + var vStatus = dbot.instance.connections[server].channels[channel].nicks[quietee].voice; dbot.api.timers.addTimeout(msTimeout, function() { if(_.has(this.hosts[server], quietee)) { @@ -41,11 +48,11 @@ var commands = function(dbot) { }.bind(this)); event.reply(dbot.t('tquieted', { 'quietee': quietee, - 'minutes': minutes + 'minutes': duration })); dbot.api.report.notify('quiet', server, event.rUser, channel, dbot.t('tquiet_notify', { - 'minutes': minutes, + 'minutes': duration, 'quieter': event.rUser.primaryNick, 'quietee': quietee, 'reason': reason @@ -160,14 +167,20 @@ var commands = function(dbot) { }.bind(this); banChannel(channels); - this.hosts[event.server][banee] = host; // Create notify string if(!_.isUndefined(timeout)) { - timeout = parseFloat(timeout.trim()); - - var msTimeout = new Date(new Date().getTime() + (timeout * 3600000)); + timeout = timeout.trim(); + + var msTimeout = new Date(new Date().getTime() + (parseFloat(timeout) * 3600000)); + if(_.has(dbot.modules, 'remind')) { + msTimeout = dbot.api.remind.parseTime(timeout); + timeout = timeout.replace(/([\d]+)d/, '$1 days').replace(/([\d]+)h/, '$1 hours ').replace(/([\d]+)m/, '$1 minutes ').replace(/([\d]+)s/, '$1 seconds'); + } else { + timeout += ' hours'; + } + if(!_.has(this.tempBans, event.server)) this.tempBans[event.server] = {}; this.tempBans[event.server][banee] = msTimeout; this.internalAPI.addTempBan(event.server, banee, msTimeout); @@ -310,8 +323,8 @@ var commands = function(dbot) { commands['~unquiet'].access = 'voice'; commands['~ckick'].regex = /^ckick (#[^ ]+ )?([^ ]+) ?(.*)?$/; - commands['~nban'].regex = /^nban ([\d\.^ ]+)?([^ ]+) (.+)$/; - commands['~quiet'].regex = /^quiet ([\d\.^ ]+)?(#[^ ]+ )?([^ ]+) ?(.*)?$/; + commands['~nban'].regex = /^nban ([\d\.dhms^ ]+)?([^ ]+) (.+)$/; + commands['~quiet'].regex = /^quiet ([\d\.dhms^ ]+)?(#[^ ]+ )?([^ ]+) ?(.*)?$/; commands['~unquiet'].regex = /^unquiet (#[^ ]+ )?([^ ]+) ?$/; return commands; diff --git a/modules/kick/kick.js b/modules/kick/kick.js index 08c8de3..5bbdff2 100644 --- a/modules/kick/kick.js +++ b/modules/kick/kick.js @@ -93,11 +93,11 @@ var kick = function(dbot) { 'addTempBan': function(server, banee, timeout) { dbot.api.users.resolveUser(server, dbot.config.name, function(err, bot) { dbot.api.timers.addTimeout(timeout, function() { - this.api.networkUnban(server, banee, bot, function(err) {}); - delete this.tempBans[server][banee]; - }.bind(this)); + this.api.networkUnban(server, banee, bot, function(err) {}); + delete this.tempBans[server][banee]; + }.bind(this)); }.bind(this)); - } + }.bind(this) }; this.listener = function(event) { diff --git a/modules/kick/strings.json b/modules/kick/strings.json index 49da5ed..51c70b0 100644 --- a/modules/kick/strings.json +++ b/modules/kick/strings.json @@ -16,7 +16,7 @@ "de": "{quietee} stummgestellt. Denk dran: Sei kein Arschloch." }, "tquieted": { - "en": "Quieted {quietee} for {minutes} minutes. Remember: don't be a coconut.", + "en": "Quieted {quietee} for {minutes}. Remember: don't be a coconut.", "fr": "{quietee} a été rendu silencieux pour {minutes} minutes. Rappelle-toi : ne sois pas têtu.", "it": "{quietee} è stato silenziato per {minutes} minuto/i. Ricordati: non essere testardo", "de": "{quietee} für {minutes} Minuten stummgestellt. Denk dran: Sei kein Arschloch." @@ -64,13 +64,13 @@ "it": "Attenzione : {banner} ha bandito {banee} da {channel}. Motivo : \"{reason}\"." }, "tbanned": { - "en": "Attention: {banner} has banned {banee} from the {network} network for {hours} hours. The reason given was \"{reason}\".", + "en": "Attention: {banner} has banned {banee} from the {network} network for {hours}. The reason given was \"{reason}\".", "de": "Achtung: {banner} hat {banee} vom {network} Netzwerk für {hours} Stunden verbannt. Der Grund war \"{reason}\".", "fr": "Attention : {banner} a banni {banee} du réseau {network} pour {hours} heures. Raison donnée : \"{reason}\".", "it": "Attenzione : {banner} ha bandito {banee} dalla rete {network} per {hours} ora/e. Motivo : \"{reason}\"." }, "tbanned_notify": { - "en": "You have been banned from the {network} network for {hours} hours by {banner}. The reason given was \"{reason}\". You can join {admin_channel} for more information or to discuss the ban.", + "en": "You have been banned from the {network} network for {hours} by {banner}. The reason given was \"{reason}\". You can join {admin_channel} for more information or to discuss the ban.", "de": "Du wurdest von {banner} im {network} Netzwerk für {hours} verbannt. Der Grund war \"{reason}\". Du kannst {admin_channel} beitreten um mehr Informatonen zu erhalten oder über die Verbannung zu diskutieren.", "fr": "Vous avez été banni du réseau {network} pour {hours} heures par {banner}. La raison donnée était \"{reason}\". Vous pouvez rejoindre {admin_channel} pour plus d'information or pour discuter du ban.", "it": "Sei stato bandito dalla rete {network} per {hours} ora/e da {banner}. Motivo: \"{reason}\". Puoi ricongiungere {admin_channel} per ulteriori informazioni o discutere sulla messa al bando." diff --git a/modules/remind/remind.js b/modules/remind/remind.js index a4ebca2..d37b851 100644 --- a/modules/remind/remind.js +++ b/modules/remind/remind.js @@ -10,8 +10,26 @@ var crypto = require('crypto'), var remind = function(dbot) { var self = this; + this.api = { + 'parseTime': function(time) { + var now = Date.now(); + var datesplits = time.match(/[0-9]+[dhms]/g); + if(datesplits == null) { + event.reply("The time parameter was not a valid time mah boy, it was "+time); + return; + } + var timeinseconds = 0; + for(var i=0;i