remind-like time periods for nban and quiet

This commit is contained in:
reality 2016-01-15 21:36:24 +00:00
parent eb35db1074
commit dc00730168
4 changed files with 53 additions and 33 deletions

View File

@ -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());
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';
}
var msTimeout = new Date(new Date().getTime() + (timeout * 3600000));
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;

View File

@ -97,7 +97,7 @@ var kick = function(dbot) {
delete this.tempBans[server][banee];
}.bind(this));
}.bind(this));
}
}.bind(this)
};
this.listener = function(event) {

View File

@ -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."

View File

@ -10,6 +10,24 @@ 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<datesplits.length;++i) {
var number = parseInt(datesplits[i].match(/[0-9]+/)[0]);
var interval = datesplits[i].match(/[^0-9]/)[0];
timeinseconds += this.internalAPI.getSeconds(number,interval);
}
return new Date(now + (timeinseconds*1000));
}
};
this.internalAPI = {
'getSeconds': function(number,interval) {
switch(interval) {
@ -24,19 +42,8 @@ var remind = function(dbot) {
}
}.bind(this),
'doReminder': function(event,user,time,message) {
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<datesplits.length;++i) {
var number = parseInt(datesplits[i].match(/[0-9]+/)[0]);
var interval = datesplits[i].match(/[^0-9]/)[0];
timeinseconds += this.internalAPI.getSeconds(number,interval);
}
var then = new Date(now + (timeinseconds*1000));
var then = this.api.parseTime(time);
if(dbot.config.debugMode)
event.reply("The timer will be at "+then);
this.internalAPI.startTimer(event.server,event.channel,then,event.user,user,message);