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
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
level logged will be to IRC. See supybot.log.level for possible
values. DEBUG is disabled due to the large quantity of output."""))
conf.registerGlobalValue(conf.supybot.plugins.LogToIrc, 'targets',
values. DEBUG is disabled due to the large quantity of output."""),
opSettable=False)
conf.registerNetworkValue(conf.supybot.plugins.LogToIrc, 'targets',
Targets([], """Determines which channels/nicks the bot should
log to. If no channels/nicks are set, this plugin will effectively be
turned off."""))
@ -67,7 +68,7 @@ conf.registerGlobalValue(conf.supybot.plugins.LogToIrc, 'networks',
registry.SpaceSeparatedSetOfStrings([], """Determines what networks the
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)."""))
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
required to have for the bot to log to the channel. If this string is
empty, no modes will be checked."""))
@ -75,10 +76,10 @@ conf.registerGlobalValue(conf.supybot.plugins.LogToIrc,
'userCapabilityRequired', registry.String('owner', """Determines what
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."""))
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
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
sent via NOTICE instead of PRIVMSG. Channels will always be PRIVMSGed,
regardless of this variable; NOTICEs will only be used if this variable is

View File

@ -52,14 +52,16 @@ class IrcHandler(logging.Handler):
except:
self.handleError(record)
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:
if irc.driver is None:
continue
for irc in world.ircs:
network = irc.network
if irc.driver is None:
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:
if not irc.driver.connected:
continue
@ -73,11 +75,13 @@ class IrcHandler(logging.Handler):
msgOk = True
if target in irc.state.channels:
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:
msgOk = False
else:
capability = config.userCapabilityRequired()
capability = config.userCapabilityRequired.getSpecific()
if capability:
try:
hostmask = irc.state.nicksToHostmasks[target]