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 -*-
import sqlite3
import os
DATA = 'data'
MIGRATE = os.path.join(DATA, 'migrate')
db = sqlite3.connect(os.path.join(DATA, 'nxy.db'))
def mcmaniac():
with open('data/mcmaniac.txt', 'r') as fp:
items = [(l.replace('\n', ''),) for l in fp]
con = sqlite3.connect('data/nxy.db')
con.executemany('insert into mcmaniacs (item) values (?)', items)
con.commit()
def read_file(file):
with open(os.path.join(MIGRATE, file), 'r') as fp:
return [(l.replace('\n', ''),) for l in fp]
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} - '
'Low: {bold}{color}{maroon}${low:,.2f}{reset} - '
'Volume: {bold}฿{volume:,.2f}',
last=float(data['last']),
high=float(data['high']),
low=float(data['low']),
volume=float(data['volume']))
last=float(data['last']), high=float(data['high']),
low=float(data['low']), volume=float(data['volume']))

View File

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

View File

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

View File

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