forked from GitHub/dbot
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:
parent
09947921d1
commit
c690611cdc
2
jsbot
2
jsbot
@ -1 +1 @@
|
|||||||
Subproject commit 6723ded150692bd157b43ac287a3913abd1d7a99
|
Subproject commit 87ede262d4d384878941eb17095e4dc0e1b57962
|
@ -12,21 +12,34 @@ var admin = function(dbot) {
|
|||||||
// Join a channel
|
// Join a channel
|
||||||
'join': function(event) {
|
'join': function(event) {
|
||||||
var channel = event.params[1];
|
var channel = event.params[1];
|
||||||
|
if(event.allChannels.hasOwnProperty(channel)) {
|
||||||
|
event.reply("I'm already in that channel.");
|
||||||
|
} else {
|
||||||
dbot.instance.join(event, channel);
|
dbot.instance.join(event, channel);
|
||||||
event.reply(dbot.t('join', {'channel': channel}));
|
event.reply(dbot.t('join', {'channel': channel}));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Leave a channel
|
// Leave a channel
|
||||||
'part': function(event) {
|
'part': function(event) {
|
||||||
var channel = event.params[1];
|
var channel = event.params[1];
|
||||||
|
if(!event.allChannels.hasOwnProperty(channel)) {
|
||||||
|
event.reply("I'm not in that channel.");
|
||||||
|
} else {
|
||||||
event.instance.part(event, channel);
|
event.instance.part(event, channel);
|
||||||
event.reply(dbot.t('part', {'channel': channel}));
|
event.reply(dbot.t('part', {'channel': channel}));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Op admin caller in given channel
|
// Op admin caller in given channel
|
||||||
'opme': function(event) {
|
'opme': function(event) {
|
||||||
event.channel = event.params[1];
|
var channel = event.params[1];
|
||||||
dbot.instance.mode(event, '+o ' + event.user);
|
|
||||||
|
// 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
|
// Do a git pull and reload
|
||||||
@ -49,7 +62,7 @@ var admin = function(dbot) {
|
|||||||
'say': function(event) {
|
'say': function(event) {
|
||||||
var channel = event.params[1];
|
var channel = event.params[1];
|
||||||
if(event.params[1] === "@") {
|
if(event.params[1] === "@") {
|
||||||
var channel = event.channel;
|
var channel = event.channel.name;
|
||||||
}
|
}
|
||||||
var message = event.params.slice(2).join(' ');
|
var message = event.params.slice(2).join(' ');
|
||||||
dbot.say(event.server, channel, message);
|
dbot.say(event.server, channel, message);
|
||||||
|
@ -10,7 +10,7 @@ var link = function(dbot) {
|
|||||||
|
|
||||||
var commands = {
|
var commands = {
|
||||||
'~title': function(event) {
|
'~title': function(event) {
|
||||||
var link = links[event.channel];
|
var link = links[event.channel.name];
|
||||||
if(event.params[1] !== undefined) {
|
if(event.params[1] !== undefined) {
|
||||||
var urlMatches = event.params[1].match(urlRegex);
|
var urlMatches = event.params[1].match(urlRegex);
|
||||||
if(urlMatches !== null) {
|
if(urlMatches !== null) {
|
||||||
@ -40,7 +40,7 @@ var link = function(dbot) {
|
|||||||
'listener': function(event) {
|
'listener': function(event) {
|
||||||
var urlMatches = event.message.match(urlRegex);
|
var urlMatches = event.message.match(urlRegex);
|
||||||
if(urlMatches !== null) {
|
if(urlMatches !== null) {
|
||||||
links[event.channel] = urlMatches[0];
|
links[event.channel.name] = urlMatches[0];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'on': 'PRIVMSG'
|
'on': 'PRIVMSG'
|
||||||
|
@ -5,8 +5,8 @@ var report = function(dbot) {
|
|||||||
var nick = event.input[2];
|
var nick = event.input[2];
|
||||||
var reason = event.input[3];
|
var reason = event.input[3];
|
||||||
|
|
||||||
if(dbot.instance.connections[event.server].channels.hasOwnProperty(channelName)) {
|
if(event.allChannels.hasOwnProperty(channelName)) {
|
||||||
var channel = dbot.instance.connections[event.server].channels[channelName];
|
var channel = event.allChannels[channelName];
|
||||||
if(channel.nicks.hasOwnProperty(nick)) {
|
if(channel.nicks.hasOwnProperty(nick)) {
|
||||||
var ops = [];
|
var ops = [];
|
||||||
for(var possibOps in channel.nicks) {
|
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++) {
|
for(var i=0;i<ops.length;i++) {
|
||||||
dbot.say(event.server, ops[i],
|
dbot.say(event.server, ops[i],
|
||||||
'Attention: ' + event.user + ' has reported ' +
|
'Attention: ' + event.user + ' has reported ' +
|
||||||
@ -22,21 +27,12 @@ var report = function(dbot) {
|
|||||||
'given was: "' + reason + '."');
|
'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.');
|
event.reply('Thank you, ' + nick + ' has been reported the channel administrators.');
|
||||||
} else {
|
} else {
|
||||||
event.reply('Nick is not in channel.');
|
event.reply('User is not in that channel.');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
event.reply('Channel does not exist.');
|
event.reply('I am not in that channel.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ var spelling = function(dbot) {
|
|||||||
var last = {};
|
var last = {};
|
||||||
|
|
||||||
var correct = function (event, correction, candidate, output_callback) {
|
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 = [];
|
var candidates = [];
|
||||||
for(var i=0;i<rawCandidates.length;i++) {
|
for(var i=0;i<rawCandidates.length;i++) {
|
||||||
candidates.push(rawCandidates[i].join(' '));
|
candidates.push(rawCandidates[i].join(' '));
|
||||||
@ -20,11 +20,11 @@ var spelling = function(dbot) {
|
|||||||
|
|
||||||
if(winnerDistance < Math.ceil(winner.length * 1.33)) {
|
if(winnerDistance < Math.ceil(winner.length * 1.33)) {
|
||||||
if(winner !== correction) {
|
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)) {
|
if (/^.ACTION/.test(fix)) {
|
||||||
fix = fix.replace(/^.ACTION/, '/me');
|
fix = fix.replace(/^.ACTION/, '/me');
|
||||||
}
|
}
|
||||||
last[event.channel][candidate] = fix;
|
last[event.channel.name][candidate] = fix;
|
||||||
var output = {
|
var output = {
|
||||||
'fix': fix,
|
'fix': fix,
|
||||||
'correcter': event.user,
|
'correcter': event.user,
|
||||||
@ -51,11 +51,11 @@ var spelling = function(dbot) {
|
|||||||
event.reply(dbot.t('spelling_other', e));
|
event.reply(dbot.t('spelling_other', e));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if(last.hasOwnProperty(event.channel)) {
|
if(last.hasOwnProperty(event.channel.name)) {
|
||||||
last[event.channel][event.user] = event.message;
|
last[event.channel.name][event.user] = event.message;
|
||||||
} else {
|
} else {
|
||||||
last[event.channel] = { };
|
last[event.channel.name] = { };
|
||||||
last[event.channel][event.user] = event.message;
|
last[event.channel.name][event.user] = event.message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -32,8 +32,9 @@ var webInterface = function(dbot) {
|
|||||||
var channel = '#' + req.params.channel;
|
var channel = '#' + req.params.channel;
|
||||||
var connections = dbot.instance.connections;
|
var connections = dbot.instance.connections;
|
||||||
|
|
||||||
if(connections.hasOwnProperty(connection) && connections[connection].channels.hasOwnProperty(channel)) {
|
if(connections.hasOwnProperty(connection) &&
|
||||||
var nicks = connections[connection].channels[channel].nicks;
|
connections[connection].channels.hasOwnProperty(channel)) {
|
||||||
|
var nicks = Object.keys(connections[connection].channels[channel].nicks);
|
||||||
res.render('users', { 'name': dbot.name, 'connection': connection,
|
res.render('users', { 'name': dbot.name, 'connection': connection,
|
||||||
'channel': channel, 'nicks': nicks });
|
'channel': channel, 'nicks': nicks });
|
||||||
} else {
|
} else {
|
||||||
|
@ -164,6 +164,10 @@ Object.prototype.isArray = function(obj) {
|
|||||||
return Object.prototype.toString.call(obj) === '[object Array]';
|
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) {
|
Object.prototype.withAll = function(fun) {
|
||||||
for(key in this) {
|
for(key in this) {
|
||||||
if(this.hasOwnProperty(key)){
|
if(this.hasOwnProperty(key)){
|
||||||
|
Loading…
Reference in New Issue
Block a user