Fixed some bugs

This commit is contained in:
mrhanky 2017-08-16 14:39:44 +02:00
parent f8c51c9242
commit 3808ac60d2
No known key found for this signature in database
GPG Key ID: 67D772C481CB41B8
6 changed files with 55 additions and 38 deletions

View File

@ -26,7 +26,7 @@ class Coins(Plugin):
%%btc [<currency>]
"""
return self._cryptowat_summary('btc', args.get('<currency>') or 'usd')
return self.cryptowat_summary('btc', args.get('<currency>') or 'usd')
@command
def eth(self, mask: IrcString, target: IrcString, args: DocOptDict):
@ -34,9 +34,9 @@ class Coins(Plugin):
%%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
if currency not in self.CURRENCIES or crypto == currency:
return
@ -45,7 +45,7 @@ class Coins(Plugin):
data = requests.get(self.API_URL.format(crypto=crypto, currency=currency))
if data:
result = data.json()['result']
return '\x02[{crypto}]\x0F ' \
return '\x02[{crypto}]\x02 ' \
'Current: \x02\x0307{currency}{last:,.2f}\x0F - ' \
'High: \x02\x0303{currency}{high:,.2f}\x0F - ' \
'Low: \x02\x0304{currency}{low:,.2f}\x0F - ' \

View File

@ -16,7 +16,7 @@ class CTCP(Plugin):
# noinspection PyMethodMayBeStatic
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):
nick = args.get('<nick>') or mask.nick
@ -33,8 +33,7 @@ class CTCP(Plugin):
return self._ctcp(name, nick, reply)
@command
async def ping(self, mask: IrcString, target: IrcString,
args: DocOptDict):
async def ping(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Sends ping via CTCP to user and sends the time needed
%%ping [<nick>]
@ -58,8 +57,7 @@ class CTCP(Plugin):
return self._ctcp('PING', nick, reply)
@command
async def finger(self, mask: IrcString, target: IrcString,
args: DocOptDict):
async def finger(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Gets the client response for finger nick user via CTCP
%%finger [<nick>]
@ -67,8 +65,7 @@ class CTCP(Plugin):
return await self.ctcp('FINGER', mask, args)
@command
async def time(self, mask: IrcString, target: IrcString,
args: DocOptDict):
async def time(self, mask: IrcString, target: IrcString, args: DocOptDict):
"""Gets the client time from nick via CTCP
%%time [<nick>]

View File

@ -25,9 +25,9 @@ class Quotes(DatabasePlugin):
else:
# Insert quote into database
self.cur.execute('''
insert into
INSERT INTO
quotes (nick, item, channel, created_by)
values
VALUES
(%s, %s, %s, %s)
''', [nick, quote, channel, mask.nick])
@ -83,6 +83,7 @@ class Quotes(DatabasePlugin):
self.con.commit()
except Error as ex:
# Rollback transaction on error
print(ex)
self.con.rollback()
else:
index = args.get('<index>')

View File

@ -39,7 +39,7 @@ class Timer(DatabasePlugin):
@command
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>...
"""

View File

@ -33,6 +33,14 @@ class Useless(DatabasePlugin):
'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)))
def bounce(self, mask, target):
nick = IrcString(mask).nick
@ -75,13 +83,13 @@ class Useless(DatabasePlugin):
%%kill [<nick>]
"""
self.cur.execute('''
select
SELECT
item
from
FROM
kills
order by
ORDER BY
random()
limit
LIMIT
1
''')
self.bot.action(target, self.cur.fetchone()['item'].format(
@ -95,13 +103,13 @@ class Useless(DatabasePlugin):
%%yiff [<nick>]
"""
self.cur.execute('''
select
SELECT
item
from
FROM
yiffs
order by
ORDER BY
random()
limit
LIMIT
1
''')
self.bot.action(target, self.cur.fetchone()['item'].format(
@ -122,11 +130,11 @@ class Useless(DatabasePlugin):
try:
self.cur.execute('''
insert into
INSERT INTO
users (nick, waifu)
values
VALUES
(lower(%s), %s)
on conflict (nick) do update set
ON CONFLICT (nick) DO UPDATE SET
waifu = excluded.waifu
''', [mask.nick, waifu])
self.con.commit()
@ -137,11 +145,11 @@ class Useless(DatabasePlugin):
self.con.rollback()
else:
self.cur.execute('''
select
SELECT
waifu
from
FROM
users
where
WHERE
lower(nick) = lower(%s)
''', [nick])
result = self.cur.fetchone()
@ -162,11 +170,11 @@ class Useless(DatabasePlugin):
try:
self.cur.execute('''
insert into
INSERT INTO
users (nick, husbando)
values
VALUES
(lower(%s), %s)
on conflict (nick) do update set
ON CONFLICT (nick) DO UPDATE SET
husbando = excluded.husbando
''', [mask.nick, nick])
self.con.commit()
@ -177,11 +185,11 @@ class Useless(DatabasePlugin):
self.con.rollback()
else:
self.cur.execute('''
select
SELECT
husbando
from
FROM
users
where
WHERE
lower(nick) = lower(%s)
''', [nick])
result = self.cur.fetchone()

View File

@ -23,14 +23,25 @@ def date_from_iso(date: str) -> datetime:
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:
num, unit = match.groups()
num = int(num)
unit = TIME_UNITS[unit]
if unit == 'mon':
if unit == 's':
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
elif unit == 'y':
unit = 'weeks'
num *= 52
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:
return 'R{}'.format(''.join('E' for _ in range(random.randint(low, high))))
return 'R{}'.format('E' * random.randint(low, high))