3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-24 03:33:07 +01:00

Fix dbot for the new jsbot changes passing channel as an object rather than a string. plus some efficiency changes and extra checks and stuff in admin

This commit is contained in:
Luke Slater 2012-12-02 15:28:32 +00:00
parent 09947921d1
commit c690611cdc
7 changed files with 46 additions and 32 deletions

2
jsbot

@ -1 +1 @@
Subproject commit 6723ded150692bd157b43ac287a3913abd1d7a99
Subproject commit 87ede262d4d384878941eb17095e4dc0e1b57962

View File

@ -12,21 +12,34 @@ var admin = function(dbot) {
// Join a channel
'join': function(event) {
var channel = event.params[1];
dbot.instance.join(event, channel);
event.reply(dbot.t('join', {'channel': channel}));
if(event.allChannels.hasOwnProperty(channel)) {
event.reply("I'm already in that channel.");
} else {
dbot.instance.join(event, channel);
event.reply(dbot.t('join', {'channel': channel}));
}
},
// Leave a channel
'part': function(event) {
var channel = event.params[1];
event.instance.part(event, channel);
event.reply(dbot.t('part', {'channel': channel}));
if(!event.allChannels.hasOwnProperty(channel)) {
event.reply("I'm not in that channel.");
} else {
event.instance.part(event, channel);
event.reply(dbot.t('part', {'channel': channel}));
}
},
// Op admin caller in given channel
'opme': function(event) {
event.channel = event.params[1];
dbot.instance.mode(event, '+o ' + event.user);
var channel = event.params[1];
// If given channel isn't valid just op in current one.
if(!event.allChannels.hasOwnProperty(channel)) {
channel = event.channel.name;
}
dbot.instance.mode(event, channel, ' +o ' + event.user);
},
// Do a git pull and reload
@ -49,7 +62,7 @@ var admin = function(dbot) {
'say': function(event) {
var channel = event.params[1];
if(event.params[1] === "@") {
var channel = event.channel;
var channel = event.channel.name;
}
var message = event.params.slice(2).join(' ');
dbot.say(event.server, channel, message);

View File

@ -10,7 +10,7 @@ var link = function(dbot) {
var commands = {
'~title': function(event) {
var link = links[event.channel];
var link = links[event.channel.name];
if(event.params[1] !== undefined) {
var urlMatches = event.params[1].match(urlRegex);
if(urlMatches !== null) {
@ -40,7 +40,7 @@ var link = function(dbot) {
'listener': function(event) {
var urlMatches = event.message.match(urlRegex);
if(urlMatches !== null) {
links[event.channel] = urlMatches[0];
links[event.channel.name] = urlMatches[0];
}
},
'on': 'PRIVMSG'

View File

@ -5,8 +5,8 @@ var report = function(dbot) {
var nick = event.input[2];
var reason = event.input[3];
if(dbot.instance.connections[event.server].channels.hasOwnProperty(channelName)) {
var channel = dbot.instance.connections[event.server].channels[channelName];
if(event.allChannels.hasOwnProperty(channelName)) {
var channel = event.allChannels[channelName];
if(channel.nicks.hasOwnProperty(nick)) {
var ops = [];
for(var possibOps in channel.nicks) {
@ -15,6 +15,11 @@ var report = function(dbot) {
}
}
// Does the channel have an admin channel?
if(event.allChannels.hasOwnProperty('#' + channelName)) {
ops.push('#' + channelName);
}
for(var i=0;i<ops.length;i++) {
dbot.say(event.server, ops[i],
'Attention: ' + event.user + ' has reported ' +
@ -22,21 +27,12 @@ var report = function(dbot) {
'given was: "' + reason + '."');
}
if(dbot.instance.connections[event.server].channels.hasOwnProperty('#'+
channelName)) {
var adminChannel = '#' + channelName;
dbot.say(event.server, adminChannel,
'Attention: ' + event.user + ' has reported ' +
nick + ' in ' + channelName + '. The reason ' +
'given was: "' + reason + '."');
}
event.reply('Thank you, ' + nick + ' has been reported the channel administrators.');
} else {
event.reply('Nick is not in channel.');
event.reply('User is not in that channel.');
}
} else {
event.reply('Channel does not exist.');
event.reply('I am not in that channel.');
}
}

View File

@ -2,7 +2,7 @@ var spelling = function(dbot) {
var last = {};
var correct = function (event, correction, candidate, output_callback) {
var rawCandidates = last[event.channel][candidate].split(' ').allGroupings();
var rawCandidates = last[event.channel.name][candidate].split(' ').allGroupings();
var candidates = [];
for(var i=0;i<rawCandidates.length;i++) {
candidates.push(rawCandidates[i].join(' '));
@ -20,11 +20,11 @@ var spelling = function(dbot) {
if(winnerDistance < Math.ceil(winner.length * 1.33)) {
if(winner !== correction) {
var fix = last[event.channel][candidate].replace(winner, correction);
var fix = last[event.channel.name][candidate].replace(winner, correction);
if (/^.ACTION/.test(fix)) {
fix = fix.replace(/^.ACTION/, '/me');
}
last[event.channel][candidate] = fix;
last[event.channel.name][candidate] = fix;
var output = {
'fix': fix,
'correcter': event.user,
@ -51,11 +51,11 @@ var spelling = function(dbot) {
event.reply(dbot.t('spelling_other', e));
});
} else {
if(last.hasOwnProperty(event.channel)) {
last[event.channel][event.user] = event.message;
if(last.hasOwnProperty(event.channel.name)) {
last[event.channel.name][event.user] = event.message;
} else {
last[event.channel] = { };
last[event.channel][event.user] = event.message;
last[event.channel.name] = { };
last[event.channel.name][event.user] = event.message;
}
}
},

View File

@ -32,8 +32,9 @@ var webInterface = function(dbot) {
var channel = '#' + req.params.channel;
var connections = dbot.instance.connections;
if(connections.hasOwnProperty(connection) && connections[connection].channels.hasOwnProperty(channel)) {
var nicks = connections[connection].channels[channel].nicks;
if(connections.hasOwnProperty(connection) &&
connections[connection].channels.hasOwnProperty(channel)) {
var nicks = Object.keys(connections[connection].channels[channel].nicks);
res.render('users', { 'name': dbot.name, 'connection': connection,
'channel': channel, 'nicks': nicks });
} else {

View File

@ -164,6 +164,10 @@ Object.prototype.isArray = function(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
};
Object.prototype.isString = function(obj) {
return Object.prototype.toString.call(obj) === '[object String]';
};
Object.prototype.withAll = function(fun) {
for(key in this) {
if(this.hasOwnProperty(key)){