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

@ -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)