This commit is contained in:
mrhanky 2017-05-16 13:44:39 +02:00
parent 6636d906fd
commit a86ee5e33d
No known key found for this signature in database
GPG Key ID: 67D772C481CB41B8
5 changed files with 56 additions and 50 deletions

View File

@ -1,12 +1,23 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sqlite3 import sqlite3
import os
DATA = 'data'
MIGRATE = os.path.join(DATA, 'migrate')
db = sqlite3.connect(os.path.join(DATA, 'nxy.db'))
def mcmaniac(): def read_file(file):
with open('data/mcmaniac.txt', 'r') as fp: with open(os.path.join(MIGRATE, file), 'r') as fp:
items = [(l.replace('\n', ''),) for l in fp] return [(l.replace('\n', ''),) for l in fp]
con = sqlite3.connect('data/nxy.db')
con.executemany('insert into mcmaniacs (item) values (?)', items)
con.commit()
def batch_insert(table, column, data):
db.executemany('insert into {table} ({column}) values (?)'.
format(table=table, column=column), data)
db.commit()
batch_insert('mcmaniacs', 'item', read_file('mcmaniac.txt'))
batch_insert('yiffs', 'item', read_file('yiff.txt'))

View File

@ -28,7 +28,5 @@ class Coins(Plugin):
'High: {bold}{color}{green}${high:,.2f}{reset} - ' 'High: {bold}{color}{green}${high:,.2f}{reset} - '
'Low: {bold}{color}{maroon}${low:,.2f}{reset} - ' 'Low: {bold}{color}{maroon}${low:,.2f}{reset} - '
'Volume: {bold}฿{volume:,.2f}', 'Volume: {bold}฿{volume:,.2f}',
last=float(data['last']), last=float(data['last']), high=float(data['high']),
high=float(data['high']), low=float(data['low']), volume=float(data['volume']))
low=float(data['low']),
volume=float(data['volume']))

View File

