Fixed some bugs
This commit is contained in:
parent
f8c51c9242
commit
3808ac60d2
|
@ -26,7 +26,7 @@ class Coins(Plugin):
|
||||||
|
|
||||||
%%btc [<currency>]
|
%%btc [<currency>]
|
||||||
"""
|
"""
|
||||||
return self._cryptowat_summary('btc', args.get('<currency>') or 'usd')
|
return self.cryptowat_summary('btc', args.get('<currency>') or 'usd')
|
||||||
|
|
||||||
@command
|
@command
|
||||||
def eth(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
def eth(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
|
@ -34,9 +34,9 @@ class Coins(Plugin):
|
||||||
|
|
||||||
%%eth [<currency>]
|
%%eth [<currency>]
|
||||||
"""
|
"""
|
||||||
return self._cryptowat_summary('eth', args.get('<currency>') or 'usd')
|
return self.cryptowat_summary('eth', args.get('<currency>') or 'usd')
|
||||||
|
|
||||||
def _cryptowat_summary(self, crypto: str, currency: str = 'usd'):
|
def cryptowat_summary(self, crypto: str, currency: str = 'usd'):
|
||||||
# Check if valid currency + crypto2currency
|
# Check if valid currency + crypto2currency
|
||||||
if currency not in self.CURRENCIES or crypto == currency:
|
if currency not in self.CURRENCIES or crypto == currency:
|
||||||
return
|
return
|
||||||
|
@ -45,7 +45,7 @@ class Coins(Plugin):
|
||||||
data = requests.get(self.API_URL.format(crypto=crypto, currency=currency))
|
data = requests.get(self.API_URL.format(crypto=crypto, currency=currency))
|
||||||
if data:
|
if data:
|
||||||
result = data.json()['result']
|
result = data.json()['result']
|
||||||
return '\x02[{crypto}]\x0F ' \
|
return '\x02[{crypto}]\x02 ' \
|
||||||
'Current: \x02\x0307{currency}{last:,.2f}\x0F - ' \
|
'Current: \x02\x0307{currency}{last:,.2f}\x0F - ' \
|
||||||
'High: \x02\x0303{currency}{high:,.2f}\x0F - ' \
|
'High: \x02\x0303{currency}{high:,.2f}\x0F - ' \
|
||||||
'Low: \x02\x0304{currency}{low:,.2f}\x0F - ' \
|
'Low: \x02\x0304{currency}{low:,.2f}\x0F - ' \
|
||||||
|
|
|
@ -16,7 +16,7 @@ class CTCP(Plugin):
|
||||||
|
|
||||||
# noinspection PyMethodMayBeStatic
|
# noinspection PyMethodMayBeStatic
|
||||||
def _ctcp(self, name: str, nick: str, reply: str):
|
def _ctcp(self, name: str, nick: str, reply: str):
|
||||||
return '\x02[{}]\x0F {}: {}'.format(name.upper(), nick, reply)
|
return '\x02[{}]\x02 {}: {}'.format(name.upper(), nick, reply)
|
||||||
|
|
||||||
async def ctcp(self, name: str, mask: IrcString, args: DocOptDict):
|
async def ctcp(self, name: str, mask: IrcString, args: DocOptDict):
|
||||||
nick = args.get('<nick>') or mask.nick
|
nick = args.get('<nick>') or mask.nick
|
||||||
|
@ -33,8 +33,7 @@ class CTCP(Plugin):
|
||||||
return self._ctcp(name, nick, reply)
|
return self._ctcp(name, nick, reply)
|
||||||
|
|
||||||
@command
|
@command
|
||||||
async def ping(self, mask: IrcString, target: IrcString,
|
async def ping(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
args: DocOptDict):
|
|
||||||
"""Sends ping via CTCP to user and sends the time needed
|
"""Sends ping via CTCP to user and sends the time needed
|
||||||
|
|
||||||
%%ping [<nick>]
|
%%ping [<nick>]
|
||||||
|
@ -58,8 +57,7 @@ class CTCP(Plugin):
|
||||||
return self._ctcp('PING', nick, reply)
|
return self._ctcp('PING', nick, reply)
|
||||||
|
|
||||||
@command
|
@command
|
||||||
async def finger(self, mask: IrcString, target: IrcString,
|
async def finger(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
args: DocOptDict):
|
|
||||||
"""Gets the client response for finger nick user via CTCP
|
"""Gets the client response for finger nick user via CTCP
|
||||||
|
|
||||||
%%finger [<nick>]
|
%%finger [<nick>]
|
||||||
|
@ -67,8 +65,7 @@ class CTCP(Plugin):
|
||||||
return await self.ctcp('FINGER', mask, args)
|
return await self.ctcp('FINGER', mask, args)
|
||||||
|
|
||||||
@command
|
@command
|
||||||
async def time(self, mask: IrcString, target: IrcString,
|
async def time(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
args: DocOptDict):
|
|
||||||
"""Gets the client time from nick via CTCP
|
"""Gets the client time from nick via CTCP
|
||||||
|
|
||||||
%%time [<nick>]
|
%%time [<nick>]
|
||||||
|
|
|
@ -25,9 +25,9 @@ class Quotes(DatabasePlugin):
|
||||||
else:
|
else:
|
||||||
# Insert quote into database
|
# Insert quote into database
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
insert into
|
INSERT INTO
|
||||||
quotes (nick, item, channel, created_by)
|
quotes (nick, item, channel, created_by)
|
||||||
values
|
VALUES
|
||||||
(%s, %s, %s, %s)
|
(%s, %s, %s, %s)
|
||||||
''', [nick, quote, channel, mask.nick])
|
''', [nick, quote, channel, mask.nick])
|
||||||
|
|
||||||
|
@ -83,6 +83,7 @@ class Quotes(DatabasePlugin):
|
||||||
self.con.commit()
|
self.con.commit()
|
||||||
except Error as ex:
|
except Error as ex:
|
||||||
# Rollback transaction on error
|
# Rollback transaction on error
|
||||||
|
print(ex)
|
||||||
self.con.rollback()
|
self.con.rollback()
|
||||||
else:
|
else:
|
||||||
index = args.get('<index>')
|
index = args.get('<index>')
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Timer(DatabasePlugin):
|
||||||
|
|
||||||
@command
|
@command
|
||||||
def timer(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
def timer(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
"""Sets a timer, delay can be: s, m, h, w, mon, y(
|
"""Sets a timer, delay can be: s, m, h, d, w, mon, y
|
||||||
|
|
||||||
%%timer <delay> <message>...
|
%%timer <delay> <message>...
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -33,6 +33,14 @@ class Useless(DatabasePlugin):
|
||||||
'keep your woahs to yourself',
|
'keep your woahs to yourself',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@command(permission='admin', show_in_help=False)
|
||||||
|
def kim(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
|
"""Kicks Kim, most useful command.
|
||||||
|
|
||||||
|
%%kim
|
||||||
|
"""
|
||||||
|
self.bot.kick(target, 'Kim')
|
||||||
|
|
||||||
@irc3.event(r'(?i)^:(?P<mask>\S+@\S+({isps})\S+) JOIN :(?P<target>#\S+)$'.format(isps='|'.join(ISPS)))
|
@irc3.event(r'(?i)^:(?P<mask>\S+@\S+({isps})\S+) JOIN :(?P<target>#\S+)$'.format(isps='|'.join(ISPS)))
|
||||||
def bounce(self, mask, target):
|
def bounce(self, mask, target):
|
||||||
nick = IrcString(mask).nick
|
nick = IrcString(mask).nick
|
||||||
|
@ -75,13 +83,13 @@ class Useless(DatabasePlugin):
|
||||||
%%kill [<nick>]
|
%%kill [<nick>]
|
||||||
"""
|
"""
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
select
|
SELECT
|
||||||
item
|
item
|
||||||
from
|
FROM
|
||||||
kills
|
kills
|
||||||
order by
|
ORDER BY
|
||||||
random()
|
random()
|
||||||
limit
|
LIMIT
|
||||||
1
|
1
|
||||||
''')
|
''')
|
||||||
self.bot.action(target, self.cur.fetchone()['item'].format(
|
self.bot.action(target, self.cur.fetchone()['item'].format(
|
||||||
|
@ -95,13 +103,13 @@ class Useless(DatabasePlugin):
|
||||||
%%yiff [<nick>]
|
%%yiff [<nick>]
|
||||||
"""
|
"""
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
select
|
SELECT
|
||||||
item
|
item
|
||||||
from
|
FROM
|
||||||
yiffs
|
yiffs
|
||||||
order by
|
ORDER BY
|
||||||
random()
|
random()
|
||||||
limit
|
LIMIT
|
||||||
1
|
1
|
||||||
''')
|
''')
|
||||||
self.bot.action(target, self.cur.fetchone()['item'].format(
|
self.bot.action(target, self.cur.fetchone()['item'].format(
|
||||||
|
@ -122,11 +130,11 @@ class Useless(DatabasePlugin):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
insert into
|
INSERT INTO
|
||||||
users (nick, waifu)
|
users (nick, waifu)
|
||||||
values
|
VALUES
|
||||||
(lower(%s), %s)
|
(lower(%s), %s)
|
||||||
on conflict (nick) do update set
|
ON CONFLICT (nick) DO UPDATE SET
|
||||||
waifu = excluded.waifu
|
waifu = excluded.waifu
|
||||||
''', [mask.nick, waifu])
|
''', [mask.nick, waifu])
|
||||||
self.con.commit()
|
self.con.commit()
|
||||||
|
@ -137,11 +145,11 @@ class Useless(DatabasePlugin):
|
||||||
self.con.rollback()
|
self.con.rollback()
|
||||||
else:
|
else:
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
select
|
SELECT
|
||||||
waifu
|
waifu
|
||||||
from
|
FROM
|
||||||
users
|
users
|
||||||
where
|
WHERE
|
||||||
lower(nick) = lower(%s)
|
lower(nick) = lower(%s)
|
||||||
''', [nick])
|
''', [nick])
|
||||||
result = self.cur.fetchone()
|
result = self.cur.fetchone()
|
||||||
|
@ -162,11 +170,11 @@ class Useless(DatabasePlugin):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
insert into
|
INSERT INTO
|
||||||
users (nick, husbando)
|
users (nick, husbando)
|
||||||
values
|
VALUES
|
||||||
(lower(%s), %s)
|
(lower(%s), %s)
|
||||||
on conflict (nick) do update set
|
ON CONFLICT (nick) DO UPDATE SET
|
||||||
husbando = excluded.husbando
|
husbando = excluded.husbando
|
||||||
''', [mask.nick, nick])
|
''', [mask.nick, nick])
|
||||||
self.con.commit()
|
self.con.commit()
|
||||||
|
@ -177,11 +185,11 @@ class Useless(DatabasePlugin):
|
||||||
self.con.rollback()
|
self.con.rollback()
|
||||||
else:
|
else:
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
select
|
SELECT
|
||||||
husbando
|
husbando
|
||||||
from
|
FROM
|
||||||
users
|
users
|
||||||
where
|
WHERE
|
||||||
lower(nick) = lower(%s)
|
lower(nick) = lower(%s)
|
||||||
''', [nick])
|
''', [nick])
|
||||||
result = self.cur.fetchone()
|
result = self.cur.fetchone()
|
||||||
|
|
19
bot/utils.py
19
bot/utils.py
|
@ -23,14 +23,25 @@ def date_from_iso(date: str) -> datetime:
|
||||||
|
|
||||||
|
|
||||||
def time_delta(text: str) -> timedelta:
|
def time_delta(text: str) -> timedelta:
|
||||||
match = re.match(r'(\d+)(s|m|h|mon|w|y)', text)
|
match = re.match(r'(\d+)(s|m|h|d|mon|w|y)', text)
|
||||||
if match:
|
if match:
|
||||||
num, unit = match.groups()
|
num, unit = match.groups()
|
||||||
num = int(num)
|
num = int(num)
|
||||||
unit = TIME_UNITS[unit]
|
if unit == 's':
|
||||||
if unit == 'mon':
|
unit = 'seconds'
|
||||||
|
elif unit == 'm':
|
||||||
|
unit = 'minutes'
|
||||||
|
elif unit == 'h':
|
||||||
|
unit = 'hours'
|
||||||
|
elif unit == 'd':
|
||||||
|
unit = 'days'
|
||||||
|
elif unit == 'w':
|
||||||
|
unit = 'weeks'
|
||||||
|
elif unit == 'mon':
|
||||||
|
unit = 'weeks'
|
||||||
num *= 4
|
num *= 4
|
||||||
elif unit == 'y':
|
elif unit == 'y':
|
||||||
|
unit = 'weeks'
|
||||||
num *= 52
|
num *= 52
|
||||||
return timedelta(**{unit: num})
|
return timedelta(**{unit: num})
|
||||||
|
|
||||||
|
@ -52,4 +63,4 @@ def parse_int(val: str, select: bool = True) -> Tuple[int, str]:
|
||||||
|
|
||||||
|
|
||||||
def re_generator(low: int = 5, high: int = 20) -> str:
|
def re_generator(low: int = 5, high: int = 20) -> str:
|
||||||
return 'R{}'.format(''.join('E' for _ in range(random.randint(low, high))))
|
return 'R{}'.format('E' * random.randint(low, high))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user