mirror of
https://github.com/reality/dbot.git
synced 2024-11-23 20:39:25 +01:00
remind-like time periods for nban and quiet
This commit is contained in:
parent
eb35db1074
commit
dc00730168
@ -7,7 +7,7 @@ var commands = function(dbot) {
|
|||||||
'~quiet': function(event) {
|
'~quiet': function(event) {
|
||||||
var server = event.server,
|
var server = event.server,
|
||||||
quieter = event.user,
|
quieter = event.user,
|
||||||
minutes = event.input[1],
|
duration = event.input[1].trim(),
|
||||||
channel = (event.input[2] || event.channel.name).trim(),
|
channel = (event.input[2] || event.channel.name).trim(),
|
||||||
quietee = event.input[3].trim(),
|
quietee = event.input[3].trim(),
|
||||||
reason = event.input[4] || "N/A";
|
reason = event.input[4] || "N/A";
|
||||||
@ -17,9 +17,16 @@ var commands = function(dbot) {
|
|||||||
if(host) {
|
if(host) {
|
||||||
this.hosts[server][quietee] = host;
|
this.hosts[server][quietee] = host;
|
||||||
|
|
||||||
if(!_.isUndefined(minutes)) {
|
if(!_.isUndefined(duration)) {
|
||||||
minutes = parseFloat(minutes.trim());
|
var msTimeout = new Date(new Date().getTime() + (parseFloat(duration) * 60000));
|
||||||
var msTimeout = new Date(new Date().getTime() + (minutes * 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;
|
var vStatus = dbot.instance.connections[server].channels[channel].nicks[quietee].voice;
|
||||||
dbot.api.timers.addTimeout(msTimeout, function() {
|
dbot.api.timers.addTimeout(msTimeout, function() {
|
||||||
if(_.has(this.hosts[server], quietee)) {
|
if(_.has(this.hosts[server], quietee)) {
|
||||||
@ -41,11 +48,11 @@ var commands = function(dbot) {
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
event.reply(dbot.t('tquieted', {
|
event.reply(dbot.t('tquieted', {
|
||||||
'quietee': quietee,
|
'quietee': quietee,
|
||||||
'minutes': minutes
|
'minutes': duration
|
||||||
}));
|
}));
|
||||||
dbot.api.report.notify('quiet', server, event.rUser, channel,
|
dbot.api.report.notify('quiet', server, event.rUser, channel,
|
||||||
dbot.t('tquiet_notify', {
|
dbot.t('tquiet_notify', {
|
||||||
'minutes': minutes,
|
'minutes': duration,
|
||||||
'quieter': event.rUser.primaryNick,
|
'quieter': event.rUser.primaryNick,
|
||||||
'quietee': quietee,
|
'quietee': quietee,
|
||||||
'reason': reason
|
'reason': reason
|
||||||
@ -160,14 +167,20 @@ var commands = function(dbot) {
|
|||||||
}.bind(this);
|
}.bind(this);
|
||||||
banChannel(channels);
|
banChannel(channels);
|
||||||
|
|
||||||
|
|
||||||
this.hosts[event.server][banee] = host;
|
this.hosts[event.server][banee] = host;
|
||||||
|
|
||||||
// Create notify string
|
// Create notify string
|
||||||
if(!_.isUndefined(timeout)) {
|
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] = {};
|
if(!_.has(this.tempBans, event.server)) this.tempBans[event.server] = {};
|
||||||
this.tempBans[event.server][banee] = msTimeout;
|
this.tempBans[event.server][banee] = msTimeout;
|
||||||
this.internalAPI.addTempBan(event.server, banee, msTimeout);
|
this.internalAPI.addTempBan(event.server, banee, msTimeout);
|
||||||
@ -310,8 +323,8 @@ var commands = function(dbot) {
|
|||||||
commands['~unquiet'].access = 'voice';
|
commands['~unquiet'].access = 'voice';
|
||||||
|
|
||||||
commands['~ckick'].regex = /^ckick (#[^ ]+ )?([^ ]+) ?(.*)?$/;
|
commands['~ckick'].regex = /^ckick (#[^ ]+ )?([^ ]+) ?(.*)?$/;
|
||||||
commands['~nban'].regex = /^nban ([\d\.^ ]+)?([^ ]+) (.+)$/;
|
commands['~nban'].regex = /^nban ([\d\.dhms^ ]+)?([^ ]+) (.+)$/;
|
||||||
commands['~quiet'].regex = /^quiet ([\d\.^ ]+)?(#[^ ]+ )?([^ ]+) ?(.*)?$/;
|
commands['~quiet'].regex = /^quiet ([\d\.dhms^ ]+)?(#[^ ]+ )?([^ ]+) ?(.*)?$/;
|
||||||
commands['~unquiet'].regex = /^unquiet (#[^ ]+ )?([^ ]+) ?$/;
|
commands['~unquiet'].regex = /^unquiet (#[^ ]+ )?([^ ]+) ?$/;
|
||||||
|
|
||||||
return commands;
|
return commands;
|
||||||
|
@ -93,11 +93,11 @@ var kick = function(dbot) {
|
|||||||
'addTempBan': function(server, banee, timeout) {
|
'addTempBan': function(server, banee, timeout) {
|
||||||
dbot.api.users.resolveUser(server, dbot.config.name, function(err, bot) {
|
dbot.api.users.resolveUser(server, dbot.config.name, function(err, bot) {
|
||||||
dbot.api.timers.addTimeout(timeout, function() {
|
dbot.api.timers.addTimeout(timeout, function() {
|
||||||
this.api.networkUnban(server, banee, bot, function(err) {});
|
this.api.networkUnban(server, banee, bot, function(err) {});
|
||||||
delete this.tempBans[server][banee];
|
delete this.tempBans[server][banee];
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}.bind(this)
|
||||||
};
|
};
|
||||||
|
|
||||||
this.listener = function(event) {
|
this.listener = function(event) {
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
"de": "{quietee} stummgestellt. Denk dran: Sei kein Arschloch."
|
"de": "{quietee} stummgestellt. Denk dran: Sei kein Arschloch."
|
||||||
},
|
},
|
||||||
"tquieted": {
|
"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.",
|
"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",
|
"it": "{quietee} è stato silenziato per {minutes} minuto/i. Ricordati: non essere testardo",
|
||||||
"de": "{quietee} für {minutes} Minuten stummgestellt. Denk dran: Sei kein Arschloch."
|
"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}\"."
|
"it": "Attenzione : {banner} ha bandito {banee} da {channel}. Motivo : \"{reason}\"."
|
||||||
},
|
},
|
||||||
"tbanned": {
|
"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}\".",
|
"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}\".",
|
"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}\"."
|
"it": "Attenzione : {banner} ha bandito {banee} dalla rete {network} per {hours} ora/e. Motivo : \"{reason}\"."
|
||||||
},
|
},
|
||||||
"tbanned_notify": {
|
"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.",
|
"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.",
|
"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."
|
"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."
|
||||||
|
@ -10,8 +10,26 @@ var crypto = require('crypto'),
|
|||||||
var remind = function(dbot) {
|
var remind = function(dbot) {
|
||||||
var self = this;
|
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 = {
|
this.internalAPI = {
|
||||||
'getSeconds': function(number,interval) {
|
'getSeconds': function(number,interval) {
|
||||||
switch(interval) {
|
switch(interval) {
|
||||||
case "d":
|
case "d":
|
||||||
return number*24*60*60;
|
return number*24*60*60;
|
||||||
@ -24,19 +42,8 @@ var remind = function(dbot) {
|
|||||||
}
|
}
|
||||||
}.bind(this),
|
}.bind(this),
|
||||||
'doReminder': function(event,user,time,message) {
|
'doReminder': function(event,user,time,message) {
|
||||||
var now = Date.now();
|
var then = this.api.parseTime(time);
|
||||||
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));
|
|
||||||
if(dbot.config.debugMode)
|
if(dbot.config.debugMode)
|
||||||
event.reply("The timer will be at "+then);
|
event.reply("The timer will be at "+then);
|
||||||
this.internalAPI.startTimer(event.server,event.channel,then,event.user,user,message);
|
this.internalAPI.startTimer(event.server,event.channel,then,event.user,user,message);
|
||||||
|
Loading…
Reference in New Issue
Block a user