mirror of
https://github.com/reality/dbot.git
synced 2024-12-24 03:33:07 +01:00
Merge github.com:reality/depressionbot into database
This commit is contained in:
commit
f5fb2322b1
@ -31,10 +31,18 @@ var api = function(dbot) {
|
||||
var applies = false;
|
||||
if(_.has(dbot.commands[commandName], 'regex')) {
|
||||
var cRegex = dbot.commands[commandName].regex;
|
||||
var q = event.message.valMatch(cRegex[0], cRegex[1]);
|
||||
if(q) {
|
||||
applies = true;
|
||||
event.input = q;
|
||||
if(_.isArray(cRegex) && cRegex.length == 2) {
|
||||
var q = event.message.valMatch(cRegex[0], cRegex[1]);
|
||||
if(q) {
|
||||
applies = true;
|
||||
event.input = q;
|
||||
}
|
||||
} else {
|
||||
var q = event.message.match(cRegex);
|
||||
if(q) {
|
||||
applies = true;
|
||||
event.input = q;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
applies = true;
|
||||
|
@ -1,3 +1,4 @@
|
||||
{
|
||||
"ignorable": true
|
||||
"ignorable": true,
|
||||
"help": "https://github.com/reality/depressionbot/blob/master/modules/ctcp/README.md"
|
||||
}
|
||||
|
@ -3,5 +3,6 @@
|
||||
"password": "yourpasswordhere",
|
||||
"dependencies": [ "command" ],
|
||||
"ignorable": true,
|
||||
"help": "https://github.com/reality/depressionbot/blob/master/modules/dent/README.md",
|
||||
"dentQuotes": false
|
||||
}
|
||||
|
3
modules/dns/config.json
Normal file
3
modules/dns/config.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"help": "https://github.com/reality/depressionbot/blob/master/modules/dns/README.md"
|
||||
}
|
3
modules/event/config.json
Normal file
3
modules/event/config.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"help": "https://github.com/reality/depressionbot/blob/master/modules/event/README.md"
|
||||
}
|
@ -28,11 +28,8 @@ var flashy = function(dbot) {
|
||||
var text = event.input[2].trim().toUpperCase();
|
||||
|
||||
if(_.has(this.colourMap, colour)) {
|
||||
event.reply(dbot.t('url', {
|
||||
'host': dbot.config.web.webHost,
|
||||
'port': dbot.config.web.webPort,
|
||||
'path': 'flashy/' + colour + '/' + encodeURIComponent(text)
|
||||
}));
|
||||
event.reply(dbot.api.web.getUrl('flashy/' + colour + '/' +
|
||||
encodeURIComponent(text)));
|
||||
} else {
|
||||
var possibleColours = _.keys(this.colourMap).join(', ') + '.';
|
||||
event.reply('No such colour, brah. Available colours are: ' + possibleColours);
|
||||
|
@ -16,12 +16,17 @@ var imgur = function(dbot) {
|
||||
if(imgData.title) {
|
||||
info += imgData.title + ' is ';
|
||||
}
|
||||
if(imgData.animated) {
|
||||
info += 'an animated ' + imgData.type.split('/')[1] + ' with ';
|
||||
if(imgData.type) {
|
||||
if(imgData.animated) {
|
||||
info += 'an animated ' + imgData.type.split('/')[1] + ' with ';
|
||||
} else {
|
||||
info += 'a ' + imgData.type.split('/')[1] + ' with ';
|
||||
}
|
||||
} else {
|
||||
info += 'a non-animated ' + imgData.type.split('/')[1] + ' with ';
|
||||
info += 'an image with ';
|
||||
}
|
||||
info += imgData.views + ' views].';
|
||||
info += imgData.views + ' views (';
|
||||
info += imgData.width + 'x' + imgData.height + ')].';
|
||||
}
|
||||
|
||||
return info;
|
||||
@ -76,15 +81,15 @@ var imgur = function(dbot) {
|
||||
|
||||
this.onLoad = function() {
|
||||
var imgurHandler = function(event, matches, name) {
|
||||
if(matches[2]) { // TODO: handle this in the regex
|
||||
if(matches[1]) {
|
||||
this.api.getImageInfo(matches[1], function(imgData) {
|
||||
var info = this.internalAPI.infoString(imgData);
|
||||
if(info) event.reply(info);
|
||||
}.bind(this));
|
||||
}
|
||||
}.bind(this);
|
||||
dbot.api.link.addHandler(this.name, /http:\/\/i\.imgur\.com\/([a-zA-Z0-9]+)\.([jpg|png|gif])/, imgurHandler);
|
||||
dbot.api.link.addHandler(this.name, /\bhttps?:\/\/imgur\.com\/([a-zA-Z0-9]+)\b/i, imgurHandler);
|
||||
dbot.api.link.addHandler(this.name, /https?:\/\/i\.imgur\.com\/([a-zA-Z0-9]+)\.([jpg|png|gif])/, imgurHandler);
|
||||
dbot.api.link.addHandler(this.name, /https?:\/\/imgur\.com\/([a-zA-Z0-9]+)/, imgurHandler);
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
|
78
modules/kick/commands.js
Normal file
78
modules/kick/commands.js
Normal file
@ -0,0 +1,78 @@
|
||||
var commands = function(dbot) {
|
||||
var commands = {
|
||||
/*** Kick Management ***/
|
||||
'~ckick': function(event) {
|
||||
var server = event.server,
|
||||
kicker = event.user,
|
||||
kickee = event.input[2],
|
||||
channel = event.input[1],
|
||||
reason = event.input[3];
|
||||
|
||||
this.api.kick(server, kickee, channel, reason + ' (requested by ' + kicker + ')');
|
||||
dbot.api.report.notify(server, channel, kicker, kickee, dbot.t('ckicked', {
|
||||
'kicker': kicker,
|
||||
'kickee': kickee,
|
||||
'channel': channel,
|
||||
'reason': reason
|
||||
}));
|
||||
},
|
||||
|
||||
/*** Kick Stats ***/
|
||||
|
||||
// Give the number of times a given user has been kicked and has kicked
|
||||
// other people.
|
||||
'~kickcount': function(event) {
|
||||
var username = event.params[1];
|
||||
|
||||
if(!_.has(dbot.db.kicks, username)) {
|
||||
var kicks = '0';
|
||||
} else {
|
||||
var kicks = dbot.db.kicks[username];
|
||||
}
|
||||
|
||||
if(!_.has(dbot.db.kickers, username)) {
|
||||
var kicked = '0';
|
||||
} else {
|
||||
var kicked = dbot.db.kickers[username];
|
||||
}
|
||||
|
||||
event.reply(dbot.t('user_kicks', {
|
||||
'user': username,
|
||||
'kicks': kicks,
|
||||
'kicked': kicked
|
||||
}));
|
||||
},
|
||||
|
||||
// Output a list of the people who have been kicked the most and those
|
||||
// who have kicked other people the most.
|
||||
'~kickstats': function(event) {
|
||||
var orderedKickLeague = function(list, topWhat) {
|
||||
var kickArr = _.chain(list)
|
||||
.pairs()
|
||||
.sortBy(function(kick) { return kick[1] })
|
||||
.reverse()
|
||||
.first(10)
|
||||
.value();
|
||||
|
||||
var kickString = "Top " + topWhat + ": ";
|
||||
for(var i=0;i<kickArr.length;i++) {
|
||||
kickString += kickArr[i][0] + " (" + kickArr[i][1] + "), ";
|
||||
}
|
||||
|
||||
return kickString.slice(0, -2);
|
||||
};
|
||||
|
||||
event.reply(orderedKickLeague(dbot.db.kicks, 'Kicked'));
|
||||
event.reply(orderedKickLeague(dbot.db.kickers, 'Kickers'));
|
||||
}
|
||||
};
|
||||
|
||||
commands['~ckick'].access = 'moderator';
|
||||
commands['~ckick'].regex = [/^~ckick ([^ ]+) ([^ ]+) (.+)$/, 4];
|
||||
|
||||
return commands;
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return commands(dbot);
|
||||
};
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"dbKeys": [ "kicks", "kickers" ],
|
||||
"dependencies": [ "command" ],
|
||||
"dependencies": [ "command", "report", "users" ],
|
||||
"help": "http://github.com/reality/depressionbot/blob/master/modules/kick/README.md",
|
||||
"ignorable": true
|
||||
"ignorable": true,
|
||||
"countSilently": true
|
||||
}
|
||||
|
@ -1,56 +1,7 @@
|
||||
var _ = require('underscore')._;
|
||||
|
||||
var kick = function(dbot) {
|
||||
var commands = {
|
||||
// Give the number of times a given user has been kicked and has kicked
|
||||
// other people.
|
||||
'~kickcount': function(event) {
|
||||
var username = event.params[1];
|
||||
|
||||
if(!_.has(dbot.db.kicks, username)) {
|
||||
var kicks = '0';
|
||||
} else {
|
||||
var kicks = dbot.db.kicks[username];
|
||||
}
|
||||
|
||||
if(!_.has(dbot.db.kickers, username)) {
|
||||
var kicked = '0';
|
||||
} else {
|
||||
var kicked = dbot.db.kickers[username];
|
||||
}
|
||||
|
||||
event.reply(dbot.t('user_kicks', {
|
||||
'user': username,
|
||||
'kicks': kicks,
|
||||
'kicked': kicked
|
||||
}));
|
||||
},
|
||||
|
||||
// Output a list of the people who have been kicked the most and those
|
||||
// who have kicked other people the most.
|
||||
'~kickstats': function(event) {
|
||||
var orderedKickLeague = function(list, topWhat) {
|
||||
var kickArr = _.chain(list)
|
||||
.pairs()
|
||||
.sortBy(function(kick) { return kick[1] })
|
||||
.reverse()
|
||||
.first(10)
|
||||
.value();
|
||||
|
||||
var kickString = "Top " + topWhat + ": ";
|
||||
for(var i=0;i<kickArr.length;i++) {
|
||||
kickString += kickArr[i][0] + " (" + kickArr[i][1] + "), ";
|
||||
}
|
||||
|
||||
return kickString.slice(0, -2);
|
||||
};
|
||||
|
||||
event.reply(orderedKickLeague(dbot.db.kicks, 'Kicked'));
|
||||
event.reply(orderedKickLeague(dbot.db.kickers, 'Kickers'));
|
||||
}
|
||||
};
|
||||
this.commands = commands;
|
||||
|
||||
|
||||
this.api = {
|
||||
'ban': function(server, user, channel) {
|
||||
dbot.instance.connections[server].send('MODE ' + channel + ' +b ' + user + '!*@*');
|
||||
@ -79,13 +30,15 @@ var kick = function(dbot) {
|
||||
dbot.db.kickers[event.user] += 1;
|
||||
}
|
||||
|
||||
event.reply(event.kickee + '-- (' + dbot.t('user_kicks', {
|
||||
'user': event.kickee,
|
||||
'kicks': dbot.db.kicks[event.kickee],
|
||||
'kicked': dbot.db.kickers[event.kickee]
|
||||
}) + ')');
|
||||
if(!this.config.countSilently) {
|
||||
event.reply(event.kickee + '-- (' + dbot.t('user_kicks', {
|
||||
'user': event.kickee,
|
||||
'kicks': dbot.db.kicks[event.kickee],
|
||||
'kicked': dbot.db.kickers[event.kickee]
|
||||
}) + ')');
|
||||
}
|
||||
}
|
||||
};
|
||||
}.bind(this);
|
||||
this.on = 'KICK';
|
||||
};
|
||||
|
||||
|
@ -10,5 +10,8 @@
|
||||
"es": "No expulsás {botname}",
|
||||
"na'vi": "Ngal {botname}it ke tsun tsrive'i",
|
||||
"cy": "Ni ddylech cicio {botname}"
|
||||
},
|
||||
"ckicked": {
|
||||
"en": "Attention: {kicker} has kicked {kickee} from {channel}. The reason given was: \"{reason}.\""
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ var commands = function(dbot){
|
||||
if(event.params[1]){
|
||||
var primary = dbot.api.users.resolveUser(event.server, event.params[1]);
|
||||
if(_.has(dbot.db.profiles[event.server], primary.toLowerCase())){
|
||||
event.reply(dbot.api.web.getUrl("/profile/"+event.server+"/"+primary.toLowerCase());
|
||||
event.reply(dbot.api.web.getUrl("profile/"+event.server+"/"+primary.toLowerCase()));
|
||||
}
|
||||
else{
|
||||
event.reply("No profile found for "+event.params[1]);
|
||||
|
115
modules/reddit/reddit.js
Normal file
115
modules/reddit/reddit.js
Normal file
@ -0,0 +1,115 @@
|
||||
/**
|
||||
* Module Name: reddit
|
||||
* Description: Various reddit functionality
|
||||
*/
|
||||
var _ = require('underscore')._,
|
||||
request = require('request');
|
||||
|
||||
var reddit = function(dbot) {
|
||||
this.ApiRoot = 'http://reddit.com/';
|
||||
this.UserAgent = 'dbot by u/realitone';
|
||||
|
||||
this.api = {
|
||||
'getSubredditInfo': function(name, callback) {
|
||||
request.get({
|
||||
'url': this.ApiRoot + 'r/' + name + '/about.json',
|
||||
'json': true,
|
||||
'headers': {
|
||||
'User-Agent': this.UserAgent
|
||||
}
|
||||
}, function(err, response, body) {
|
||||
var data = null;
|
||||
if(_.has(body, 'data')) data = body.data;
|
||||
callback(data);
|
||||
});
|
||||
},
|
||||
|
||||
'getPostInfo': function(name, callback) {
|
||||
request.get({
|
||||
'url': this.ApiRoot + 'comments/' + name + '.json',
|
||||
'json': true,
|
||||
'headers': {
|
||||
'User-Agent': this.UserAgent
|
||||
}
|
||||
}, function(err, response, body) {
|
||||
if(body[0] && _.has(body[0], 'data')) {
|
||||
callback(body[0].data.children[0].data);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
'getCommentInfo': function(post, name, callback) {
|
||||
request.get({
|
||||
'url': this.ApiRoot + 'comments/' + post + '.json',
|
||||
'qs': {
|
||||
'comment': name
|
||||
},
|
||||
'json': true,
|
||||
'headers': {
|
||||
'User-Agent': this.UserAgent
|
||||
}
|
||||
}, function(err, response, body) {
|
||||
if(body[1] && _.has(body[1], 'data')) {
|
||||
callback(body[1].data.children[0].data);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.onLoad = function() {
|
||||
var rHandler = function(event, matches, name) {
|
||||
if(matches[6]) { // It's a comment
|
||||
this.api.getCommentInfo(matches[4], matches[6], function(info) {
|
||||
if(info) {
|
||||
var infoString = dbot.t('about_comment', {
|
||||
'poster': info.author,
|
||||
'subreddit': info.subreddit,
|
||||
'comments': info.num_comments,
|
||||
'score': info.ups - info.downs,
|
||||
'up': info.ups,
|
||||
'down': info.downs
|
||||
});
|
||||
if(info.over_18) infoString += " " + dbot.t("nsfw");
|
||||
event.reply(infoString);
|
||||
}
|
||||
});
|
||||
} else if(matches[4]) { // It's a post
|
||||
this.api.getPostInfo(matches[4], function(info) {
|
||||
if(info) {
|
||||
var infoString = dbot.t('about_post', {
|
||||
'poster': info.author,
|
||||
'subreddit': info.subreddit,
|
||||
'comments': info.num_comments,
|
||||
'score': info.score,
|
||||
'up': info.ups,
|
||||
'down': info.downs,
|
||||
'url': this.ApiRoot + matches[4]
|
||||
});
|
||||
if(info.over_18) infoString += " " + dbot.t("nsfw");
|
||||
event.reply(infoString);
|
||||
}
|
||||
}.bind(this));
|
||||
} else if(matches[2]) { // It's a subreddit
|
||||
this.api.getSubredditInfo(matches[2], function(info) {
|
||||
if(info) {
|
||||
var infoString = dbot.t('about_subreddit', {
|
||||
'display_name': info.display_name,
|
||||
'subscribers': info.subscribers,
|
||||
'active': info.accounts_active
|
||||
});
|
||||
if(info.over18) infoString += dbot.t("nsfw");
|
||||
event.reply(infoString);
|
||||
}
|
||||
});
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
dbot.api.link.addHandler(this.name, // I'm so sorry, Jesus.
|
||||
/https?:\/\/(www\.)?reddit\.com\/r\/([a-zA-Z0-9]+)(\/comments\/([a-zA-Z0-9]+)?\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)?)?/,
|
||||
rHandler);
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return new reddit(dbot);
|
||||
}
|
14
modules/reddit/strings.json
Normal file
14
modules/reddit/strings.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"about_subreddit": {
|
||||
"en": "[{display_name} has {subscribers} subscribers ({active} active)]"
|
||||
},
|
||||
"about_post": {
|
||||
"en": "[Post by {poster} in {subreddit} — Comments: {comments}, Score: {score} (\u00039▲{up}\u000f|\u000312{down}▼\u000f)] — {url}"
|
||||
},
|
||||
"about_comment": {
|
||||
"en": "[Comment by {poster} in {subreddit} — Score: {score} (\u00039▲{up}\u000f|\u000312{down}▼\u000f)]"
|
||||
},
|
||||
"nsfw": {
|
||||
"en": "[NSFW]"
|
||||
}
|
||||
}
|
@ -1,6 +1,23 @@
|
||||
var _ = require('underscore')._;
|
||||
|
||||
var report = function(dbot) {
|
||||
this.api = {
|
||||
'notify': function(server, channel, reporter, reported, message) {
|
||||
var channel = dbot.instance.connections[server].channels[channel];
|
||||
var ops = _.filter(channel.nicks, function(user) {
|
||||
if(this.config.notifyVoice) {
|
||||
return user.op || user.voice;
|
||||
} else {
|
||||
return user.op;
|
||||
}
|
||||
}, this);
|
||||
|
||||
_.each(ops, function(user) {
|
||||
dbot.say(server, user.name, message);
|
||||
}, this);
|
||||
}
|
||||
};
|
||||
|
||||
var commands = {
|
||||
'~report': function(event) {
|
||||
var channelName = event.input[1];
|
||||
@ -8,31 +25,21 @@ var report = function(dbot) {
|
||||
var reason = event.input[3];
|
||||
|
||||
if(_.has(event.allChannels, channelName)) {
|
||||
var channel = event.allChannels[channelName];
|
||||
if(dbot.api.users.isChannelUser(event.server, nick, channelName, true)) {
|
||||
var nick = dbot.api.users.resolveUser(event.server, nick, true);
|
||||
var ops = _.filter(channel.nicks, function(user) {
|
||||
if(this.config.notifyVoice) {
|
||||
return user.op || user.voice;
|
||||
} else {
|
||||
return user.op;
|
||||
}
|
||||
}, this);
|
||||
|
||||
_.each(ops, function(user) {
|
||||
dbot.say(event.server, user.name, dbot.t('report', {
|
||||
'reporter': event.user,
|
||||
'reported': nick,
|
||||
'channel': channelName,
|
||||
'reason': reason
|
||||
}));
|
||||
}, this);
|
||||
|
||||
nick = dbot.api.users.resolveUser(event.server, nick, true);
|
||||
this.api.notify(event.server, channelName, event.user, nick, dbot.t('report', {
|
||||
'reporter': event.user,
|
||||
'reported': nick,
|
||||
'channel': channelName,
|
||||
'reason': reason
|
||||
}));
|
||||
event.reply(dbot.t('reported', { 'reported': nick }));
|
||||
} else {
|
||||
event.reply(dbot.t('user_not_found', { 'reported': nick,
|
||||
'channel': channelName }));
|
||||
}
|
||||
event.reply(dbot.t('user_not_found', {
|
||||
'reported': nick,
|
||||
'channel': channelName
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
event.reply(dbot.t('not_in_channel', { 'channel': channelName }));
|
||||
}
|
||||
|
3
modules/timers/config.json
Normal file
3
modules/timers/config.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"help": "https://github.com/reality/depressionbot/blob/master/modules/timers/README.md"
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"webHost": "localhost",
|
||||
"webPort": 8080,
|
||||
"externalPath": false
|
||||
"externalPath": false,
|
||||
"help": "https://github.com/reality/depressionbot/blob/master/modules/web/README.md"
|
||||
}
|
||||
|
@ -41,12 +41,15 @@ var webInterface = function(dbot) {
|
||||
|
||||
this.api = {
|
||||
'getUrl': function(path) {
|
||||
console.log(path);
|
||||
if(this.config.externalPath) {
|
||||
console.log('external');
|
||||
return this.config.externalPath + '/' + path;
|
||||
} else {
|
||||
return 'http://' + this.config.webHost + ':' + port + '/' + path;
|
||||
console.log('internal');
|
||||
return 'http://' + this.config.webHost + ':' + this.config.webPort + '/' + path;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user