LogToIrc: Make variables channel- and network-specific when relevant

This commit is contained in:
Valentin Lorentz 2021-03-11 20:20:53 +01:00
parent 7359ddce90
commit 54342765cd
2 changed files with 21 additions and 16 deletions

View File

@ -55,11 +55,12 @@ class Targets(registry.SpaceSeparatedListOfStrings):
Value = ValidChannelOrNick Value = ValidChannelOrNick
conf.registerPlugin('LogToIrc') conf.registerPlugin('LogToIrc')
conf.registerGlobalValue(conf.supybot.plugins.LogToIrc, 'level', conf.registerChannelValue(conf.supybot.plugins.LogToIrc, 'level',
IrcLogLevel(logging.WARNING, """Determines what the minimum priority IrcLogLevel(logging.WARNING, """Determines what the minimum priority
level logged will be to IRC. See supybot.log.level for possible level logged will be to IRC. See supybot.log.level for possible
values. DEBUG is disabled due to the large quantity of output.""")) values. DEBUG is disabled due to the large quantity of output."""),
conf.registerGlobalValue(conf.supybot.plugins.LogToIrc, 'targets', opSettable=False)
conf.registerNetworkValue(conf.supybot.plugins.LogToIrc, 'targets',
Targets([], """Determines which channels/nicks the bot should Targets([], """Determines which channels/nicks the bot should
log to. If no channels/nicks are set, this plugin will effectively be log to. If no channels/nicks are set, this plugin will effectively be
turned off.""")) turned off."""))
@ -67,7 +68,7 @@ conf.registerGlobalValue(conf.supybot.plugins.LogToIrc, 'networks',
registry.SpaceSeparatedSetOfStrings([], """Determines what networks the registry.SpaceSeparatedSetOfStrings([], """Determines what networks the
bot should log to. If no networks are set, the bot will log on one network bot should log to. If no networks are set, the bot will log on one network
(whichever happens to be around at the time it feels like logging).""")) (whichever happens to be around at the time it feels like logging)."""))
conf.registerGlobalValue(conf.supybot.plugins.LogToIrc, 'channelModesRequired', conf.registerNetworkValue(conf.supybot.plugins.LogToIrc, 'channelModesRequired',
registry.String('s', """Determines what channel modes a channel will be registry.String('s', """Determines what channel modes a channel will be
required to have for the bot to log to the channel. If this string is required to have for the bot to log to the channel. If this string is
empty, no modes will be checked.""")) empty, no modes will be checked."""))
@ -75,10 +76,10 @@ conf.registerGlobalValue(conf.supybot.plugins.LogToIrc,
'userCapabilityRequired', registry.String('owner', """Determines what 'userCapabilityRequired', registry.String('owner', """Determines what
capability is required for the bot to log to in private messages to the capability is required for the bot to log to in private messages to the
user. If this is empty, there will be no capability that's checked.""")) user. If this is empty, there will be no capability that's checked."""))
conf.registerGlobalValue(conf.supybot.plugins.LogToIrc, 'color', conf.registerChannelValue(conf.supybot.plugins.LogToIrc, 'color',
registry.Boolean(False, """Determines whether the bot's logs to IRC will be registry.Boolean(False, """Determines whether the bot's logs to IRC will be
colorized with mIRC colors.""")) colorized with mIRC colors."""))
conf.registerGlobalValue(conf.supybot.plugins.LogToIrc, 'notice', conf.registerChannelValue(conf.supybot.plugins.LogToIrc, 'notice',
registry.Boolean(False, """Determines whether the bot's logs to IRC will be registry.Boolean(False, """Determines whether the bot's logs to IRC will be
sent via NOTICE instead of PRIVMSG. Channels will always be PRIVMSGed, sent via NOTICE instead of PRIVMSG. Channels will always be PRIVMSGed,
regardless of this variable; NOTICEs will only be used if this variable is regardless of this variable; NOTICEs will only be used if this variable is

View File

@ -52,14 +52,16 @@ class IrcHandler(logging.Handler):
except: except:
self.handleError(record) self.handleError(record)
return return
for target in config.targets():
msgmaker = ircmsgs.privmsg
if config.notice() and not ircutils.isChannel(target):
msgmaker = ircmsgs.notice
msg = msgmaker(target, s)
for irc in world.ircs: for irc in world.ircs:
network = irc.network
if irc.driver is None: if irc.driver is None:
continue continue
for target in config.targets.getSpecific(network=irc.network)():
msgmaker = ircmsgs.privmsg
if config.notice.getSpecific(target, network)() \
and not irc.isChannel(target):
msgmaker = ircmsgs.notice
msg = msgmaker(target, s)
try: try:
if not irc.driver.connected: if not irc.driver.connected:
continue continue
@ -73,11 +75,13 @@ class IrcHandler(logging.Handler):
msgOk = True msgOk = True
if target in irc.state.channels: if target in irc.state.channels:
channel = irc.state.channels[target] channel = irc.state.channels[target]
for modeChar in config.channelModesRequired(): modes = config.channelModesRequired.getSpecific(
network=network)()
for modeChar in modes:
if modeChar not in channel.modes: if modeChar not in channel.modes:
msgOk = False msgOk = False
else: else:
capability = config.userCapabilityRequired() capability = config.userCapabilityRequired.getSpecific()
if capability: if capability:
try: try:
hostmask = irc.state.nicksToHostmasks[target] hostmask = irc.state.nicksToHostmasks[target]