@ -55,12 +55,8 @@ class CTCP(Plugin):
unit = 'ms' unit = 'ms'
else: else:
unit = 's' unit = 's'
reply = '{delta:.3f} {unit}'.format( reply = '{delta:.3f} {unit}'.format(unit=unit, delta=delta)
unit=unit, # 'ms' if delta < 0 else 's', return fmt('{bold}[PING]{reset} {nick}: {text}', nick=nick, text=reply)
delta=delta)
return fmt('{bold}[PING]{reset} {nick}: {text}',
nick=nick,
text=reply)
@command @command
async def finger(self, mask: IrcString, channel: IrcString, async def finger(self, mask: IrcString, channel: IrcString,

View File

@ -21,9 +21,6 @@ class Futures(DatabasePlugin):
def __init__(self, bot: IrcBot): def __init__(self, bot: IrcBot):
super().__init__(bot) super().__init__(bot)
self.restore()
def restore(self):
self.cur.execute('select * from timers') self.cur.execute('select * from timers')
for res in self.cur.fetchall(): for res in self.cur.fetchall():
delta = res['until'] - datetime.utcnow() delta = res['until'] - datetime.utcnow()
@ -33,7 +30,9 @@ class Futures(DatabasePlugin):
@command @command
def timer(self, mask: IrcString, channel: IrcString, args: DocOptDict): def timer(self, mask: IrcString, channel: IrcString, args: DocOptDict):
"""Timer command. """Timer command, delay can be: s(econd), m(min), h(our), w(week),
mon(th), y(ear)
%%timer <delay> <message>... %%timer <delay> <message>...
""" """
delay = args['<delay>'] delay = args['<delay>']
@ -42,14 +41,15 @@ class Futures(DatabasePlugin):
date = datetime.utcnow() + delta date = datetime.utcnow() + delta
message = ' '.join(args['<message>']) message = ' '.join(args['<message>'])
self.cur.execute('''insert into timers (mask, channel, message, self.cur.execute('''insert into timers (mask, channel, message,
delay, until) values (?, ?, ?, ?, ?)''', delay, until) values (?, ?, ?, ?, ?)''', [mask.nick, channel,
[mask.nick, channel, message, delay, date]) message, delay, date])
self.con.commit() self.con.commit()
asyncio.ensure_future(self._timer( asyncio.ensure_future(self._timer(mask, channel, delta, message,
mask, channel, delta, message, delay, self.cur.lastrowid)) delay, self.cur.lastrowid))
self.bot.notice(mask.nick, 'Timer in {delay} set: {message}'
.format(delay=delay, message=message))
else: else:
self.bot.notice(mask.nick, 'Invalid delay "{delay}" for "timer"' self.bot.privmsg(channel, 'Invalid timer delay')
.format(delay=args['<delay>']))
async def _timer(self, mask: IrcString, channel: IrcString, async def _timer(self, mask: IrcString, channel: IrcString,
delta: timedelta, message: str, delay: str, row_id: int): delta: timedelta, message: str, delay: str, row_id: int):
@ -60,10 +60,8 @@ class Futures(DatabasePlugin):
seconds = delta.total_seconds() seconds = delta.total_seconds()
if seconds > 0: if seconds > 0:
await asyncio.sleep(seconds) await asyncio.sleep(seconds)
text = fmt('{bold}[Reminder]{reset} {nick}: {message} ({delay})', text = fmt('{bold}[Timer]{reset} {nick}: {message} ({delay})',
message=message, message=message, delay=delay, nick=mask.nick)
delay=delay,
nick=mask.nick)
self.bot.privmsg(channel, text) self.bot.privmsg(channel, text)
self.cur.execute('delete from timers where id = ?', [row_id]) self.cur.execute('delete from timers where id = ?', [row_id])
self.con.commit() self.con.commit()

View File

@ -6,22 +6,22 @@ from pprint import pprint
# @formatter:off # @formatter:off
COLORS = dict( COLORS = dict(
white='00', # white white=0, # white
black='01', # black black=1, # black
blue='02', # blue (navy) blue=2, # blue (navy)
green='03', # green green=3, # green
red='04', # red red=4, # red
maroon='05', # brown (maroon) maroon=5, # brown (maroon)
purple='06', # purple purple=6, # purple
orange='07', # orange (olive) orange=7, # orange (olive)
yellow='08', # yellow yellow=8, # yellow
ltgreen='09', # light green (lime) ltgreen=9, # light green (lime)
teal='10', # teal (a green/blue cyan) teal=10, # teal (a green/blue cyan)
ltcyan='11', # light cyan (cyan / aqua) ltcyan=11, # light cyan (cyan / aqua)
ltblue='12', # light blue (royal) ltblue=12, # light blue (royal)
pink='13', # pink (light purple / fuchsia) pink=13, # pink (light purple / fuchsia)
grey='14', # grey grey=14, # grey
ltgrey='15', # light grey (silver) ltgrey=15, # light grey (silver)
) )
FORMATTING = dict( FORMATTING = dict(
@ -45,22 +45,25 @@ def fmt(__text: str, **kwargs) -> str:
def time_delta(text: str) -> timedelta: def time_delta(text: str) -> timedelta:
match = re.match(r'(\d+)([smhdwy])', text) match = re.match(r'(\d+)(s|m|h|mon|w|y)', text)
if match: if match:
num, unit = match.groups() num, unit = match.groups()
num = int(num) num = int(num)
if unit == 's': if unit == 's':
unit = 'seconds' unit = 'seconds'
elif unit == 'm': elif unit == 'm':
unit = 'months' unit = 'minutes'
elif unit == 'h': elif unit == 'h':
unit = 'hours' unit = 'hours'
elif unit == 'd': elif unit == 'd':
unit = 'days' unit = 'days'
elif unit == 'w': elif unit == 'w':
unit = 'weeks' unit = 'weeks'
elif unit == 's': elif unit == 'mon':
unit = 'years' unit = 'weeks'
num *= 4
elif unit == 'y':
unit = 'weeks'
num *= 52 num *= 52
return timedelta(**{unit: num}) return timedelta(**{unit: num})