Removed add/del from mcmaniac (regex event adds now)
This commit is contained in:
parent
4fdc951718
commit
63eb1e3889
|
@ -2,6 +2,7 @@
|
|||
from docopt import Dict as DocOptDict
|
||||
from irc3.plugins.command import command
|
||||
from irc3.utils import IrcString
|
||||
from irc3 import event
|
||||
|
||||
from . import DatabasePlugin
|
||||
from ..utils import parse_int
|
||||
|
@ -14,30 +15,10 @@ class McManiac(DatabasePlugin):
|
|||
# noinspection PyUnusedLocal
|
||||
@command(options_first=True)
|
||||
def mcmaniac(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
"""Get, add or delete McManiaCs
|
||||
"""Get a random McManiaC or by index.
|
||||
|
||||
%%mcmaniac <cmd> <mcmaniac>
|
||||
%%mcmaniac [<index>]
|
||||
"""
|
||||
cmd = args.get('<cmd>')
|
||||
item = args.get('<mcmaniac>')
|
||||
if cmd and item:
|
||||
if self.guard.has_permission(mask, 'admin'):
|
||||
if cmd == 'add':
|
||||
self.cur.execute('insert into mcmaniacs (item) values (?)',
|
||||
[item])
|
||||
if cmd == 'del':
|
||||
index, order, op = parse_int(item, select=False)
|
||||
if not index:
|
||||
return
|
||||
self.cur.execute('''delete from mcmaniacs where id =
|
||||
(select id from mcmaniacs a where ? = (select count(id)
|
||||
from mcmaniacs b where a.id {op} b.id) order by id {order})
|
||||
'''.format(op=op, order=order), [index])
|
||||
self.con.commit()
|
||||
else:
|
||||
self.bot.notice(mask.nick, 'Permission denied')
|
||||
else:
|
||||
index = args.get('<index>')
|
||||
if index:
|
||||
index = parse_int(index)
|
||||
|
@ -59,3 +40,11 @@ class McManiac(DatabasePlugin):
|
|||
result = self.cur.fetchone()
|
||||
if result:
|
||||
return '[{idx}/{len}] {item}'.format(**result)
|
||||
|
||||
@event(r'(?i)^:(?P<mask>\S+) PRIVMSG \S+ :(?P<msg>.*(?P<item>Mc\S+iaC).*)')
|
||||
def check(self, mask: str, msg: str, item: str):
|
||||
nick = IrcString(mask).nick
|
||||
if nick != self.bot.nick and msg != '.reload mcmaniac':
|
||||
self.cur.execute('insert into mcmaniacs (item) values (?)', [item])
|
||||
self.con.commit()
|
||||
self.bot.notice(nick, '[McManiac] added "{}"'.format(item))
|
||||
|
|
|
@ -72,7 +72,7 @@ def time_delta(text: str) -> timedelta:
|
|||
return timedelta(**{unit: num})
|
||||
|
||||
|
||||
def parse_int(val: str, select: bool = True) -> tuple:
|
||||
def parse_int(val: str) -> tuple:
|
||||
try:
|
||||
val = int(val)
|
||||
if val is not 0:
|
||||
|
@ -81,7 +81,6 @@ def parse_int(val: str, select: bool = True) -> tuple:
|
|||
val *= -1
|
||||
else:
|
||||
order, op = 'asc', '>='
|
||||
if select:
|
||||
val -= 1
|
||||
return val, order, op
|
||||
except ValueError:
|
||||
|
|
Loading…
Reference in New Issue
Block a user