wub wub wub

This commit is contained in:
mrhanky 2017-05-16 12:49:06 +02:00
parent 3845b28e0a
commit fa045886de
No known key found for this signature in database
GPG Key ID: 67D772C481CB41B8
7 changed files with 43 additions and 36 deletions

View File

@ -15,7 +15,7 @@
"irc3.plugins.command",
"irc3.plugins.uptime",
"nxy.plugins.admin",
"nxy.plugins.bitcoin",
"nxy.plugins.coins",
"nxy.plugins.ctcp",
"nxy.plugins.database",
"nxy.plugins.futures",

12
nxy/migrate.py Normal file
View File

@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
import sqlite3
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()

View File

@ -1,27 +1,28 @@
# -*- coding: utf-8 -*-
import irc3
import requests
from docopt import Dict as DocOptDict
from irc3.plugins.command import command
from irc3.utils import IrcString
from . import Plugin
from ..utils import fmt, req
from ..utils import fmt
# noinspection PyUnusedLocal
@irc3.plugin
class Bitcoin(Plugin):
class Coins(Plugin):
requires = [
'irc3.plugins.command',
]
@command
async def btc(self, mask: IrcString, channel: IrcString, args: DocOptDict):
def btc(self, mask: IrcString, channel: IrcString, args: DocOptDict):
"""Bitcoin command.
%%btc
"""
data = (await req('get', 'https://www.bitstamp.net/api/ticker')).json()
data = requests.get('https://www.bitstamp.net/api/ticker').json()
return fmt('{bold}[BitStamp, 24h]{reset} '
'Current: {bold}{color}{orange}${last:,.2f}{reset} - '
'High: {bold}{color}{green}${high:,.2f}{reset} - '

View File

@ -13,7 +13,7 @@ from ..utils import fmt
# noinspection PyUnusedLocal
@irc3.plugin
class CTCP(Plugin):
TIMEOUT = 5
TIMEOUT = 10
requires = [
'irc3.plugins.async',
@ -50,8 +50,13 @@ class CTCP(Plugin):
reply = 'Error: {reply}'.format(reply=ctcp['reply'])
else:
delta = time.time() - float(ctcp['reply'])
reply = '{delta:.9f} {unit}'.format(
unit='ms' if delta < 0 else 's',
if delta < 1.0:
delta *= 1000
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,

View File

@ -54,7 +54,7 @@ class McManiac(DatabasePlugin):
binds = []
self.cur.execute('''select item,
(select count(id) from mcmaniacs b where a.id >= b.id) as idx,
(select count(id) from mcmaniasc) as len
(select count(id) from mcmaniacs) as len
from mcmaniacs a order by {order} limit 1 {extra}
'''.format(order=order, extra=extra), binds)
result = self.cur.fetchone()

View File

@ -3,7 +3,6 @@ import re
from datetime import timedelta
from pprint import pprint
from requests import request, Response
# @formatter:off
COLORS = dict(
@ -36,17 +35,6 @@ FORMATTING = dict(
)
# @formatter:on
TIME_REGEX = re.compile(r'(\d+)([smhdwy])')
TIME_DICT = {
's': ['seconds', 1],
'm': ['minutes', 60],
'h': ['hours', 3600],
'd': ['days', 86400],
'w': ['weeks', 604800],
'y': ['years', 31449600],
}
# Debug helper
pp = pprint
@ -56,25 +44,25 @@ def fmt(__text: str, **kwargs) -> str:
return __text.format(**kwargs, **FORMATTING)
async def req(method: str, url: str, **kwargs) -> Response:
return request(method, url, **kwargs)
def time_to_sec(text: str) -> int:
match = TIME_REGEX.match(text)
if match:
num, unit = match.groups()
return int(num) * TIME_DICT[unit][1]
def time_delta(text: str) -> timedelta:
match = TIME_REGEX.match(text)
match = re.match(r'(\d+)([smhdwy])', text)
if match:
num, unit = match.groups()
num = int(num)
if unit == 'years':
if unit == 's':
unit = 'seconds'
elif unit == 'm':
unit = 'months'
elif unit == 'h':
unit = 'hours'
elif unit == 'd':
unit = 'days'
elif unit == 'w':
unit = 'weeks'
elif unit == 's':
unit = 'years'
num *= 52
return timedelta(**{TIME_DICT[unit][0]: num})
return timedelta(**{unit: num})
def parse_int(val: str, select: bool = True) -> tuple:

View File

@ -1,4 +1,5 @@
irc3==1.0.0
#irc3==1.0.0
git+https://github.com/gawel/irc3.git
aiocron==0.6
requests==2.14.2
python_dotenv==0.6.4