Encyclopedia: Add 'review' command to list edit requests.

This commit is contained in:
Krytarik Raido 2021-07-24 20:34:04 +02:00
parent 2bd46f38ff
commit 148bf183e2
2 changed files with 44 additions and 14 deletions

View File

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

View File

@ -806,7 +806,7 @@ class Encyclopedia(callbacks.Plugin):
for r in res: for r in res:
ret.append(get_factoid_label(r[0], r[1])) ret.append(get_factoid_label(r[0], r[1]))
if not ret: if not ret:
return "None found" return "No matches found"
return 'Found: %s' % ', '.join(ret) return 'Found: %s' % ', '.join(ret)
def sync(self, irc, msg, args, channel): def sync(self, irc, msg, args, channel):
@ -887,10 +887,10 @@ class Encyclopedia(callbacks.Plugin):
return return
sync = wrap(sync, [optional("channel")]) sync = wrap(sync, [optional("channel")])
def lookup(self, irc, msg, args, author, channel): def lookup(self, irc, msg, args, channel, author):
"""[<author>] [<channel>] """[<channel>] [<author>]
Looks up factoids created or edited by <author>, Lists factoids created or edited by <author>,
<author> defaults to you. <author> defaults to you.
""" """
if not capab(msg.prefix, "editfactoids"): if not capab(msg.prefix, "editfactoids"):
@ -915,19 +915,49 @@ class Encyclopedia(callbacks.Plugin):
edit_ret.append(get_factoid_label(r[0], r[1])) edit_ret.append(get_factoid_label(r[0], r[1]))
if not auth_ret: if not auth_ret:
auth_rmsg = "Authored: None found" auth_rmsg = "Authored: (none)"
else: else:
auth_rmsg = 'Authored: %s' % ', '.join(auth_ret) auth_rmsg = 'Authored: %s' % ', '.join(auth_ret)
if not edit_ret: if not edit_ret:
edit_rmsg = "Edited: None found" edit_rmsg = "Edited: (none)"
else: else:
edit_rmsg = 'Edited: %s' % ', '.join(edit_ret) edit_rmsg = 'Edited: %s' % ', '.join(edit_ret)
irc.reply("%s; %s" % (auth_rmsg, edit_rmsg)) irc.reply("%s; %s" % (auth_rmsg, edit_rmsg))
lookup = wrap(lookup, [optional("nick"), optional("channel")]) lookup = wrap(lookup, [optional("channel"), optional("nick")])
def review(self, irc, msg, args, channel, reqid):
"""[<channel>] [<id>]
Lists edit requests. If <id> is given, prints the suggested new value.
"""
if not capab(msg.prefix, "editfactoids"):
irc.errorNoCapability("editfactoids")
return
db = self.get_db(channel)
cur = db.cursor()
if not reqid:
cur.execute("SELECT id, type, name, requester, requested FROM requests ORDER BY id DESC LIMIT 15")
res = cur.fetchall()
ret = []
for r in res:
ret.append("[%s] %s (%s) by %s on %s" % (r[0], r[2], r[1], r[3][:r[3].find('!')], r[4][:r[4].rfind('.')]))
if not ret:
rmsg = "No requests found"
else:
rmsg = ', '.join(ret)
else:
cur.execute("SELECT value FROM requests WHERE id = ?", (reqid,))
res = cur.fetchall()
if not res:
rmsg = "Request not found"
else:
rmsg = res[0][0]
irc.reply(rmsg)
review = wrap(review, [optional("channel"), optional("positiveInt")])
class ignore(callbacks.Commands): class ignore(callbacks.Commands):
def add(self, irc, msg, args, banmask, expires, channel): def add(self, irc, msg, args, channel, banmask, expires):
"""<hostmask|nick> [<expires>] [<channel>] """[<channel>] <hostmask|nick> [<expires>]
Ignores commands/requests from <hostmask> or <nick>. If <expires> is Ignores commands/requests from <hostmask> or <nick>. If <expires> is
given, the ignore will expire after that ammount of seconds. given, the ignore will expire after that ammount of seconds.
@ -944,10 +974,10 @@ class Encyclopedia(callbacks.Plugin):
else: else:
ircdb.ignores.add(banmask, expires) ircdb.ignores.add(banmask, expires)
irc.replySuccess() irc.replySuccess()
add = wrap(add, ['hostmask', optional("expiry", 0), optional("channel")]) add = wrap(add, [optional("channel"), 'hostmask', optional("expiry", 0)])
def remove(self, irc, msg, args, banmask, channel): def remove(self, irc, msg, args, channel, banmask):
"""<hostmask|nick> [<channel>] """[<channel>] <hostmask|nick>
Removes an ignore previously set by @ignore. If <channel> was Removes an ignore previously set by @ignore. If <channel> was
given in the original @ignore command, it must be given here. given in the original @ignore command, it must be given here.
@ -969,7 +999,7 @@ class Encyclopedia(callbacks.Plugin):
irc.replySuccess() irc.replySuccess()
except KeyError: except KeyError:
irc.error("That hostmask is not globally ignored") irc.error("That hostmask is not globally ignored")
remove = wrap(remove, ['hostmask', optional("channel")]) remove = wrap(remove, [optional("channel"), 'hostmask'])
def ignores(self, irc, msg, args, channel): def ignores(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]