forked from GitHub/dbot
Merge branch 'master' of https://github.com/reality/dbot
This commit is contained in:
commit
a4697e8d36
@ -39,7 +39,8 @@ var commands = function(dbot) {
|
||||
if (this.recentTimeouts[user.id] == 0) {
|
||||
delete this.recentTimeouts[user.id];
|
||||
}
|
||||
}.bind(this), 3600000);
|
||||
}
|
||||
.bind(this), 3600000);
|
||||
|
||||
if (this.recentTimeouts[user.id] == 3) {
|
||||
duration = null;
|
||||
@ -51,7 +52,8 @@ var commands = function(dbot) {
|
||||
event.reply(response);
|
||||
});
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
.bind(this));
|
||||
},
|
||||
|
||||
'~unquiet': function (event) {
|
||||
@ -66,7 +68,9 @@ var commands = function(dbot) {
|
||||
} else {
|
||||
this.api.unquiet(server, this.hosts[server][quietee], channel);
|
||||
}
|
||||
event.reply(dbot.t('unquieted', { 'quietee': quietee }));
|
||||
event.reply(dbot.t('unquieted', {
|
||||
'quietee': quietee
|
||||
}));
|
||||
dbot.api.report.notify('unquiet', server, event.rUser, channel,
|
||||
dbot.t('unquiet_notify', {
|
||||
'unquieter': quieter,
|
||||
@ -98,7 +102,8 @@ var commands = function(dbot) {
|
||||
|
||||
// Kick and ban from all channels on the network.
|
||||
'~nban': function (event) {
|
||||
if(!event.input) return;
|
||||
if (!event.input)
|
||||
return;
|
||||
|
||||
var server = event.server,
|
||||
banner = event.user,
|
||||
@ -116,7 +121,10 @@ var commands = function(dbot) {
|
||||
dbot.api.nickserv.getUserHost(event.server, banee, function (host) {
|
||||
// Add host record entry
|
||||
if (host) {
|
||||
var didKill = false;
|
||||
|
||||
if ((reason.match('#line') || reason.match('#specialk') || reason.match('#kline')) && _.include(dbot.access.moderator(), event.rUser.primaryNick)) {
|
||||
didKill = true;
|
||||
var t = ' !P ';
|
||||
if (timeout) {
|
||||
t = ' !T ' + (timeout * 60);
|
||||
@ -124,6 +132,8 @@ var commands = function(dbot) {
|
||||
dbot.say(event.server, 'operserv', 'akill add ' + banee + t + banee + ' banned by ' + banner + ': ' + reason);
|
||||
}
|
||||
|
||||
// Do not ban if user was killed - redundant
|
||||
if(!didKill) {
|
||||
// Ban from current channel first
|
||||
this.api.ban(server, host, event.channel);
|
||||
this.api.kick(server, banee, event.channel, reason +
|
||||
@ -138,14 +148,18 @@ var commands = function(dbot) {
|
||||
// Ban the user from all channels
|
||||
var i = 0;
|
||||
var banChannel = function (channels) {
|
||||
if(i >= channels.length) return;
|
||||
if (i >= channels.length)
|
||||
return;
|
||||
var channel = channels[i];
|
||||
this.api.ban(server, host, channel);
|
||||
this.api.kick(server, banee, channel, reason +
|
||||
' (network-wide ban)');
|
||||
i++; banChannel(channels);
|
||||
}.bind(this);
|
||||
i++;
|
||||
banChannel(channels);
|
||||
}
|
||||
.bind(this);
|
||||
banChannel(channels);
|
||||
}
|
||||
|
||||
this.hosts[event.server][banee] = host;
|
||||
|
||||
@ -164,9 +178,13 @@ var commands = function(dbot) {
|
||||
timeout += ' hours';
|
||||
}
|
||||
|
||||
if(!_.has(this.tempBans, event.server)) this.tempBans[event.server] = {};
|
||||
// Do not schedule unbans if the user was killed as no ban was put in place
|
||||
if(!didKill) {
|
||||
if (!_.has(this.tempBans, event.server))
|
||||
this.tempBans[event.server] = {};
|
||||
this.tempBans[event.server][banee] = msTimeout;
|
||||
this.internalAPI.addTempBan(event.server, banee, msTimeout);
|
||||
}
|
||||
|
||||
var notifyString = dbot.t('tbanned', {
|
||||
'network': network,
|
||||
@ -232,9 +250,12 @@ var commands = function(dbot) {
|
||||
// err
|
||||
dbot.say(event.server, 'NickServ', 'FREEZE ' + banee + ' ON ' + reason);
|
||||
} else {
|
||||
event.reply(dbot.t('no_user', { 'user': banee }));
|
||||
event.reply(dbot.t('no_user', {
|
||||
'user': banee
|
||||
}));
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
.bind(this));
|
||||
},
|
||||
|
||||
'~nunban': function (event) {
|
||||
@ -244,7 +265,9 @@ var commands = function(dbot) {
|
||||
|
||||
this.api.networkUnban(event.server, unbanee, unbanner, host, function (err) {
|
||||
if (err) {
|
||||
event.reply(dbot.t('nunban_error', { 'unbanee': unbanee }));
|
||||
event.reply(dbot.t('nunban_error', {
|
||||
'unbanee': unbanee
|
||||
}));
|
||||
}
|
||||
});
|
||||
},
|
||||
@ -281,7 +304,9 @@ var commands = function(dbot) {
|
||||
var orderedKickLeague = function (list, topWhat) {
|
||||
var kickArr = _.chain(list)
|
||||
.pairs()
|
||||
.sortBy(function(kick) { return kick[1] })
|
||||
.sortBy(function (kick) {
|
||||
return kick[1]
|
||||
})
|
||||
.reverse()
|
||||
.first(10)
|
||||
.value();
|
||||
@ -310,7 +335,13 @@ var commands = function(dbot) {
|
||||
}
|
||||
|
||||
if (!_.has(this.voteQuiets, user.id)) {
|
||||
this.voteQuiets[user.id] = { 'user': user.id, 'reason': reason, 'channel': event.channel, 'yes': [event.rUser.primaryNick], 'no': [] };
|
||||
this.voteQuiets[user.id] = {
|
||||
'user': user.id,
|
||||
'reason': reason,
|
||||
'channel': event.channel,
|
||||
'yes': [event.rUser.primaryNick],
|
||||
'no': []
|
||||
};
|
||||
event.reply(event.user + ' has started a vote to quiet ' + target + ' for "' + reason + '." Type either "~voteyes ' + target + '" or "~voteno ' + target + '" in the next 90 seconds.');
|
||||
|
||||
this.voteQuiets[user.id].timer = setTimeout(function () {
|
||||
@ -337,8 +368,10 @@ var commands = function(dbot) {
|
||||
|
||||
setTimeout(function () {
|
||||
delete this.voteQuiets[user.id];
|
||||
}.bind(this), 600000);
|
||||
}.bind(this), 90000);
|
||||
}
|
||||
.bind(this), 600000);
|
||||
}
|
||||
.bind(this), 90000);
|
||||
} else {
|
||||
if (this.voteQuiets[user.id].spent) {
|
||||
event.reply('A votequiet attempt has already been made on this user in the last 10 minutes.');
|
||||
@ -357,7 +390,8 @@ var commands = function(dbot) {
|
||||
vq.spent = true;
|
||||
setTimeout(function () {
|
||||
delete this.voteQuiets[user.id];
|
||||
}.bind(this), 600000);
|
||||
}
|
||||
.bind(this), 600000);
|
||||
event.reply(response);
|
||||
});
|
||||
}
|
||||
@ -369,7 +403,8 @@ var commands = function(dbot) {
|
||||
} else {
|
||||
event.reply('Target does not seem to be in the channel.');
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
.bind(this));
|
||||
} else {
|
||||
event.reply('Target does not seem to be in the channel.');
|
||||
}
|
||||
@ -399,7 +434,8 @@ var commands = function(dbot) {
|
||||
vq.spent = true;
|
||||
setTimeout(function () {
|
||||
delete this.voteQuiets[user.id];
|
||||
}.bind(this), 600000);
|
||||
}
|
||||
.bind(this), 600000);
|
||||
event.reply(response);
|
||||
});
|
||||
}
|
||||
@ -412,7 +448,8 @@ var commands = function(dbot) {
|
||||
} else {
|
||||
event.reply('No idea who that is m8');
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
.bind(this));
|
||||
},
|
||||
|
||||
'~voteno': function (event) {
|
||||
@ -440,7 +477,8 @@ var commands = function(dbot) {
|
||||
} else {
|
||||
event.reply('No idea who that is m8');
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
.bind(this));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -78,7 +78,8 @@ var kick = function(dbot) {
|
||||
}), false, quietee);
|
||||
});
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
.bind(this));
|
||||
callback(dbot.t('tquieted', {
|
||||
'quietee': quietee,
|
||||
'minutes': duration
|
||||
@ -89,10 +90,11 @@ var kick = function(dbot) {
|
||||
'quieter': quieter.primaryNick,
|
||||
'quietee': quietee,
|
||||
'reason': reason
|
||||
}), false, quietee
|
||||
);
|
||||
}), false, quietee);
|
||||
} else {
|
||||
callback(dbot.t('quieted', { 'quietee': quietee }));
|
||||
callback(dbot.t('quieted', {
|
||||
'quietee': quietee
|
||||
}));
|
||||
dbot.api.report.notify('quiet', server, quieter.primaryNick, channel,
|
||||
dbot.t('quiet_notify', {
|
||||
'quieter': quieter.primaryNick,
|
||||
@ -115,9 +117,12 @@ var kick = function(dbot) {
|
||||
function () {});
|
||||
}
|
||||
} else {
|
||||
event.reply(dbot.t('no_user', { 'user': quietee }));
|
||||
event.reply(dbot.t('no_user', {
|
||||
'user': quietee
|
||||
}));
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
.bind(this));
|
||||
},
|
||||
|
||||
'networkUnban': function (server, unbanee, unbanner, manualHost, callback) {
|
||||
@ -156,13 +161,16 @@ var kick = function(dbot) {
|
||||
// Unban
|
||||
var i = 0;
|
||||
var unbanChannel = function (channels) {
|
||||
if(i >= channels.length) return;
|
||||
if (i >= channels.length)
|
||||
return;
|
||||
var channel = channels[i];
|
||||
this.api.unban(server, host, channel);
|
||||
setTimeout(function () {
|
||||
i++; unbanChannel(channels);
|
||||
i++;
|
||||
unbanChannel(channels);
|
||||
}, 1000);
|
||||
}.bind(this);
|
||||
}
|
||||
.bind(this);
|
||||
unbanChannel(channels);
|
||||
|
||||
dbot.say(server, 'NickServ', 'FREEZE ' + unbanee + ' OFF');
|
||||
@ -171,13 +179,15 @@ var kick = function(dbot) {
|
||||
// Attempt to look up the host on-the-fly
|
||||
dbot.api.nickserv.getUserHost(server, unbanee, unbanner, function (host) {
|
||||
if (host) {
|
||||
if(!_.has(this.hosts, server)) this.hosts[server] = {};
|
||||
if (!_.has(this.hosts, server))
|
||||
this.hosts[server] = {};
|
||||
this.hosts[server][unbanee] = host;
|
||||
this.api.networkUnban(server, unbanee, unbanner);
|
||||
} else {
|
||||
callback(true); // No host could be found
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
.bind(this));
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -188,15 +198,20 @@ var kick = function(dbot) {
|
||||
dbot.api.timers.addTimeout(timeout, function () {
|
||||
this.api.networkUnban(server, banee, bot, undefined, function (err) {});
|
||||
delete this.tempBans[server][banee];
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}.bind(this)
|
||||
}
|
||||
.bind(this));
|
||||
}
|
||||
.bind(this));
|
||||
}
|
||||
.bind(this)
|
||||
};
|
||||
|
||||
this.listener = function (event) {
|
||||
if (event.kickee == dbot.config.name) {
|
||||
dbot.instance.join(event, event.channel.name);
|
||||
event.reply(dbot.t('kicked_dbot', { 'botname': dbot.config.name }));
|
||||
event.reply(dbot.t('kicked_dbot', {
|
||||
'botname': dbot.config.name
|
||||
}));
|
||||
dbot.db.kicks[dbot.config.name] += 1;
|
||||
} else {
|
||||
if (!_.has(dbot.db.kicks, event.kickee)) {
|
||||
@ -219,7 +234,8 @@ var kick = function(dbot) {
|
||||
}) + ')');
|
||||
}
|
||||
}
|
||||
}.bind(this);
|
||||
}
|
||||
.bind(this);
|
||||
this.on = 'KICK';
|
||||
|
||||
this.onLoad = function () {
|
||||
@ -229,7 +245,8 @@ var kick = function(dbot) {
|
||||
dbot.db.hosts[k] = {};
|
||||
}, this);
|
||||
}
|
||||
if(!_.has(dbot.db, 'tempBans')) dbot.db.tempBans = {};
|
||||
if (!_.has(dbot.db, 'tempBans'))
|
||||
dbot.db.tempBans = {};
|
||||
this.hosts = dbot.db.hosts;
|
||||
this.tempBans = dbot.db.tempBans;
|
||||
this.voteQuiets = {};
|
||||
@ -244,7 +261,8 @@ var kick = function(dbot) {
|
||||
if (_.has(dbot.modules, 'web')) {
|
||||
dbot.api.web.addIndexLink('/bans', 'Ban List');
|
||||
}
|
||||
}.bind(this);
|
||||
}
|
||||
.bind(this);
|
||||
};
|
||||
|
||||
exports.fetch = function (dbot) {
|
||||
|
@ -9,7 +9,9 @@ var pages = function(dbot) {
|
||||
},
|
||||
|
||||
'/underbans': function (req, res) {
|
||||
this.db.search('nbans', { 'server': server }, function(ban) {
|
||||
this.db.search('nbans', {
|
||||
'server': server
|
||||
}, function (ban) {
|
||||
if (ban.reason.match('#underban')) {
|
||||
bans.push(ban);
|
||||
}
|
||||
@ -25,7 +27,9 @@ var pages = function(dbot) {
|
||||
var server = req.params.server,
|
||||
bans = [];
|
||||
|
||||
this.db.search('nbans', { 'server': server }, function(ban) {
|
||||
this.db.search('nbans', {
|
||||
'server': server
|
||||
}, function (ban) {
|
||||
bans.push(ban);
|
||||
}, function () {
|
||||
res.render('bans', {
|
||||
|
@ -6,5 +6,6 @@
|
||||
"________ ______"
|
||||
],
|
||||
"cliconn_channel": "#dnsbl",
|
||||
"cliconn_patterns": []
|
||||
"cliconn_patterns": [],
|
||||
"exempt_channels": []
|
||||
}
|
||||
|
@ -12,25 +12,36 @@ var kill_namespam = function(dbot) {
|
||||
dbot.modules.admin.internalAPI.saveConfig();
|
||||
}.bind(this);
|
||||
|
||||
this.matchedKill = {};
|
||||
|
||||
this.listener = function(event) {
|
||||
if(event.action == 'PRIVMSG') {
|
||||
// Here we listen for atropos
|
||||
if(event.channel == this.config.cliconn_channel) {
|
||||
if(event.message.match('▶')) {
|
||||
var matchedPattern = _.find(this.config.cliconn_patterns,
|
||||
function(p) { try { return event.message.match(p); } catch(e) {}; }); // ok.jpg
|
||||
if(matchedPattern) {
|
||||
var ip = event.message.split(' ')[1]
|
||||
|
||||
// Alternatively you can just do dbot.api.kick.kill(event.server, event.user, message);
|
||||
dbot.say(event.server, 'operserv', 'akill add *@'+ ip +' !P Naughty Nelly Auto-kill v6.2. Matched pattern: /'+ matchedPattern +'/');
|
||||
|
||||
var msg = dbot.t('clikill_act', {
|
||||
'ip': ip,
|
||||
var nick = event.message.split(' ')[2];
|
||||
dbot.api.nickserv.getUserHost(event.server, nick, function(host) {
|
||||
var userIsAuthenticated = host && host.startsWith('tripsit/');
|
||||
if (userIsAuthenticated) {
|
||||
event.reply(dbot.t('clikill_spared', {
|
||||
'user': nick,
|
||||
'pattern': matchedPattern
|
||||
});
|
||||
event.reply(msg);
|
||||
dbot.api.report.notify('autokill', event.server, event.rUser,
|
||||
dbot.config.servers[event.server].admin_channel, msg, ip, ip);
|
||||
}));
|
||||
} else {
|
||||
if(!this.matchedKill[host]) {
|
||||
// Defer killing this connection until after they join a non-exempted channel
|
||||
this.matchedKill[host] = {
|
||||
ip: event.message.split(' ')[1],
|
||||
server: event.server,
|
||||
matchedPattern: matchedPattern,
|
||||
rUser: event.rUser
|
||||
};
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -76,8 +87,31 @@ var kill_namespam = function(dbot) {
|
||||
|
||||
dbot.api.report.notify('spam', event.server, event.user, event.channel, message, event.host, event.user);
|
||||
}
|
||||
} else if (event.action == 'JOIN') {
|
||||
|
||||
if(this.matchedKill[event.host]) {
|
||||
if(this.config.exempt_channels.indexOf(event.channel) == -1) {
|
||||
var kill = this.matchedKill[event.host];
|
||||
delete this.matchedKill[event.host];
|
||||
|
||||
// Alternatively you can just do dbot.api.kick.kill(event.server, event.user, message);
|
||||
dbot.say(event.server, 'operserv', 'akill add *@'+ kill.ip +' !P Naughty Nelly Auto-kill v6.2. Matched pattern: /'+ kill.matchedPattern +'/');
|
||||
|
||||
var msg = dbot.t('clikill_act', {
|
||||
'ip': kill.ip,
|
||||
'pattern': kill.matchedPattern
|
||||
});
|
||||
dbot.api.report.notify('autokill', kill.server, kill.rUser,
|
||||
dbot.config.servers[kill.server].admin_channel, msg, kill.ip, kill.ip);
|
||||
}
|
||||
}
|
||||
} else if (event.action == 'QUIT') {
|
||||
if(this.matchedKill[event.host]) {
|
||||
delete this.matchedKill[event.host];
|
||||
}
|
||||
}
|
||||
}.bind(this);
|
||||
this.on = 'PRIVMSG';
|
||||
this.on = ['PRIVMSG', 'JOIN', 'QUIT'];
|
||||
|
||||
this.commands = {
|
||||
'~add_spamkill': function(event) {
|
||||
|
@ -7,5 +7,8 @@
|
||||
},
|
||||
"clikill_act": {
|
||||
"en": "Added K-Line for {ip}, due to matching pattern: /{pattern}/"
|
||||
},
|
||||
"clikill_spared": {
|
||||
"en": "{user} spared from clikill matched pattern: /{pattern}/"
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,8 @@ var link = function(dbot) {
|
||||
},
|
||||
|
||||
'~xkcd': function(event) {
|
||||
var comicId = event.params[1] || "";
|
||||
//var comicId = event.params[1] || "";
|
||||
var comicId = event.params.slice(1).join(' ');
|
||||
|
||||
if(comicId == "*") {
|
||||
request("http://xkcd.com/info.0.json", function(error, response, body){
|
||||
@ -109,6 +110,65 @@ var link = function(dbot) {
|
||||
}
|
||||
} catch(err) { };
|
||||
});
|
||||
} else {
|
||||
if (isNaN(parseInt(comicId))) {
|
||||
request({
|
||||
url: 'http://www.explainxkcd.com/wiki/api.php',
|
||||
qs: {
|
||||
action: 'query',
|
||||
format: 'json',
|
||||
generator: 'search',
|
||||
gsrwhat: 'text',
|
||||
gsrsearch: comicId,
|
||||
prop: 'info|categories',
|
||||
gsrlimit: 50
|
||||
},
|
||||
json: true
|
||||
}, function(err, res, body) {
|
||||
if(!body) {
|
||||
event.reply(dbot.t("no-hits"));
|
||||
return;
|
||||
}
|
||||
|
||||
var pages = _.values(body.query.pages);
|
||||
|
||||
// page titles must be of the format "####: $$$$$$"
|
||||
pages = _.filter(pages, p => p.title.indexOf(':') > 0);
|
||||
|
||||
if (pages.length > 0) {
|
||||
// See if any of these matches are exact title matches
|
||||
var match = false;
|
||||
_.each(pages, function(p) {
|
||||
var title = p.title.slice(p.title.indexOf(':')+2).trim();
|
||||
if(title.toLowerCase() == comicId.toLowerCase()) {
|
||||
match = p;
|
||||
}
|
||||
});
|
||||
|
||||
if (match) {
|
||||
// We got a match! Get the ID and let's get tf out of here.
|
||||
comicId = match.title.slice(0, match.title.indexOf(':'));
|
||||
} else {
|
||||
comicId = pages[0].title.slice(0, pages[0].title.indexOf(':'));
|
||||
}
|
||||
|
||||
var link = "http://xkcd.com/"+comicId+"/info.0.json";
|
||||
request(link, function(error, response, body) {
|
||||
try {
|
||||
if (response.statusCode == "200") {
|
||||
data = JSON.parse(body);
|
||||
event.reply(dbot.t("xkcd", data));
|
||||
} else {
|
||||
event.reply(dbot.t("no-hits"));
|
||||
}
|
||||
} catch(err) { };
|
||||
});
|
||||
|
||||
|
||||
} else {
|
||||
event.reply(dbot.t("no-hits"));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if(comicId !== "") {
|
||||
comicId = comicId + "/";
|
||||
@ -126,7 +186,7 @@ var link = function(dbot) {
|
||||
} catch(err) { };
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
'~ud': function(event) {
|
||||
|
@ -26,12 +26,15 @@ var nickserv = function(dbot) {
|
||||
}.bind(this), 6000);
|
||||
},
|
||||
|
||||
'getUserHost': function(server, nick, callback) {
|
||||
'getUserHost': function(server, nick, callback, skipFallback) {
|
||||
if(!_.has(this.userStack, server)) this.userStack[server] = {};
|
||||
this.userStack[server][nick] = callback;
|
||||
dbot.instance.connections[server].send('USERHOST ' + nick);
|
||||
setTimeout(function() {
|
||||
if(_.has(this.userStack[server], nick)) {
|
||||
if (skipFallback) {
|
||||
callback(false);
|
||||
} else {
|
||||
dbot.instance.connections[server].send('WHOWAS ' + nick + ' 1');
|
||||
setTimeout(function() {
|
||||
if(_.has(this.userStack[server], nick)) {
|
||||
@ -39,6 +42,7 @@ var nickserv = function(dbot) {
|
||||
}
|
||||
}.bind(this), 2000);
|
||||
}
|
||||
}
|
||||
}.bind(this), 4000);
|
||||
}
|
||||
};
|
||||
|
6
modules/omdb/config.json
Normal file
6
modules/omdb/config.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"dependencies": [ ],
|
||||
"ignorable": true,
|
||||
"outputPrefix": "omdb",
|
||||
"api_key": "insert api key here - get from http://www.omdbapi.com/apikey.aspx"
|
||||
}
|
83
modules/omdb/omdb.js
Normal file
83
modules/omdb/omdb.js
Normal file
@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Module Name: omdb
|
||||
* Description: Interacts with the Open Movie Database to provide movie summary
|
||||
* and review information.
|
||||
*/
|
||||
|
||||
var rp = require('request-promise-native'),
|
||||
_ = require('underscore')._;
|
||||
|
||||
var OMDB = function(dbot) {
|
||||
this.apiRoot = 'http://www.omdbapi.com';
|
||||
this.imdbLinkPrefix = 'https://www.imdb.com/title/';
|
||||
|
||||
this.internalAPI = {
|
||||
formatLink: r => {
|
||||
var aRating = parseFloat(r.imdbRating) * 10;
|
||||
var cRating = parseFloat(r.Metascore);
|
||||
|
||||
if (isNaN(aRating)) {
|
||||
aRating = " N/A";
|
||||
} else {
|
||||
var aColour = (aRating <= 5) ? '\u00033 ' : '\u00034 ';
|
||||
aRating = aColour + String(aRating) + '%\u000f';
|
||||
}
|
||||
|
||||
if (isNaN(cRating)) {
|
||||
cRating = " N/A";
|
||||
} else {
|
||||
var cColour = (cRating <= 5) ? '\u00033 ' : '\u00034 ';
|
||||
cRating = cColour + String(cRating) + '%\u000f';
|
||||
}
|
||||
|
||||
var mString = dbot.t('omdb_film', {
|
||||
'title': r.Title,
|
||||
'year': r.Year,
|
||||
'aRating': aRating,
|
||||
'cRating': cRating
|
||||
});
|
||||
|
||||
if (_.has(r, 'Director') && r.Director != "N/A") mString += ' [Director: ' + r.Director + ']';
|
||||
if (_.has(r, 'Genre') && r.Genre != "N/A") mString += ' [Genre: ' + r.Genre + ']';
|
||||
if (_.has(r, 'Plot') && r.Plot != "N/A") {
|
||||
if (r.Plot.length > 140) r.Plot = r.Plot.substring(0, 140) + '...';
|
||||
mString += ' [Plot: ' + r.Plot + ']';
|
||||
}
|
||||
|
||||
mString += ' - ' + this.imdbLinkPrefix + r.imdbID;
|
||||
|
||||
return mString;
|
||||
}
|
||||
};
|
||||
|
||||
this.commands = {
|
||||
'~movie': async event => {
|
||||
try {
|
||||
var r = await rp({
|
||||
url: this.apiRoot,
|
||||
qs: {
|
||||
apikey: this.config.api_key,
|
||||
t: event.input[1],
|
||||
plot: 'short',
|
||||
r: 'json'
|
||||
},
|
||||
json: true
|
||||
});
|
||||
|
||||
if (r.Response === 'True') {
|
||||
event.reply(this.internalAPI.formatLink(r));
|
||||
} else {
|
||||
event.reply(dbot.t('omdb_noresults'));
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.commands['~movie'].regex = [/^movie (.+)$/, 2];
|
||||
}
|
||||
|
||||
|
||||
exports.fetch = dbot => new OMDB(dbot);
|
10
modules/omdb/strings.json
Normal file
10
modules/omdb/strings.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"omdb_film": {
|
||||
"en": "[{title} - Audience:{aRating} - Critic:{cRating} - {year}]",
|
||||
"de": "[{title} - {aRating} - {year}]"
|
||||
},
|
||||
"omdb_noresults": {
|
||||
"en": "No films found.",
|
||||
"de": "Kein Film gefunden."
|
||||
}
|
||||
}
|
@ -113,6 +113,8 @@ var spotify = function(dbot) {
|
||||
}
|
||||
}
|
||||
};
|
||||
commands['~sp'] = commands['~spotify'].bind(this);
|
||||
commands['~sp'].regex = [/^sp (.*)/, 2];
|
||||
commands['~spotify'].regex = [/^spotify (.*)/, 2];
|
||||
this.commands = commands;
|
||||
|
||||
|
@ -30,13 +30,14 @@ var youtube = function(dbot) {
|
||||
|
||||
this.internalAPI = {
|
||||
'formatLink': function(v) {
|
||||
var time = v.contentDetails.duration.match(/^PT(\d+)?M?(\d+)S$/);
|
||||
var time = v.contentDetails.duration.match(/^PT(?:(\d+)M)?(\d+)S$/);
|
||||
|
||||
if(time) {
|
||||
if(time[1]) {
|
||||
var seconds =((time[2]%60 < 10) ? "0"+time[2]%60 : time[2]%60),
|
||||
minutes = time[1];
|
||||
} else {
|
||||
var seconds =((time[1]%60 < 10) ? "0"+time[1]%60 : time[1]%60),
|
||||
var seconds =((time[2]%60 < 10) ? "0"+time[2]%60 : time[2]%60),
|
||||
minutes = 0;
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user