Various: Follow upstream bot development.

Specifically, use msg.channel and make network-aware where easily possible.

* Bugtracker
* Encyclopedia
* PackageInfo
This commit is contained in:
Krytarik Raido 2020-10-23 06:23:04 +02:00
parent fdbaa3fc36
commit 32f2c9ac3f
6 changed files with 71 additions and 74 deletions

View File

@ -24,7 +24,7 @@ import supybot.world as world
from imp import reload
__version__ = "4.4.0"
__version__ = "4.5.0"
__author__ = supybot.Author("Krytarik Raido", "krytarik", "krytarik@tuxgarage.com")
__contributors__ = {
supybot.Author("Dennis Kaarsemaker", "Seveas", "dennis@kaarsemaker.net"): ['Original Author'],

View File

@ -30,19 +30,16 @@ from .config import registerBugtracker, default_bugtrackers
from .trackers import defined_bugtrackers
from . import trackers
def defaultIgnored(hostmask, recipient):
def defaultIgnored(hostmask):
if not conf.supybot.defaultIgnore():
return False
if conf.version <= '0.83.4.1' \
and ircutils.isChannel(recipient):
return False
try:
user = ircdb.users.getUser(hostmask)
except KeyError:
return True
return False
def checkIgnored(hostmask, recipient):
def checkIgnored(hostmask, channel):
try:
user = ircdb.users.getUser(hostmask)
if user._checkCapability('owner'):
@ -53,8 +50,8 @@ def checkIgnored(hostmask, recipient):
pass
if ircdb.ignores.checkIgnored(hostmask):
return True
if ircutils.isChannel(recipient):
c = ircdb.channels.getChannel(recipient)
if channel:
c = ircdb.channels.getChannel(channel)
if c.checkIgnored(hostmask):
return True
return False
@ -97,11 +94,11 @@ class Bugtracker(callbacks.PluginRegexp):
supylog.warning("Bugtracker: Unknown trackertype '%s' (%s)" % (trackers[name].trackertype(), name))
self.shorthand = utils.abbrev(list(self.db.keys()))
def is_ok(self, channel, tracker, bugid):
def is_ok(self, channel, network, tracker, bugid):
"""Flood/repeat protection"""
now = time.time()
for k in list(self.shown.keys()):
if self.shown[k] < now - self.registryValue('repeatdelay', channel):
if self.shown[k] < now - self.registryValue('repeatdelay', channel, network):
self.shown.pop(k)
if (channel, tracker, bugid) not in self.shown:
self.shown[(channel, tracker, bugid)] = now
@ -152,7 +149,7 @@ class Bugtracker(callbacks.PluginRegexp):
self.shorthand = utils.abbrev(list(self.db.keys()))
irc.replySuccess()
except KeyError:
s = self.registryValue('replyNoBugtracker', msg.args[0] if ircutils.isChannel(msg.args[0]) else None)
s = self.registryValue('replyNoBugtracker', msg.channel, irc.network)
irc.error(s % name)
remove = wrap(remove, [('checkCapability', 'admin'), 'text'])
@ -181,7 +178,7 @@ class Bugtracker(callbacks.PluginRegexp):
self.aliases[a] = newname
irc.replySuccess()
except KeyError:
s = self.registryValue('replyNoBugtracker', msg.args[0] if ircutils.isChannel(msg.args[0]) else None)
s = self.registryValue('replyNoBugtracker', msg.channel, irc.network)
irc.error(s % oldname)
rename = wrap(rename, [('checkCapability', 'admin'), 'something', 'something', additional('text')])
@ -207,7 +204,7 @@ class Bugtracker(callbacks.PluginRegexp):
self.aliases[alias] = name
irc.replySuccess()
except KeyError:
s = self.registryValue('replyNoBugtracker', msg.args[0] if ircutils.isChannel(msg.args[0]) else None)
s = self.registryValue('replyNoBugtracker', msg.channel, irc.network)
irc.error(s % name)
alias = wrap(alias, [('checkCapability', 'admin'), 'something', additional('text')])
@ -230,7 +227,7 @@ class Bugtracker(callbacks.PluginRegexp):
irc.error("Bugtracker '%s' has no alias '%s' set" % (name, alias))
return
except KeyError:
s = self.registryValue('replyNoBugtracker', msg.args[0] if ircutils.isChannel(msg.args[0]) else None)
s = self.registryValue('replyNoBugtracker', msg.channel, irc.network)
irc.error(s % name)
unalias = wrap(unalias, [('checkCapability', 'admin'), 'something', 'something'])
@ -247,7 +244,7 @@ class Bugtracker(callbacks.PluginRegexp):
irc.reply('%s%s: %s, %s [%s]' % (name, ' (%s)' % ', '.join(sorted(tracker.aliases)) if tracker.aliases else '',
tracker.description, tracker.url, tracker.__class__.__name__))
except KeyError:
s = self.registryValue('replyNoBugtracker', msg.args[0] if ircutils.isChannel(msg.args[0]) else None)
s = self.registryValue('replyNoBugtracker', msg.channel, irc.network)
irc.error(s % name)
else:
if self.db:
@ -283,7 +280,7 @@ class Bugtracker(callbacks.PluginRegexp):
supylog.warning("Bugtracker: Unknown trackertype '%s' (%s)" % (trackers[name].trackertype(), name))
self.shorthand = utils.abbrev(list(self.db.keys()))
except KeyError:
s = self.registryValue('replyNoBugtracker', msg.args[0] if ircutils.isChannel(msg.args[0]) else None)
s = self.registryValue('replyNoBugtracker', msg.channel, irc.network)
irc.error(s % name)
return
else:
@ -300,9 +297,9 @@ class Bugtracker(callbacks.PluginRegexp):
return msg
if not ircutils.isUserHostmask(msg.prefix):
return msg
if not defaultIgnored(msg.prefix, msg.args[0]):
if not defaultIgnored(msg.prefix):
return msg
if checkIgnored(msg.prefix, msg.args[0]):
if checkIgnored(msg.prefix, msg.channel):
return msg
if msg.command == 'PRIVMSG':
self.doPrivmsg(irc, msg)
@ -317,7 +314,7 @@ class Bugtracker(callbacks.PluginRegexp):
self.termSnarfer(irc, msg, match, 'commit')
def termSnarfer(self, irc, msg, match, termtype):
channel = msg.args[0] if ircutils.isChannel(msg.args[0]) else None
channel = msg.channel
if checkAddressed(msg.args[1].strip(), channel):
return
if not self.registryValue('{}Snarfer'.format(termtype), channel):
@ -378,7 +375,7 @@ class Bugtracker(callbacks.PluginRegexp):
if not name:
showTracker = False
snarfTarget = self.registryValue('snarfTarget', channel)
snarfTarget = self.registryValue('snarfTarget', channel, irc.network)
if not snarfTarget:
supylog.warning("Bugtracker: No snarfTarget set")
return
@ -386,14 +383,16 @@ class Bugtracker(callbacks.PluginRegexp):
name = self.shorthand[snarfTarget.lower()]
tracker = self.db[name]
except:
s = self.registryValue('replyNoBugtracker', channel)
s = self.registryValue('replyNoBugtracker', channel, irc.network)
irc.error(s % (name or snarfTarget))
return
for bugid in bugids:
try:
report = self.get_bug(channel or msg.nick, tracker, bugtype, bugid, self.registryValue('showassignee', channel),
self.registryValue('extended', channel), do_tracker=showTracker)
report = self.get_bug(channel or msg.nick, irc.network, tracker, bugtype, bugid,
self.registryValue('showassignee', channel, irc.network),
self.registryValue('extended', channel, irc.network),
do_tracker=showTracker)
except trackers.BugNotFoundError:
if self.registryValue('replyWhenNotFound'):
irc.error("Could not find %s %s %s" % (tracker.description, termtype, bugid))
@ -413,7 +412,7 @@ class Bugtracker(callbacks.PluginRegexp):
self.urlSnarfer(irc, msg, match, 'commit')
def urlSnarfer(self, irc, msg, match, urltype):
channel = msg.args[0] if ircutils.isChannel(msg.args[0]) else None
channel = msg.channel
if checkAddressed(msg.args[1].strip(), channel):
return
if not self.registryValue('{}Snarfer'.format(urltype), channel):
@ -430,8 +429,10 @@ class Bugtracker(callbacks.PluginRegexp):
tracker = self.get_tracker(url, bugid)
if not tracker:
return
report = self.get_bug(channel or msg.nick, tracker, 'url', bugid, self.registryValue('showassignee', channel),
self.registryValue('extended', channel), do_url=False)
report = self.get_bug(channel or msg.nick, irc.network, tracker, 'url', bugid,
self.registryValue('showassignee', channel, irc.network),
self.registryValue('extended', channel, irc.network),
do_url=False)
except trackers.BugNotFoundError:
if self.registryValue('replyWhenNotFound'):
irc.error("Could not find %s %s %s" % (tracker.description, urltype, match.group('bug')))
@ -445,26 +446,28 @@ class Bugtracker(callbacks.PluginRegexp):
# Only useful to Launchpad developers
def oopsSnarfer(self, irc, msg, match):
r"(https?://\S+[=/])?OOPS-(?P<oopsid>[a-f0-9]{6,})"
channel = msg.args[0] if ircutils.isChannel(msg.args[0]) else None
channel = msg.channel
if checkAddressed(msg.args[1].strip(), channel):
return
if not (self.registryValue('bugSnarfer', channel) and self.registryValue('oopsSnarfer', channel)):
if not (self.registryValue('bugSnarfer', channel, irc.network) \
and self.registryValue('oopsSnarfer', channel, irc.network)):
return
oopsid = match.group('oopsid')
if not self.is_ok(channel or msg.nick, 'lpoops', oopsid):
if not self.is_ok(channel or msg.nick, irc.network, 'lpoops', oopsid):
return
if not match.group(1):
irc.reply('https://oops.canonical.com/?oopsid=OOPS-%s' % oopsid)
def cveSnarfer(self, irc, msg, match):
r"(https?://\S+=)?CVE[- ](?P<cveid>\d{4}[- ]\d{4,})"
channel = msg.args[0] if ircutils.isChannel(msg.args[0]) else None
channel = msg.channel
if checkAddressed(msg.args[1].strip(), channel):
return
if not (self.registryValue('bugSnarfer', channel) and self.registryValue('cveSnarfer', channel)):
if not (self.registryValue('bugSnarfer', channel, irc.network) \
and self.registryValue('cveSnarfer', channel, irc.network)):
return
cveid = match.group('cveid').replace(' ','-')
if not self.is_ok(channel or msg.nick, 'cve', cveid):
if not self.is_ok(channel or msg.nick, irc.network, 'cve', cveid):
return
if not match.group(1):
do_url = True
@ -530,8 +533,8 @@ class Bugtracker(callbacks.PluginRegexp):
self.shorthand = utils.abbrev(list(self.db.keys()))
return tracker
def get_bug(self, channel, tracker, bugtype, bugid, do_assignee, do_extinfo, do_url=True, do_tracker=True):
if not self.is_ok(channel, tracker, bugid):
def get_bug(self, channel, network, tracker, bugtype, bugid, do_assignee, do_extinfo, do_url=True, do_tracker=True):
if not self.is_ok(channel, network, tracker, bugid):
return
bugdata = tracker.get_bug(bugtype, bugid)
@ -540,7 +543,7 @@ class Bugtracker(callbacks.PluginRegexp):
(bugid, product, title, severity, status, assignee, url, extinfo, duplicate) = bugdata
if duplicate and not self.is_ok(channel, tracker, bugid):
if duplicate and not self.is_ok(channel, network, tracker, bugid):
return
bugtype = re.match(r'\S+/(feature-)?(?P<type>request|patch|todo|issue|pull|merge|ticket|commit)(_requests)?(e?s)?/([^\s?]*\?([^\s?&]+&)?id=)?[a-f0-9]+$', url)

View File

@ -24,7 +24,7 @@ import supybot
import supybot.world as world
from imp import reload
__version__ = "2.8"
__version__ = "2.9"
__author__ = supybot.Author("Krytarik Raido", "krytarik", "krytarik@tuxgarage.com")
__contributors__ = {
supybot.Author("Dennis Kaarsemaker", "Seveas", "dennis@kaarsemaker.net"): ['Original Author'],

View File

@ -33,19 +33,16 @@ def stripNick(nick):
nick = nick[:-1]
return nick
def defaultIgnored(hostmask, recipient):
def defaultIgnored(hostmask):
if not conf.supybot.defaultIgnore():
return False
if conf.version <= '0.83.4.1' \
and ircutils.isChannel(recipient):
return False
try:
user = ircdb.users.getUser(hostmask)
except KeyError:
return True
return False
def checkIgnored(hostmask, recipient):
def checkIgnored(hostmask, channel):
try:
user = ircdb.users.getUser(hostmask)
if user._checkCapability('owner'):
@ -56,8 +53,8 @@ def checkIgnored(hostmask, recipient):
pass
if ircdb.ignores.checkIgnored(hostmask):
return True
if ircutils.isChannel(recipient):
c = ircdb.channels.getChannel(recipient)
if channel:
c = ircdb.channels.getChannel(channel)
if c.checkIgnored(hostmask):
return True
return False
@ -219,7 +216,7 @@ class Encyclopedia(callbacks.Plugin):
irc.reply(', '.join([u.name for u in list(ircdb.users.users.values()) if capab(u.name, 'addeditors')]), private=True)
moderators = wrap(moderators)
def get_target(self, nick, text, target):
def get_target(self, irc, nick, text, target):
ret, retmsg = text, ''
orig_target = target
@ -254,7 +251,7 @@ class Encyclopedia(callbacks.Plugin):
target = nick
retmsg = "<%s> wants you to know: " % nick
if target.lower() != orig_target.lower() and ircutils.isChannel(target):
if target.lower() != orig_target.lower() and irc.isChannel(target):
target = orig_target
retmsg = "(Forwarding to channels is not permitted) "
elif nick.lower() in (target.lower(), retmsg[:-2].lower()) \
@ -388,9 +385,9 @@ class Encyclopedia(callbacks.Plugin):
return msg
if not ircutils.isUserHostmask(msg.prefix):
return msg
if not defaultIgnored(msg.prefix, msg.args[0]):
if not defaultIgnored(msg.prefix):
return msg
if checkIgnored(msg.prefix, msg.args[0]):
if checkIgnored(msg.prefix, msg.channel):
return msg
if msg.command == "PRIVMSG":
self.doPrivmsg(irc, msg)
@ -414,7 +411,7 @@ class Encyclopedia(callbacks.Plugin):
if not text:
return
target = msg.args[0]
channel = target if ircutils.isChannel(target) else None
channel = msg.channel
if checkAddressed(text, channel):
return
@ -457,7 +454,7 @@ class Encyclopedia(callbacks.Plugin):
# Now switch between actions
ret, retmsg = '', ''
term = self.get_target(msg.nick, text, target)
term = self.get_target(irc, msg.nick, text, target)
lower_term = term[0].lower()
if re.match(r"please\s+see\s+((%s|(the\s+)?bot)(\s*'?s)?\s+\S+|\S+.*\s+\S+\s+(%s|(the\s+)?bot)\b)" % (re.escape(irc.nick), re.escape(irc.nick)), text, re.I):
@ -546,7 +543,7 @@ class Encyclopedia(callbacks.Plugin):
if retmsg and checkUrl(retmsg):
# !ops factoid called with a URL, most likely spam
return
if doChanMsg and channel and not ircutils.isChannel(target) \
if doChanMsg and channel and not irc.isChannel(target) \
and target in irc.state.channels[channel].users:
myqueue(irc, channel, "%s: Please see my private message" % target)
myqueue(irc, target, retmsg + ret[0])

View File

@ -22,7 +22,7 @@ import supybot
import supybot.world as world
from imp import reload
__version__ = "1.6.0"
__version__ = "1.7.0"
__author__ = supybot.Author("Krytarik Raido", "krytarik", "krytarik@tuxgarage.com")
__contributors__ = {
supybot.Author("Dennis Kaarsemaker", "Seveas", "dennis@kaarsemaker.net"): ['Original Concept'],

View File

@ -30,19 +30,16 @@ def stripNick(nick):
nick = nick[:-1]
return nick
def defaultIgnored(hostmask, recipient):
def defaultIgnored(hostmask):
if not conf.supybot.defaultIgnore():
return False
if conf.version <= '0.83.4.1' \
and ircutils.isChannel(recipient):
return False
try:
user = ircdb.users.getUser(hostmask)
except KeyError:
return True
return False
def checkIgnored(hostmask, recipient):
def checkIgnored(hostmask, channel):
try:
user = ircdb.users.getUser(hostmask)
if user._checkCapability('owner'):
@ -53,8 +50,8 @@ def checkIgnored(hostmask, recipient):
pass
if ircdb.ignores.checkIgnored(hostmask):
return True
if ircutils.isChannel(recipient):
c = ircdb.channels.getChannel(recipient)
if channel:
c = ircdb.channels.getChannel(channel)
if c.checkIgnored(hostmask):
return True
return False
@ -90,7 +87,7 @@ class PackageInfo(callbacks.Plugin):
def __getRelease(self, irc, release, channel, doError=True):
if release:
release = release.strip()
defaultRelease = self.registryValue("defaultRelease", channel)
defaultRelease = self.registryValue("defaultRelease", channel, irc.network)
if not defaultRelease:
if doError:
irc.error("'supybot.plugins.PackageInfo.defaultRelease' is not set")
@ -108,7 +105,7 @@ class PackageInfo(callbacks.Plugin):
return (package, True)
return (package, False)
def __handleRest(self, msg, target, reply, rest):
def __handleRest(self, irc, msg, target, reply, rest):
targeto = target
prefix = ''
if rest[0] == '|':
@ -126,7 +123,7 @@ class PackageInfo(callbacks.Plugin):
target = msg.nick
prefix = "<%s> wants you to know: " % msg.nick
if target.lower() != targeto.lower() and ircutils.isChannel(target):
if target.lower() != targeto.lower() and irc.isChannel(target):
target = targeto
prefix = "(Forwarding to channels is not permitted) "
elif msg.nick.lower() in (target.lower(), prefix[:-2].lower()) \
@ -141,8 +138,8 @@ class PackageInfo(callbacks.Plugin):
Look up information for <package>, optionally in <release>
"""
channel = msg.args[0] if ircutils.isChannel(msg.args[0]) else None
if not self.registryValue("enabled", channel):
channel = msg.channel
if not self.registryValue("enabled", channel, irc.network):
return
(release, rest) = self.__getRelease(irc, release, channel)
if not release:
@ -151,7 +148,7 @@ class PackageInfo(callbacks.Plugin):
target = ircutils.replyTo(msg)
reply = self.Apt.info(package, release, isSource)
if rest:
(target, reply) = self.__handleRest(msg, target, reply, rest)
(target, reply) = self.__handleRest(irc, msg, target, reply, rest)
queue(irc, target, reply)
info = wrap(real_info, ['anything', optional('text')])
@ -160,8 +157,8 @@ class PackageInfo(callbacks.Plugin):
Look up dependencies for <package>, optionally in <release>
"""
channel = msg.args[0] if ircutils.isChannel(msg.args[0]) else None
if not self.registryValue("enabled", channel):
channel = msg.channel
if not self.registryValue("enabled", channel, irc.network):
return
(release, rest) = self.__getRelease(irc, release, channel)
if not release:
@ -170,7 +167,7 @@ class PackageInfo(callbacks.Plugin):
target = ircutils.replyTo(msg)
reply = self.Apt.depends(package, release, isSource)
if rest:
(target, reply) = self.__handleRest(msg, target, reply, rest)
(target, reply) = self.__handleRest(irc, msg, target, reply, rest)
queue(irc, target, reply)
depends = wrap(real_depends, ['anything', optional('text')])
@ -180,8 +177,8 @@ class PackageInfo(callbacks.Plugin):
Search for <package> or, if that fails, <filename> in packages,
optionally in <release>
"""
channel = msg.args[0] if ircutils.isChannel(msg.args[0]) else None
if not self.registryValue("enabled", channel):
channel = msg.channel
if not self.registryValue("enabled", channel, irc.network):
return
(release, rest) = self.__getRelease(irc, release, channel)
if not release:
@ -189,7 +186,7 @@ class PackageInfo(callbacks.Plugin):
target = ircutils.replyTo(msg)
reply = self.Apt.find(package, release)
if rest:
(target, reply) = self.__handleRest(msg, target, reply, rest)
(target, reply) = self.__handleRest(irc, msg, target, reply, rest)
queue(irc, target, reply)
find = wrap(real_find, ['anything', optional('text')])
@ -199,8 +196,8 @@ class PackageInfo(callbacks.Plugin):
text = msg.args[1].strip()
if not text:
return
channel = msg.args[0] if ircutils.isChannel(msg.args[0]) else None
if text[0] == self.registryValue("prefixchar", channel):
channel = msg.channel
if text[0] == self.registryValue("prefixchar", channel, irc.network):
text = text[1:].strip()
elif channel or text[0] in conf.supybot.reply.whenAddressedBy.chars():
return
@ -221,9 +218,9 @@ class PackageInfo(callbacks.Plugin):
return msg
if not ircutils.isUserHostmask(msg.prefix):
return msg
if not defaultIgnored(msg.prefix, msg.args[0]):
if not defaultIgnored(msg.prefix):
return msg
if checkIgnored(msg.prefix, msg.args[0]):
if checkIgnored(msg.prefix, msg.channel):
return msg
if msg.command == "PRIVMSG":
self.doPrivmsg(irc, msg)