3
0
mirror of https://github.com/reality/dbot.git synced 2025-01-25 19:44:22 +01:00
This commit is contained in:
reality 2013-08-27 22:01:44 +00:00
parent 5cdd2d927c
commit 78860ce01a
4 changed files with 79 additions and 120 deletions

View File

@ -22,28 +22,32 @@ var commands = function(dbot) {
var msTimeout = new Date(new Date().getTime() + (minutes * 60000)); var msTimeout = new Date(new Date().getTime() + (minutes * 60000));
dbot.api.timers.addTimeout(msTimeout, function() { dbot.api.timers.addTimeout(msTimeout, function() {
this.api.unquiet(server, quietee, channel); this.api.unquiet(server, quietee, channel);
dbot.api.report.notify(server, channel, dbot.t('unquiet_notify', {
dbot.api.users.resolveUser(server, dbot.config.name, function(user) {
dbot.api.report.notify('unquiet', server, user, channel,
dbot.t('unquiet_notify', {
'unquieter': dbot.config.name, 'unquieter': dbot.config.name,
'channel': channel,
'quietee': quietee 'quietee': quietee
})); }));
});
}.bind(this)); }.bind(this));
event.reply(dbot.t('tquieted', { event.reply(dbot.t('tquieted', {
'quietee': quietee, 'quietee': quietee,
'minutes': minutes 'minutes': minutes
})); }));
dbot.api.report.notify(server, channel, dbot.t('tquiet_notify', { dbot.api.report.notify('quiet', server, event.rUser, channel,
'quieter': quieter, dbot.t('tquiet_notify', {
'channel': channel,
'quietee': quietee,
'minutes': minutes, 'minutes': minutes,
'quieter': event.rUser.primaryNick,
'quietee': quietee,
'reason': reason 'reason': reason
})); })
);
} else { } else {
event.reply(dbot.t('quieted', { 'quietee': quietee })); event.reply(dbot.t('quieted', { 'quietee': quietee }));
dbot.api.report.notify(server, channel, dbot.t('quiet_notify', { dbot.api.report.notify('quiet', server, event.rUser, channel,
dbot.t('quiet_notify', {
'quieter': quieter, 'quieter': quieter,
'channel': channel,
'quietee': quietee, 'quietee': quietee,
'reason': reason 'reason': reason
})); }));
@ -65,9 +69,9 @@ var commands = function(dbot) {
this.api.unquiet(server, quietee, channel); this.api.unquiet(server, quietee, channel);
event.reply(dbot.t('unquieted', { 'quietee': quietee })); event.reply(dbot.t('unquieted', { 'quietee': quietee }));
dbot.api.report.notify(server, channel, dbot.t('unquiet_notify', { dbot.api.report.notify('unquiet', server, event.rUser, channel,
dbot.t('unquiet_notify', {
'unquieter': quieter, 'unquieter': quieter,
'channel': channel,
'quietee': quietee 'quietee': quietee
})); }));
}, },
@ -81,28 +85,9 @@ var commands = function(dbot) {
this.api.kick(server, kickee, channel, reason + ' (requested by ' + kicker + ')'); this.api.kick(server, kickee, channel, reason + ' (requested by ' + kicker + ')');
dbot.api.report.notify(server, channel, dbot.t('ckicked', { dbot.api.report.notify('kick', server, event.rUser, channel, dbot.t('ckicked', {
'kicker': kicker, 'kicker': kicker,
'kickee': kickee, 'kickee': kickee,
'channel': channel,
'reason': reason
}));
},
'~cban': function(event) {
var server = event.server,
banner = event.user,
banee = event.input[2],
channel = event.input[1],
reason = event.input[3];
this.api.ban(server, banee, channel);
this.api.kick(server, kickee, channel, reason + ' (requested by ' + banner + ')');
dbot.api.report.notify(server, channel, dbot.t('cbanned', {
'banner': banner,
'banee': banee,
'channel': channel,
'reason': reason 'reason': reason
})); }));
}, },
@ -146,13 +131,6 @@ var commands = function(dbot) {
'hours': timeout, 'hours': timeout,
'reason': reason 'reason': reason
}); });
var quoteString = dbot.t('tban_quote', {
'banee': banee,
'banner': banner,
'hours': timeout,
'time': new Date().toUTCString(),
'reason': reason
});
} else { } else {
var notifyString = dbot.t('nbanned', { var notifyString = dbot.t('nbanned', {
'network': network, 'network': network,
@ -160,12 +138,6 @@ var commands = function(dbot) {
'banee': banee, 'banee': banee,
'reason': reason 'reason': reason
}); });
var quoteString = dbot.t('nban_quote', {
'banee': banee,
'banner': banner,
'time': new Date().toUTCString(),
'reason': reason
});
} }
// Add qutoe category documenting ban // Add qutoe category documenting ban
@ -190,7 +162,7 @@ var commands = function(dbot) {
adminChannel = event.channel.name; adminChannel = event.channel.name;
} }
dbot.api.report.notify(server, adminChannel, notifyString); dbot.api.report.notify('ban', server, event.rUser, adminChannel, notifyString);
dbot.say(event.server, adminChannel, notifyString); dbot.say(event.server, adminChannel, notifyString);
if(!_.isUndefined(timeout)) { if(!_.isUndefined(timeout)) {

View File

@ -20,10 +20,10 @@
"it": "{quietee} è stato silenziato per {minutes} minuto/i. Ricordati: non essere testardo" "it": "{quietee} è stato silenziato per {minutes} minuto/i. Ricordati: non essere testardo"
}, },
"quiet_notify": { "quiet_notify": {
"en": "Attention: {quieter} has quieted {quietee} in {channel}. The reason given was \"{reason}\"." "en": "{quieter} has quieted {quietee}. The reason given was \"{reason}\"."
}, },
"tquiet_notify": { "tquiet_notify": {
"en": "Attention: {quieter} has quieted {quietee} in {channel} for {minutes} minutes. The reason given was \"{reason}\"." "en": "{quieter} has quieted {quietee} for {minutes} minutes. The reason given was \"{reason}\"."
}, },
"unquieted": { "unquieted": {
"en": "Unquieted {quietee}. Remember: don't be a coconut.", "en": "Unquieted {quietee}. Remember: don't be a coconut.",
@ -31,7 +31,7 @@
"it": "{quietee} può nuovamente parlare. Ricordati: non essere testardo." "it": "{quietee} può nuovamente parlare. Ricordati: non essere testardo."
}, },
"unquiet_notify": { "unquiet_notify": {
"en": "Attention: {unquieter} has unquieted {quietee} in {channel}." "en": "{unquieter} has unquieted {quietee}."
}, },
"kicked_dbot": { "kicked_dbot": {
"en": "Thou shalt not kick {botname}", "en": "Thou shalt not kick {botname}",
@ -44,7 +44,7 @@
"it": "Non dare pedata a {botname}" "it": "Non dare pedata a {botname}"
}, },
"ckicked": { "ckicked": {
"en": "Attention: {kicker} has kicked {kickee} from {channel}. The reason given was: \"{reason}.\"", "en": "{kicker} has kicked {kickee}. The reason given was: \"{reason}.\"",
"cy": "Sylw: {kicker} wedi cicio'r {kickee} o {channel}. Y rheswm a roddwyd oedd: \"{reason}.\"", "cy": "Sylw: {kicker} wedi cicio'r {kickee} o {channel}. Y rheswm a roddwyd oedd: \"{reason}.\"",
"de": "Achtung: {kicker} hat {kickee} von {channel} verwiesen. Grund: \"{reason}.\"", "de": "Achtung: {kicker} hat {kickee} von {channel} verwiesen. Grund: \"{reason}.\"",
"fr": "Attention : {kicker} a kické {kickee} de {channel}. Raison donnée : \"{reason}.\"", "fr": "Attention : {kicker} a kické {kickee} de {channel}. Raison donnée : \"{reason}.\"",

View File

@ -16,12 +16,53 @@ var report = function(dbot) {
next(); next();
}, 1000); }, 1000);
}); });
},
'formatNotify': function(type, server, user, channel, message) {
var notifier = '[' + user.primaryNick + ']';
if(_.has(this.config.colours, server)) {
var colours = this.config.colours[server];
notifier = '[' + colours['nicks'] + user.primaryNick + '\u000f]';
if(_.has(colours.type, type)) {
type = colours['type'][type] + type + '\u000f';
} }
if(_.has(colours['channels'], channel)) {
channel = colours['channels'][channel] +
channel + "\u000f";
}
_.each(message.match(/ @([\d\w*|-]+)/g), function(u) {
u = u.substr(1);
message = message.replace(u, colours['nicks'] + u + "\u000f");
notifier += '[' + colours['nicks'] + u.substr(1) + '\u000f]';
});
}
return dbot.t('notify', {
'type': type,
'channel': channel,
'notifier': notifier,
'message': message
});
}.bind(this)
}; };
this.api = { this.api = {
'notify': function(server, channel, message) { 'notify': function(type, server, user, cName, message) {
var channel = dbot.instance.connections[server].channels[channel]; var id = uuid.v4();
this.db.save('notifies', id, {
'id': id,
'server': server,
'type': type,
'channel': channel,
'user': user.id,
'time': new Date().getTime(),
'message': message
}, function() {});
var channel = dbot.instance.connections[server].channels[cName];
var ops = _.filter(channel.nicks, function(user) { var ops = _.filter(channel.nicks, function(user) {
if(this.config.notifyVoice) { if(this.config.notifyVoice) {
return user.op || user.voice; return user.op || user.voice;
@ -30,7 +71,7 @@ var report = function(dbot) {
} }
}, this); }, this);
dbot.api.users.resolveChannel(server, channel, function(channel) { dbot.api.users.resolveChannel(server, cName, function(channel) {
if(channel) { if(channel) {
var perOps = channel.op; var perOps = channel.op;
if(this.config.notifyVoice) pOps = _.union(perOps, channel.voice); if(this.config.notifyVoice) pOps = _.union(perOps, channel.voice);
@ -50,6 +91,8 @@ var report = function(dbot) {
this.pNotify[id] = true; this.pNotify[id] = true;
}.bind(this)); }.bind(this));
message = this.internalAPI.formatNotify(type, server,
user, cName, message);
this.internalAPI.notify(server, _.pluck(ops, 'name'), message); this.internalAPI.notify(server, _.pluck(ops, 'name'), message);
}.bind(this)); }.bind(this));
} }
@ -93,29 +136,7 @@ var report = function(dbot) {
dbot.api.users.resolveUser(event.server, nick, function(reportee) { dbot.api.users.resolveUser(event.server, nick, function(reportee) {
if(_.has(event.allChannels, channelName)) { if(_.has(event.allChannels, channelName)) {
if(reportee) { if(reportee) {
var notifier = '[' + event.user + ']', this.api.notify('report', event.server, event.rUser, channelName, reason);
cChan = channelName,
type = 'report',
reporter = event.user;
if(_.has(this.config.colours, event.server)) {
var colours = this.config.colours[event.server];
reporter = colours['nicks'] + reporter + '\u000f';
nick = colours['nicks'] + nick + '\u000f';
type = colours['type'][type] + type + '\u000f';
if(_.has(colours['channels'], channelName)) {
cChan = colours['channels'][channelName] +
cChan + "\u000f";
}
}
this.api.notify(event.server, channelName, dbot.t('report', {
'type': type,
'reporter': reporter,
'reported': nick,
'channel': cChan,
'reason': reason
}));
event.reply(dbot.t('reported', { 'reported': nick })); event.reply(dbot.t('reported', { 'reported': nick }));
} else { } else {
event.reply(dbot.t('user_not_found', { event.reply(dbot.t('user_not_found', {
@ -130,47 +151,11 @@ var report = function(dbot) {
}, },
'~notify': function(event) { '~notify': function(event) {
console.log('~notify triggered');
var channelName = event.input[1], var channelName = event.input[1],
message = event.input[2]; message = event.input[2];
if(_.has(event.allChannels, channelName)) { if(_.has(event.allChannels, channelName)) {
var id = uuid.v4(); this.api.notify('notify', event.server, event.rUser, channelName, message);
this.db.save('notifies', id, {
'id': id,
'server': event.server,
'channel': channelName,
'user': event.rUser.id,
'time': new Date().getTime(),
'message': message
}, function() {});
var notifier = '[' + event.user + ']',
cChan = channelName,
type = 'notify';
if(_.has(this.config.colours, event.server)) {
var colours = this.config.colours[event.server];
notifier = '[' + colours['nicks'] + event.user + '\u000f]';
type = colours['type'][type] + type + '\u000f';
if(_.has(colours['channels'], channelName)) {
cChan = colours['channels'][channelName] +
cChan + "\u000f";
}
_.each(message.match(/ @([\d\w*|-]+)/g), function(user) {
user = user.substr(1);
message = message.replace(user, colours['nicks'] + user + "\u000f");
notifier += '[' + colours['nicks'] + user.substr(1) + '\u000f]';
});
}
this.api.notify(event.server, channelName, dbot.t('notify', {
'type': type,
'channel': cChan,
'notifier': notifier,
'message': message
}));
event.reply(dbot.t('notified', { event.reply(dbot.t('notified', {
'user': event.user, 'user': event.user,

View File

@ -12,6 +12,7 @@ block content
tr tr
th Date th Date
th Channel th Channel
th type
th User th User
th Message th Message
tbody tbody
@ -19,5 +20,6 @@ block content
tr tr
td #{new Date(notify.time)} td #{new Date(notify.time)}
td #{notify.channel} td #{notify.channel}
td #{notify.type}
td #{notify.user} td #{notify.user}
td #{notify.message} td #{notify.message}