mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-19 23:20:57 +01:00
Updated to use commands.wrap.
This commit is contained in:
parent
71e18515d7
commit
ca5a27f2d4
@ -54,8 +54,8 @@ import supybot.conf as conf
|
|||||||
import supybot.utils as utils
|
import supybot.utils as utils
|
||||||
import supybot.ircdb as ircdb
|
import supybot.ircdb as ircdb
|
||||||
import supybot.plugins as plugins
|
import supybot.plugins as plugins
|
||||||
|
from supybot.commands import wrap
|
||||||
import supybot.registry as registry
|
import supybot.registry as registry
|
||||||
import supybot.privmsgs as privmsgs
|
|
||||||
import supybot.ircutils as ircutils
|
import supybot.ircutils as ircutils
|
||||||
import supybot.callbacks as callbacks
|
import supybot.callbacks as callbacks
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ class Dunno(callbacks.Privmsg):
|
|||||||
dunno = plugins.standardSubstitute(irc, msg, dunno)
|
dunno = plugins.standardSubstitute(irc, msg, dunno)
|
||||||
irc.reply(dunno, prefixName=prefixName)
|
irc.reply(dunno, prefixName=prefixName)
|
||||||
|
|
||||||
def add(self, irc, msg, args):
|
def add(self, irc, msg, args, user, at, channel, dunno):
|
||||||
"""[<channel>] <text>
|
"""[<channel>] <text>
|
||||||
|
|
||||||
Adds <text> as a "dunno" to be used as a random response when no
|
Adds <text> as a "dunno" to be used as a random response when no
|
||||||
@ -123,57 +123,36 @@ class Dunno(callbacks.Privmsg):
|
|||||||
<channel> is only necessary if the message isn't sent in the channel
|
<channel> is only necessary if the message isn't sent in the channel
|
||||||
itself.
|
itself.
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
id = self.db.add(channel, dunno, user.id, at)
|
||||||
try:
|
|
||||||
by = ircdb.users.getUserId(msg.prefix)
|
|
||||||
except KeyError:
|
|
||||||
irc.errorNotRegistered()
|
|
||||||
return
|
|
||||||
dunno = privmsgs.getArgs(args)
|
|
||||||
at = int(time.time())
|
|
||||||
id = self.db.add(channel, dunno, by, at)
|
|
||||||
irc.replySuccess('Dunno #%s added.' % id)
|
irc.replySuccess('Dunno #%s added.' % id)
|
||||||
|
add = wrap(add, ['user', 'now', 'channeldb', 'text'])
|
||||||
|
|
||||||
def remove(self, irc, msg, args):
|
def remove(self, irc, msg, args, user, channel, id):
|
||||||
"""[<channel>] <id>
|
"""[<channel>] <id>
|
||||||
|
|
||||||
Removes dunno with the given <id>. <channel> is only necessary if the
|
Removes dunno with the given <id>. <channel> is only necessary if the
|
||||||
message isn't sent in the channel itself.
|
message isn't sent in the channel itself.
|
||||||
"""
|
"""
|
||||||
# Must be registered to use this
|
# Must be registered to use this
|
||||||
channel = privmsgs.getChannel(msg, args)
|
|
||||||
try:
|
try:
|
||||||
by = ircdb.users.getUserId(msg.prefix)
|
|
||||||
except KeyError:
|
|
||||||
irc.errorNotRegistered()
|
|
||||||
return
|
|
||||||
id = privmsgs.getArgs(args)
|
|
||||||
try:
|
|
||||||
id = int(id)
|
|
||||||
except ValueError:
|
|
||||||
irc.error('Invalid id: %r' % id)
|
|
||||||
return
|
|
||||||
dunno = self.db.get(channel, id)
|
dunno = self.db.get(channel, id)
|
||||||
if by != dunno.by:
|
if user.id != dunno.by:
|
||||||
cap = ircdb.makeChannelCapability(channel, 'op')
|
cap = ircdb.makeChannelCapability(channel, 'op')
|
||||||
if not ircdb.users.checkCapability(cap):
|
if not ircdb.users.checkCapability(cap):
|
||||||
irc.errorNoCapability(cap)
|
irc.errorNoCapability(cap)
|
||||||
return
|
|
||||||
try:
|
|
||||||
self.db.remove(channel, id)
|
self.db.remove(channel, id)
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
irc.error('No dunno has id #%s.' % id)
|
irc.error('No dunno has id #%s.' % id)
|
||||||
|
remove = wrap(remove, ['user', 'channeldb', ('id', 'dunno')])
|
||||||
|
|
||||||
def search(self, irc, msg, args):
|
def search(self, irc, msg, args, channel, text):
|
||||||
"""[<channel>] <text>
|
"""[<channel>] <text>
|
||||||
|
|
||||||
Search for dunno containing the given text. Returns the ids of the
|
Search for dunno containing the given text. Returns the ids of the
|
||||||
dunnos with the text in them. <channel> is only necessary if the
|
dunnos with the text in them. <channel> is only necessary if the
|
||||||
message isn't sent in the channel itself.
|
message isn't sent in the channel itself.
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
def p(dunno):
|
def p(dunno):
|
||||||
return text.lower() in dunno.text.lower()
|
return text.lower() in dunno.text.lower()
|
||||||
ids = [str(dunno.id) for dunno in self.db.select(channel, p)]
|
ids = [str(dunno.id) for dunno in self.db.select(channel, p)]
|
||||||
@ -183,20 +162,14 @@ class Dunno(callbacks.Privmsg):
|
|||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
else:
|
else:
|
||||||
irc.reply('No dunnos found matching that search criteria.')
|
irc.reply('No dunnos found matching that search criteria.')
|
||||||
|
search = wrap(search, ['channeldb', 'text'])
|
||||||
|
|
||||||
def get(self, irc, msg, args):
|
def get(self, irc, msg, args, channel, id):
|
||||||
"""[<channel>] <id>
|
"""[<channel>] <id>
|
||||||
|
|
||||||
Display the text of the dunno with the given id. <channel> is only
|
Display the text of the dunno with the given id. <channel> is only
|
||||||
necessary if the message isn't sent in the channel itself.
|
necessary if the message isn't sent in the channel itself.
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
|
||||||
id = privmsgs.getArgs(args)
|
|
||||||
try:
|
|
||||||
id = int(id)
|
|
||||||
except ValueError:
|
|
||||||
irc.error('%r is not a valid dunno id.' % id)
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
dunno = self.db.get(channel, id)
|
dunno = self.db.get(channel, id)
|
||||||
name = ircdb.users.getUser(dunno.by).name
|
name = ircdb.users.getUser(dunno.by).name
|
||||||
@ -206,50 +179,33 @@ class Dunno(callbacks.Privmsg):
|
|||||||
(id, dunno.text, name, timeStr))
|
(id, dunno.text, name, timeStr))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
irc.error('No dunno found with that id.')
|
irc.error('No dunno found with that id.')
|
||||||
|
get = wrap(get, ['channeldb', ('id', 'dunno')])
|
||||||
|
|
||||||
def change(self, irc, msg, args):
|
def change(self, irc, msg, args, channel, id, replacer):
|
||||||
"""[<channel>] <id> <regexp>
|
"""[<channel>] <id> <regexp>
|
||||||
|
|
||||||
Alters the dunno with the given id according to the provided regexp.
|
Alters the dunno with the given id according to the provided regexp.
|
||||||
<channel> is only necessary if the message isn't sent in the channel
|
<channel> is only necessary if the message isn't sent in the channel
|
||||||
itself.
|
itself.
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
|
||||||
(id, regexp) = privmsgs.getArgs(args, required=2)
|
|
||||||
try:
|
try:
|
||||||
user_id = ircdb.users.getUserId(msg.prefix)
|
self.db.change(channel, id, replacer)
|
||||||
except KeyError:
|
|
||||||
irc.errorNotRegistered()
|
|
||||||
return
|
|
||||||
# Check id arg
|
|
||||||
try:
|
|
||||||
id = int(id)
|
|
||||||
except ValueError:
|
|
||||||
irc.error('%r is not a valid dunno id.' % id)
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
_ = self.db.get(channel, id)
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
irc.error('There is no dunno #%s.' % id)
|
irc.error('There is no dunno #%s.' % id)
|
||||||
return
|
return
|
||||||
try:
|
|
||||||
replacer = utils.perlReToReplacer(regexp)
|
|
||||||
except:
|
|
||||||
irc.error('%r is not a valid regular expression.' % regexp)
|
|
||||||
return
|
|
||||||
self.db.change(channel, id, replacer)
|
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
|
change = wrap(change, ['channeldb', ('id', 'dunno'), 'regexpReplacer'])
|
||||||
|
|
||||||
def stats(self, irc, msg, args):
|
def stats(self, irc, msg, args, channel):
|
||||||
"""[<channel>]
|
"""[<channel>]
|
||||||
|
|
||||||
Returns the number of dunnos in the dunno database. <channel> is only
|
Returns the number of dunnos in the dunno database. <channel> is only
|
||||||
necessary if the message isn't sent in the channel itself.
|
necessary if the message isn't sent in the channel itself.
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
|
||||||
num = self.db.size(channel)
|
num = self.db.size(channel)
|
||||||
irc.reply('There %s %s in my database.' %
|
irc.reply('There %s %s in my database.' %
|
||||||
(utils.be(num), utils.nItems('dunno', num)))
|
(utils.be(num), utils.nItems('dunno', num)))
|
||||||
|
stats = wrap(stats, ['channeldb'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user