-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add options to nickserv plugin; don't broadcast to unjoined channels
- Loading branch information
Showing
4 changed files
with
46 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,40 @@ | ||
module.exports = function (bot) { | ||
module.exports = function () { | ||
function broadcastToTargets(msg, targets) { | ||
targets.forEach(function (target) { | ||
// Don't send to the same target the message came from. | ||
if (target.network == msg.network && target.channel == msg.replyto) return; | ||
// Don't send to channels we aren't currently in. | ||
if (!(target.channel in this.networks[target.network].channels)) return; | ||
|
||
var identifier = (network != msg.network ? (msg.network + ':') : '') + msg.replyto; | ||
bot.say(target.network, target.channel, '<%s> [%s]', identifier, msg.nick, msg.text); | ||
}); | ||
var identifier = (target.network != msg.network ? (msg.network + ':') : '') + msg.replyto; | ||
this.say(target.network, target.channel, '<%s> [%s]', identifier, msg.nick, msg.text); | ||
}, this); | ||
} | ||
|
||
bot.listen('.*', function (msg) { | ||
if (bot.config.get('plugins.broadcast.broadcast_all')) { | ||
// build a set of targets from all joined channels in all connected networks | ||
this.listen('.*', function (msg) { | ||
if (this.config.get('plugins.broadcast.broadcast_all')) { | ||
// Build a set of targets from all joined channels in all connected networks. | ||
var targets = []; | ||
for (network in bot.networks) { | ||
for (channel in bot.networks[network].channels) { | ||
for (var network in this.networks) { | ||
for (var channel in this.networks[network].channels) { | ||
targets.push({ | ||
network: network, | ||
channel: channel, | ||
}); | ||
} | ||
} | ||
broadcastToTargets(msg, targets); | ||
broadcastToTargets.call(this, msg, targets); | ||
} | ||
else { | ||
// iterate through the configured sets of targets that will be broadcast to each other | ||
bot.config.get('plugins.broadcast.target_sets', []).forEach(function (targets) { | ||
// check that the received message's target is in this set | ||
// Iterate through the configured sets of targets that will be broadcast to each other. | ||
this.config.get('plugins.broadcast.target_sets', []).forEach(function (targets) { | ||
// Check that the received message's target is in this set. | ||
if (targets.some(function (target) { | ||
return target.network == msg.network && target.channel == msg.replyto; | ||
})) { | ||
broadcastToTargets(msg, targets); | ||
broadcastToTargets.call(this, msg, targets); | ||
} | ||
}); | ||
}, this); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters