3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 14:29:29 +01:00
This commit is contained in:
reality 2013-06-21 18:32:00 +00:00
commit 5f3c06a7a0
11 changed files with 189 additions and 27 deletions

View File

@ -8,7 +8,8 @@
"password": "lolturtles", "password": "lolturtles",
"channels": [ "channels": [
"#realitest" "#realitest"
] ],
"admin_channel": "#realitest"
} }
}, },
"admins": [ "batman" ], "admins": [ "batman" ],

View File

@ -8,7 +8,7 @@ var commands = function(dbot) {
var commands = { var commands = {
// Join a channel // Join a channel
'join': function(event) { '~join': function(event) {
var channel = event.params[1]; var channel = event.params[1];
if(_.has(event.allChannels, channel)) { if(_.has(event.allChannels, channel)) {
event.reply(dbot.t('already_in_channel', {'channel': channel})); event.reply(dbot.t('already_in_channel', {'channel': channel}));
@ -19,7 +19,7 @@ var commands = function(dbot) {
}, },
// Leave a channel // Leave a channel
'part': function(event) { '~part': function(event) {
var channel = event.params[1]; var channel = event.params[1];
if(!_.has(event.allChannels, channel)) { if(!_.has(event.allChannels, channel)) {
event.reply(dbot.t('not_in_channel', {'channel': channel})); event.reply(dbot.t('not_in_channel', {'channel': channel}));
@ -30,7 +30,7 @@ var commands = function(dbot) {
}, },
// Op admin caller in given channel // Op admin caller in given channel
'opme': function(event) { '~opme': function(event) {
var channel = event.params[1]; var channel = event.params[1];
// If given channel isn't valid just op in current one. // If given channel isn't valid just op in current one.
@ -41,12 +41,12 @@ var commands = function(dbot) {
}, },
// Do a git pull and reload // Do a git pull and reload
'greload': function(event) { '~greload': function(event) {
exec("git pull", function (error, stdout, stderr) { exec("git pull", function (error, stdout, stderr) {
exec("git submodule update", function (error, stdout, stderr) { exec("git submodule update", function (error, stdout, stderr) {
event.reply(dbot.t('gpull')); event.reply(dbot.t('gpull'));
commands.reload(event); commands['~reload'](event);
event.message = 'version'; event.message = '~version';
event.action = 'PRIVMSG'; event.action = 'PRIVMSG';
event.params = event.message.split(' '); event.params = event.message.split(' ');
dbot.instance.emit(event); dbot.instance.emit(event);
@ -55,7 +55,7 @@ var commands = function(dbot) {
}, },
// Display commit information for part of dbot // Display commit information for part of dbot
'version': function(event){ '~version': function(event){
var cmd = "git log --pretty=format:'%h (%s): %ar' -n 1 -- "; var cmd = "git log --pretty=format:'%h (%s): %ar' -n 1 -- ";
if(event.params[1]){ if(event.params[1]){
var input = event.params[1].trim(); var input = event.params[1].trim();
@ -77,7 +77,7 @@ var commands = function(dbot) {
}.bind(this)); }.bind(this));
}, },
'status': function(event) { '~status': function(event) {
var moduleName = event.params[1]; var moduleName = event.params[1];
if(_.has(dbot.status, moduleName)) { if(_.has(dbot.status, moduleName)) {
var status = dbot.status[moduleName]; var status = dbot.status[moduleName];
@ -98,7 +98,7 @@ var commands = function(dbot) {
}, },
// Reload DB, translations and modules. // Reload DB, translations and modules.
'reload': function(event) { '~reload': function(event) {
dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8')); dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
dbot.reloadModules(); dbot.reloadModules();
process.nextTick(function() { process.nextTick(function() {
@ -107,7 +107,7 @@ var commands = function(dbot) {
}, },
// Say something in a channel // Say something in a channel
'say': function(event) { '~say': function(event) {
var channel = event.params[1]; var channel = event.params[1];
if(event.params[1] === "@") { if(event.params[1] === "@") {
channel = event.channel.name; channel = event.channel.name;
@ -117,7 +117,7 @@ var commands = function(dbot) {
}, },
// Load new module // Load new module
'load': function(event) { '~load': function(event) {
var moduleName = event.params[1]; var moduleName = event.params[1];
if(!_.include(dbot.config.moduleNames, moduleName)) { if(!_.include(dbot.config.moduleNames, moduleName)) {
dbot.customConfig.moduleNames.push(moduleName); dbot.customConfig.moduleNames.push(moduleName);
@ -140,7 +140,7 @@ var commands = function(dbot) {
}, },
// Unload a loaded module // Unload a loaded module
'unload': function(event) { '~unload': function(event) {
var moduleNames = dbot.config.moduleNames; var moduleNames = dbot.config.moduleNames;
var moduleName = event.params[1]; var moduleName = event.params[1];
if(_.include(moduleNames, moduleName)) { if(_.include(moduleNames, moduleName)) {
@ -164,7 +164,7 @@ var commands = function(dbot) {
/*** Config options ***/ /*** Config options ***/
'setconfig': function(event) { '~setconfig': function(event) {
var configPath = event.input[1], var configPath = event.input[1],
newOption = event.input[2]; newOption = event.input[2];
@ -198,7 +198,7 @@ var commands = function(dbot) {
} }
}, },
'pushconfig': function(event) { '~pushconfig': function(event) {
var configPath = event.input[1], var configPath = event.input[1],
newOption = event.input[2]; newOption = event.input[2];
@ -221,7 +221,7 @@ var commands = function(dbot) {
} }
}, },
'showconfig': function(event) { '~showconfig': function(event) {
var configPath = event.params[1]; var configPath = event.params[1];
if(configPath) { if(configPath) {
this.internalAPI.getCurrentConfig(configPath, function(config) { this.internalAPI.getCurrentConfig(configPath, function(config) {
@ -250,7 +250,6 @@ var commands = function(dbot) {
this.commands['showconfig'](event); this.commands['showconfig'](event);
} }
}.bind(this)); }.bind(this));
} else { } else {
event.reply(dbot.t("config_keys_location", { event.reply(dbot.t("config_keys_location", {
"path": "root", "path": "root",
@ -259,7 +258,7 @@ var commands = function(dbot) {
} }
}, },
'savemodules': function(event) { '~savemodules': function(event) {
fs.readFile('config.json', 'utf-8', function(err, config) { fs.readFile('config.json', 'utf-8', function(err, config) {
config = JSON.parse(config); config = JSON.parse(config);
config.moduleNames = _.keys(dbot.modules); config.moduleNames = _.keys(dbot.modules);
@ -274,14 +273,14 @@ var commands = function(dbot) {
command.access = 'admin'; command.access = 'admin';
}); });
commands['showconfig'].access = 'moderator'; commands['~showconfig'].access = 'moderator';
commands['join'].access = 'moderator'; commands['~join'].access = 'moderator';
commands['part'].access = 'moderator'; commands['~part'].access = 'moderator';
commands['opme'].access = 'moderator'; commands['~opme'].access = 'moderator';
commands['say'].access = 'moderator'; commands['~say'].access = 'moderator';
commands['pushconfig'].regex = [/pushconfig ([^ ]+) ([^ ]+)/, 3]; commands['~pushconfig'].regex = [/~pushconfig ([^ ]+) ([^ ]+)/, 3];
commands['setconfig'].regex = [/setconfig ([^ ]+) ([^ ]+)/, 3]; commands['~setconfig'].regex = [/~setconfig ([^ ]+) ([^ ]+)/, 3];
return commands; return commands;
}; };

View File

@ -79,7 +79,7 @@
"na'vi": "{user}: ngaru '{name}' sìpawm sna'o ke lu.", "na'vi": "{user}: ngaru '{name}' sìpawm sna'o ke lu.",
"cy": "{user}: Nid ydech chi'n berchen y pôl '{name}'.", "cy": "{user}: Nid ydech chi'n berchen y pôl '{name}'.",
"nl": "{user}: Je bent niet de eigenaar van de poll '{name}'.", "nl": "{user}: Je bent niet de eigenaar van de poll '{name}'.",
"de": "{user}: "Du darfst die Umfrage '{name}' nicht verändern." "de": "{user}: Du darfst die Umfrage '{name}' nicht verändern."
}, },
"option_removed": { "option_removed": {
"en": "{user}: '{option}' removed from '{name}'", "en": "{user}: '{option}' removed from '{name}'",

View File

@ -0,0 +1,4 @@
{
"dependencies": [ "report", "users", "web" ],
"dbKeys": [ "warnings" ]
}

47
modules/warning/pages.js Normal file
View File

@ -0,0 +1,47 @@
var _ = require('underscore')._;
var pages = function(dbot) {
this.warnings = dbot.db.warnings;
return {
'/warning': function(req, res) {
res.render('servers', {
'name': dbot.config.name,
'servers': _.keys(this.warnings)
});
},
'/warning/:server': function(req, res) {
var server = req.params.server;
if(_.has(this.warnings, server)) {
res.render('users', {
'name': dbot.config.name,
'server': server,
'users': _.keys(this.warnings[server])
});
} else {
res.render('error');
}
},
'/warning/:server/:user': function(req, res) {
var server = req.params.server,
user = req.params.user;
if(_.has(this.warnings, server) && _.has(this.warnings[server], user)) {
res.render('warnings', {
'name': dbot.config.name,
'server': server,
'warnings': this.warnings[server][user]
});
} else {
res.render('error');
}
}
};
};
exports.fetch = function(dbot) {
return pages(dbot);
};

View File

@ -0,0 +1,11 @@
{
"no_warnings": {
"en": "No warnings found for {user}."
},
"warning_info": {
"en": "{user} has {num} warnings. More info can be found at {url}"
},
"warn_notify": {
"en": "Attention: {warner} has issued a warning to {warnee} for \"{reason}.\" More info can be found at {url}"
}
}

View File

@ -0,0 +1,61 @@
var _ = require('underscore')._;
var warning = function(dbot) {
this.warnings = dbot.db.warnings;
this.commands = {
'~warn': function(event) {
var warner = event.user,
server = event.server,
warnee = dbot.api.users.resolveUser(server, event.input[1]),
reason = event.input[2],
adminChannel = dbot.config.servers[server].admin_channel;
// Store the warn
if(!_.has(this.warnings, server)) this.warnings[server] = {};
if(!_.has(this.warnings[server], warnee)) this.warnings[server][warnee] = [];
this.warnings[server][warnee].push({
'warner': warner,
'reason': reason,
'time': new Date().getTime()
});
// Notify interested parties
var notifyString = dbot.t('warn_notify', {
'warner': warner,
'warnee': warnee,
'reason': reason,
'url': dbot.api.web.getUrl('warning/' + server + '/' + warnee)
});
if(!_.isUndefined(adminChannel)) {
adminChannel = event.channel.name;
}
dbot.api.report.notify(server, adminChannel, notifyString);
dbot.say(server, adminChannel, notifyString);
dbot.say(server, warnee, notifyString);
},
'~warnings': function(event) {
var warnee = event.params[1],
server = event.server;
if(_.has(this.warnings, server) && _.has(this.warnings[server], warnee)) {
event.reply(dbot.t('warning_info', {
'user': warnee,
'num': this.warnings[server][warnee].length,
'url': dbot.api.web.getUrl('warning/' + server + '/' + warnee)
}));
} else {
event.reply(dbot.t('no_warnings', { 'user': warnee }));
}
}
};
this.commands['~warn'].regex = [/~warn ([^ ]+) (.+)/, 3];
this.commands['~warn'].access = 'moderator';
};
exports.fetch = function(dbot) {
return new warning(dbot);
};

View File

@ -3,7 +3,7 @@ extends ../layout
block content block content
h3 Channels on #{connection} h3 Channels on #{connection}
div#backlink div#backlink
a(href='/connections') « Connection List a(href='/users') « Connection List
ul#quotelist ul#quotelist
-each channel in channels -each channel in channels
a(href='/users/'+connection+'/'+encodeURIComponent(channel)) a(href='/users/'+connection+'/'+encodeURIComponent(channel))

View File

@ -0,0 +1,10 @@
extends ../layout
block content
h3 Servers
div#backlink
a(href='/') « Home
ul#quotelist
-each server in servers
a(href='/warning/'+server)
li.quotes #{server}

10
views/warning/users.jade Normal file
View File

@ -0,0 +1,10 @@
extends ../layout
block content
h3 Users with warnings on #{server}
div#backlink
a(href='/warning') « Server List
ul#quotelist
-each user in users
a(href='/warning/'+server+'/'+user)
li.quotes #{user}

View File

@ -0,0 +1,19 @@
extends ../layout
block content
div#backlink
a(href='/warning/'+server) « Server Warnings
p
div#profile_datatable
table.table.table-hover.data
thead
tr
th Date
th Warner
th Reason
tbody
for warning, key in warnings
tr
td #{new Date(warning.time)}
td #{warning.warner}
td #{warning.reason}