Added noticeNonPrivmsgs configuration variable.

This commit is contained in:
Jeremy Fincher 2004-12-19 01:21:32 +00:00
parent 1a7333aef0
commit df03340113

View File

@ -40,6 +40,7 @@ import supybot.plugins as plugins
import re import re
import sys import sys
import sets
import time import time
from itertools import imap, ifilter from itertools import imap, ifilter
@ -97,6 +98,10 @@ conf.registerChannelValue(conf.supybot.plugins.Relay.channels,
'joinOnAllNetworks', registry.Boolean(True, """Determines whether the bot 'joinOnAllNetworks', registry.Boolean(True, """Determines whether the bot
will always join the channel(s) it relays for on all networks the bot is will always join the channel(s) it relays for on all networks the bot is
connected to.""")) connected to."""))
conf.registerChannelValue(conf.supybot.plugins.Relay, 'noticeNonPrivmsgs',
registry.Boolean(False, """Determines whether the bot will used NOTICEs
rather than PRIVMSGs for non-PRIVMSG relay messages (i.e., joins, parts,
nicks, quits, modes, etc.)"""))
class Relay(callbacks.Privmsg): class Relay(callbacks.Privmsg):
noIgnore = True noIgnore = True
@ -357,7 +362,7 @@ class Relay(callbacks.Privmsg):
return s return s
def _sendToOthers(self, irc, msg): def _sendToOthers(self, irc, msg):
assert msg.command == 'PRIVMSG' or msg.command == 'TOPIC' assert msg.command in ('PRIVMSG', 'NOTICE', 'TOPIC')
for otherIrc in world.ircs: for otherIrc in world.ircs:
if otherIrc != irc and not otherIrc.zombie: if otherIrc != irc and not otherIrc.zombie:
if msg.args[0] in otherIrc.state.channels: if msg.args[0] in otherIrc.state.channels:
@ -420,6 +425,25 @@ class Relay(callbacks.Privmsg):
m = ircmsgs.privmsg(channel, s) m = ircmsgs.privmsg(channel, s)
self._sendToOthers(irc, m) self._sendToOthers(irc, m)
_noticeCommands = sets.Set([
'JOIN',
'PART',
'QUIT',
'NICK',
'MODE',
'KICK',
'TOPIC',
'ERROR',
])
def _msgmaker(self, target, s):
msg = dynamic.msg
channel = dynamic.channel
if self.registryValue('noticeNonPrivmsgs', dynamic.channel) and \
msg.command in self._noticeCommands:
return ircmsgs.notice(target, s)
else:
return ircmsgs.privmsg(target, s)
def doJoin(self, irc, msg): def doJoin(self, irc, msg):
irc = self._getRealIrc(irc) irc = self._getRealIrc(irc)
channel = msg.args[0] channel = msg.args[0]
@ -431,7 +455,7 @@ class Relay(callbacks.Privmsg):
else: else:
hostmask = '' hostmask = ''
s = '%s%s has joined on %s' % (msg.nick, hostmask, network) s = '%s%s has joined on %s' % (msg.nick, hostmask, network)
m = ircmsgs.privmsg(channel, s) m = self._msgmaker(channel, s)
self._sendToOthers(irc, m) self._sendToOthers(irc, m)
def doPart(self, irc, msg): def doPart(self, irc, msg):
@ -445,7 +469,7 @@ class Relay(callbacks.Privmsg):
else: else:
hostmask = '' hostmask = ''
s = '%s%s has left on %s' % (msg.nick, hostmask, network) s = '%s%s has left on %s' % (msg.nick, hostmask, network)
m = ircmsgs.privmsg(channel, s) m = self._msgmaker(channel, s)
self._sendToOthers(irc, m) self._sendToOthers(irc, m)
def doMode(self, irc, msg): def doMode(self, irc, msg):
@ -456,7 +480,7 @@ class Relay(callbacks.Privmsg):
network = self._getIrcName(irc) network = self._getIrcName(irc)
s = 'mode change by %s on %s: %s' % \ s = 'mode change by %s on %s: %s' % \
(msg.nick, network, ' '.join(msg.args[1:])) (msg.nick, network, ' '.join(msg.args[1:]))
m = ircmsgs.privmsg(channel, s) m = self._msgmaker(channel, s)
self._sendToOthers(irc, m) self._sendToOthers(irc, m)
def doKick(self, irc, msg): def doKick(self, irc, msg):
@ -471,7 +495,7 @@ class Relay(callbacks.Privmsg):
else: else:
s = '%s was kicked by %s on %s' % \ s = '%s was kicked by %s on %s' % \
(msg.args[1], msg.nick, network) (msg.args[1], msg.nick, network)
m = ircmsgs.privmsg(channel, s) m = self._msgmaker(channel, s)
self._sendToOthers(irc, m) self._sendToOthers(irc, m)
def doNick(self, irc, msg): def doNick(self, irc, msg):
@ -482,7 +506,7 @@ class Relay(callbacks.Privmsg):
for channel in self.registryValue('channels'): for channel in self.registryValue('channels'):
if channel in irc.state.channels: if channel in irc.state.channels:
if newNick in irc.state.channels[channel].users: if newNick in irc.state.channels[channel].users:
m = ircmsgs.privmsg(channel, s) m = self._msgmaker(channel, s)
self._sendToOthers(irc, m) self._sendToOthers(irc, m)
def doTopic(self, irc, msg): def doTopic(self, irc, msg):
@ -509,7 +533,7 @@ class Relay(callbacks.Privmsg):
channel, otherIrc.network) channel, otherIrc.network)
else: else:
s = 'topic change by %s on %s: %s' % (msg.nick, network, newTopic) s = 'topic change by %s on %s: %s' % (msg.nick, network, newTopic)
m = ircmsgs.privmsg(channel, s) m = self._msgmaker(channel, s)
self._sendToOthers(irc, m) self._sendToOthers(irc, m)
def doQuit(self, irc, msg): def doQuit(self, irc, msg):
@ -522,7 +546,7 @@ class Relay(callbacks.Privmsg):
for channel in self.registryValue('channels'): for channel in self.registryValue('channels'):
if channel in self.ircstates[irc].channels: if channel in self.ircstates[irc].channels:
if msg.nick in self.ircstates[irc].channels[channel].users: if msg.nick in self.ircstates[irc].channels[channel].users:
m = ircmsgs.privmsg(channel, s) m = self._msgmaker(channel, s)
self._sendToOthers(irc, m) self._sendToOthers(irc, m)
def doError(self, irc, msg): def doError(self, irc, msg):
@ -530,7 +554,7 @@ class Relay(callbacks.Privmsg):
network = self._getIrcName(irc) network = self._getIrcName(irc)
s = 'disconnected from %s: %s' % (network, msg.args[0]) s = 'disconnected from %s: %s' % (network, msg.args[0])
for channel in self.registryValue('channels'): for channel in self.registryValue('channels'):
m = ircmsgs.privmsg(channel, s) m = self._msgmaker(channel, s)
self._sendToOthers(irc, m) self._sendToOthers(irc, m)
def outFilter(self, irc, msg): def outFilter(self, irc, msg):