Bug fixes n shit
This commit is contained in:
parent
e18bf0d23d
commit
f8bf6b6d55
|
@ -4,8 +4,7 @@
|
||||||
"port": 56791,
|
"port": 56791,
|
||||||
"ssl": true,
|
"ssl": true,
|
||||||
"raw": true,
|
"raw": true,
|
||||||
"autojoins": ["#nxy-dev"],
|
"autojoins": ["#w0bm", "#f0ck"],
|
||||||
"storage": "sqlite://db.sqlite",
|
|
||||||
"flood_burst": 1,
|
"flood_burst": 1,
|
||||||
"flood_rate": 4,
|
"flood_rate": 4,
|
||||||
"flood_rate_delay": 1,
|
"flood_rate_delay": 1,
|
||||||
|
|
|
@ -24,6 +24,7 @@ CFG_DEV = {
|
||||||
|
|
||||||
|
|
||||||
# TODO: regex
|
# TODO: regex
|
||||||
|
# TODO: ddg
|
||||||
def main(cfg_file):
|
def main(cfg_file):
|
||||||
# Load dotenv from file
|
# Load dotenv from file
|
||||||
load_dotenv('.env')
|
load_dotenv('.env')
|
||||||
|
@ -36,7 +37,7 @@ def main(cfg_file):
|
||||||
if bool(os.environ.get('DEV')):
|
if bool(os.environ.get('DEV')):
|
||||||
cfg.update(CFG_DEV)
|
cfg.update(CFG_DEV)
|
||||||
# If PASSWORD in env set it in config
|
# If PASSWORD in env set it in config
|
||||||
elif 'PASSWORD' in os.environ:
|
if 'PASSWORD' in os.environ:
|
||||||
cfg['password'] = os.environ['PASSWORD']
|
cfg['password'] = os.environ['PASSWORD']
|
||||||
|
|
||||||
# Start the bot with constructed config
|
# Start the bot with constructed config
|
||||||
|
|
|
@ -12,34 +12,56 @@ from . import Plugin
|
||||||
class Coins(Plugin):
|
class Coins(Plugin):
|
||||||
requires = ['irc3.plugins.command']
|
requires = ['irc3.plugins.command']
|
||||||
|
|
||||||
|
CRYPTOWAT = 'https://api.cryptowat.ch/markets/{market}/{crypto}{currency}' \
|
||||||
|
'/summary'
|
||||||
|
CURRENCIES = {
|
||||||
|
'usd': '$',
|
||||||
|
'eur': '€',
|
||||||
|
'eth': 'Ξ',
|
||||||
|
'btc': '฿',
|
||||||
|
}
|
||||||
|
|
||||||
@command
|
@command
|
||||||
def btc(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
def btc(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
"""Gets the Bitcoin values from BitStamp.
|
"""Gets the Bitcoin values from BitStamp.
|
||||||
|
|
||||||
%%btc
|
%%btc [<currency>]
|
||||||
"""
|
"""
|
||||||
data = requests.get('https://www.bitstamp.net/api/ticker').json()
|
return self._cryptowat_summary('btc', args.get('<currency>') or 'usd')
|
||||||
values = {k: float(data[k]) for k in ['last', 'high', 'low', 'volume']}
|
|
||||||
return '\x02[Bitcoin]\x02 ' \
|
|
||||||
'Current: \x02\x037${last:,.2f}\x0F - ' \
|
|
||||||
'High: \x02\x033${high:,.2f}\x0F - ' \
|
|
||||||
'Low: \x02\x034${low:,.2f}\x0F - ' \
|
|
||||||
'Volume: \x02฿{volume:,.2f}\x02'.format(**values)
|
|
||||||
|
|
||||||
@command
|
@command
|
||||||
def eth(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
def eth(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
"""Gets the Ethereum values from etherscan.io.
|
"""Gets the Ethereum values from etherscan.io.
|
||||||
|
|
||||||
%%eth
|
%%eth [<currency>]
|
||||||
"""
|
"""
|
||||||
volume = self._etherscan('ethsupply')
|
return self._cryptowat_summary('eth', args.get('<currency>') or 'usd')
|
||||||
data = self._etherscan('ethprice')
|
|
||||||
return '\x02[EtherScan]\x02' \
|
def _cryptowat_summary(self, crypto: str, currency: str = 'usd',
|
||||||
'\x02\x0307 ${usd:,.2f}\x0F |\x02\x0307 {btc:,.5f} BTC\x0F ' \
|
market: str = 'coinbase'):
|
||||||
'- Volume: \x02{volume:,.2f}\x02' \
|
# Check if valid currency + crypto2currency
|
||||||
.format(usd=float(data['ethusd']),
|
if currency not in self.CURRENCIES or crypto == currency:
|
||||||
btc=float(data['ethbtc']),
|
return
|
||||||
volume=float(int(volume) / 1000000000000000000))
|
|
||||||
|
# Send request to api
|
||||||
|
data = requests.get(self.CRYPTOWAT.format(market=market,
|
||||||
|
crypto=crypto,
|
||||||
|
currency=currency))
|
||||||
|
if data:
|
||||||
|
result = data.json()['result']
|
||||||
|
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 - ' \
|
||||||
|
'Change: \x02\x0307{change:,.2f}%\x0F - ' \
|
||||||
|
'Volume: \x02\x0307{volume}\x0F' \
|
||||||
|
.format(crypto=crypto.upper(),
|
||||||
|
currency=self.CURRENCIES[currency],
|
||||||
|
last=result['price']['last'],
|
||||||
|
high=result['price']['high'],
|
||||||
|
low=result['price']['low'],
|
||||||
|
change=result['price']['change']['percentage'] * 100,
|
||||||
|
volume=result['volume'])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _etherscan(action: str):
|
def _etherscan(action: str):
|
||||||
|
|
|
@ -10,28 +10,6 @@ from . import DatabasePlugin
|
||||||
from ..utils import NICK_REGEX, parse_int
|
from ..utils import NICK_REGEX, parse_int
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
delete from
|
|
||||||
quotes
|
|
||||||
where
|
|
||||||
id = (
|
|
||||||
select
|
|
||||||
id
|
|
||||||
from
|
|
||||||
quotes a
|
|
||||||
where
|
|
||||||
nick like %s and %s = (
|
|
||||||
select
|
|
||||||
count(id)
|
|
||||||
from
|
|
||||||
quotes b where a.id {op} b.id
|
|
||||||
)
|
|
||||||
order by
|
|
||||||
id {order}
|
|
||||||
)
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
@irc3.plugin
|
@irc3.plugin
|
||||||
class Quotes(DatabasePlugin):
|
class Quotes(DatabasePlugin):
|
||||||
requires = ['irc3.plugins.command',
|
requires = ['irc3.plugins.command',
|
||||||
|
@ -49,7 +27,7 @@ class Quotes(DatabasePlugin):
|
||||||
insert into
|
insert into
|
||||||
quotes (nick, item, channel, created_by)
|
quotes (nick, item, channel, created_by)
|
||||||
values
|
values
|
||||||
(%s, %s)
|
(%s, %s, %s, %s)
|
||||||
''', [nick, quote, channel, mask.nick])
|
''', [nick, quote, channel, mask.nick])
|
||||||
|
|
||||||
def delete_quote(self, nick, quote):
|
def delete_quote(self, nick, quote):
|
||||||
|
|
|
@ -61,15 +61,14 @@ class Rape(DatabasePlugin):
|
||||||
# Insert or add fine to database and return total owe
|
# Insert or add fine to database and return total owe
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
insert into
|
insert into
|
||||||
users (nick, host, fines)
|
users (nick, fines)
|
||||||
values
|
values
|
||||||
(%s, %s, %s)
|
(%s, %s, %s)
|
||||||
on conflict (nick) do update set
|
on conflict (nick) do update set
|
||||||
host = excluded.host,
|
|
||||||
fines = users.fines + excluded.fines
|
fines = users.fines + excluded.fines
|
||||||
returning
|
returning
|
||||||
fines
|
fines
|
||||||
''', [nick, mask.host, fine])
|
''', [nick, fine])
|
||||||
self.con.commit()
|
self.con.commit()
|
||||||
|
|
||||||
# Get reason based on rand value
|
# Get reason based on rand value
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import irc3
|
import irc3
|
||||||
from docopt import Dict as DocOptDict
|
from docopt import Dict as DocOptDict
|
||||||
from irc3.plugins.command import command
|
from irc3.plugins.command import command
|
||||||
|
@ -20,20 +22,19 @@ class Tell(DatabasePlugin):
|
||||||
# Fetch tells from database
|
# Fetch tells from database
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
select
|
select
|
||||||
from_nick, to_nick, message
|
to_nick, from_nick, message, created_at
|
||||||
from
|
from
|
||||||
tells
|
tells
|
||||||
''')
|
''')
|
||||||
|
|
||||||
# Add tells to queue
|
# Add tells to queue
|
||||||
for res in self.cur.fetchall():
|
for res in self.cur.fetchall():
|
||||||
nick = res['to_nick']
|
nick = res['to_nick'].lower()
|
||||||
|
|
||||||
# Create list in queue and add tell
|
# Create list in queue and add tell
|
||||||
if nick not in self.tell_queue:
|
if nick not in self.tell_queue:
|
||||||
self.tell_queue[nick] = []
|
self.tell_queue[nick] = []
|
||||||
self.tell_queue[nick].append([res['from_nick'],
|
self.tell_queue[nick].append(res[1:])
|
||||||
res['message']])
|
|
||||||
|
|
||||||
@command
|
@command
|
||||||
def tell(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
def tell(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
|
@ -41,21 +42,23 @@ class Tell(DatabasePlugin):
|
||||||
|
|
||||||
%%tell <nick> <message>...
|
%%tell <nick> <message>...
|
||||||
"""
|
"""
|
||||||
nick = args['<nick>'].lower()
|
nick = args['<nick>']
|
||||||
tell = [mask.nick.lower(), nick, ' '.join(args['<message>']).strip()]
|
nick_lower = nick.lower()
|
||||||
|
tell = [nick, mask.nick, ' '.join(args['<message>']).strip(),
|
||||||
|
datetime.now()]
|
||||||
|
|
||||||
# Create list in queue and add tell
|
# Create list in queue and add tell
|
||||||
if nick not in self.tell_queue:
|
if nick_lower not in self.tell_queue:
|
||||||
self.tell_queue[nick] = []
|
self.tell_queue[nick_lower] = []
|
||||||
self.tell_queue[nick].append(tell)
|
self.tell_queue[nick_lower].append(tell[1:])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Insert tell into database
|
# Insert tell into database
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
insert into
|
insert into
|
||||||
tells (from_nick, to_nick, message)
|
tells (to_nick, from_nick, message, created_at)
|
||||||
values
|
values
|
||||||
(%s, %s, %s)
|
(%s, %s, %s, %s)
|
||||||
''', tell)
|
''', tell)
|
||||||
self.con.commit()
|
self.con.commit()
|
||||||
except Error:
|
except Error:
|
||||||
|
@ -66,15 +69,19 @@ class Tell(DatabasePlugin):
|
||||||
def check(self, mask: str):
|
def check(self, mask: str):
|
||||||
"""If activ nick has tells, forward and delete them."""
|
"""If activ nick has tells, forward and delete them."""
|
||||||
nick = IrcString(mask).nick
|
nick = IrcString(mask).nick
|
||||||
|
nick_lower = nick.lower()
|
||||||
|
|
||||||
if nick in self.tell_queue:
|
if nick_lower in self.tell_queue:
|
||||||
# Forward all tells for nick
|
# Forward all tells for nick
|
||||||
for tell in self.tell_queue[nick]:
|
for tell in self.tell_queue[nick_lower]:
|
||||||
self.bot.privmsg(nick, '[Tell] Message from {nick}: {message}'
|
# TODO: format time
|
||||||
.format(nick=tell[0], message=tell[1]))
|
self.bot.privmsg(nick, '[Tell] Message from {nick} at {time}: '
|
||||||
|
'{message}'.format(nick=tell[0],
|
||||||
|
time=tell[2],
|
||||||
|
message=tell[1]))
|
||||||
|
|
||||||
# Remove nick from queue
|
# Remove nick from queue
|
||||||
del self.tell_queue[nick]
|
del self.tell_queue[nick_lower]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Remove tells from database
|
# Remove tells from database
|
||||||
|
@ -82,9 +89,10 @@ class Tell(DatabasePlugin):
|
||||||
delete from
|
delete from
|
||||||
tells
|
tells
|
||||||
where
|
where
|
||||||
to_nick = %s
|
lower(to_nick) = lower(%s)
|
||||||
''', [nick])
|
''', [nick])
|
||||||
self.con.commit()
|
self.con.commit()
|
||||||
except Error:
|
except Error as ex:
|
||||||
|
print(ex)
|
||||||
# Rollback transaction on error
|
# Rollback transaction on error
|
||||||
self.con.rollback()
|
self.con.rollback()
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Useless(DatabasePlugin):
|
||||||
msg=msg.upper()))
|
msg=msg.upper()))
|
||||||
|
|
||||||
@command
|
@command
|
||||||
def kill(self, mask:IrcString,target:IrcString,args:DocOptDict):
|
def kill(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
"""Kills a user with a random message.
|
"""Kills a user with a random message.
|
||||||
|
|
||||||
%%kill [<nick>]
|
%%kill [<nick>]
|
||||||
|
@ -58,7 +58,7 @@ class Useless(DatabasePlugin):
|
||||||
return self.cur.fetchone()['item'].format(nick=nick)
|
return self.cur.fetchone()['item'].format(nick=nick)
|
||||||
|
|
||||||
@command
|
@command
|
||||||
def yiff(self, mask:IrcString,target:IrcString,args:DocOptDict):
|
def yiff(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
"""Yiffs a user with a random message.
|
"""Yiffs a user with a random message.
|
||||||
|
|
||||||
%%yiff [<nick>]
|
%%yiff [<nick>]
|
||||||
|
@ -76,6 +76,82 @@ class Useless(DatabasePlugin):
|
||||||
''')
|
''')
|
||||||
return self.cur.fetchone()['item'].format(nick=nick)
|
return self.cur.fetchone()['item'].format(nick=nick)
|
||||||
|
|
||||||
|
@command
|
||||||
|
def waifu(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
|
"""Get waifu for a user.
|
||||||
|
|
||||||
|
%%waifu [<nick>]
|
||||||
|
"""
|
||||||
|
nick = args.get('<nick>') or mask.nick
|
||||||
|
|
||||||
|
if nick.startswith('='):
|
||||||
|
waifu = nick[1:]
|
||||||
|
|
||||||
|
self.cur.execute('''
|
||||||
|
insert into
|
||||||
|
users (nick, waifu)
|
||||||
|
values
|
||||||
|
(%s, %s)
|
||||||
|
on conflict (nick) do update set
|
||||||
|
waifu = excluded.waifu
|
||||||
|
''', [mask.nick, waifu])
|
||||||
|
|
||||||
|
self.bot.notice(mask.nick, 'Waifu set to: {waifu}'
|
||||||
|
.format(waifu=waifu))
|
||||||
|
else:
|
||||||
|
self.cur.execute('''
|
||||||
|
select
|
||||||
|
waifu
|
||||||
|
from
|
||||||
|
users
|
||||||
|
where
|
||||||
|
lower(nick) = lower(%s)
|
||||||
|
''', [nick])
|
||||||
|
result = self.cur.fetchone()
|
||||||
|
|
||||||
|
if result and result['waifu']:
|
||||||
|
return '\x02[Waifu]\x0F {nick}: {waifu}'.format(
|
||||||
|
nick=nick,
|
||||||
|
waifu=result['waifu'])
|
||||||
|
|
||||||
|
@command
|
||||||
|
def husbando(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
|
"""Get husbando for a user.
|
||||||
|
|
||||||
|
%%husbando [<nick>]
|
||||||
|
"""
|
||||||
|
nick = args.get('<nick>') or mask.nick
|
||||||
|
|
||||||
|
if nick.startswith('='):
|
||||||
|
husbando = nick[1:]
|
||||||
|
|
||||||
|
self.cur.execute('''
|
||||||
|
insert into
|
||||||
|
users (nick, husbando)
|
||||||
|
values
|
||||||
|
(%s, %s)
|
||||||
|
on conflict (nick) do update set
|
||||||
|
husbando = excluded.husbando
|
||||||
|
''', [mask.nick, husbando])
|
||||||
|
|
||||||
|
self.bot.notice(mask.nick, 'Husbando set to: {husbando}'
|
||||||
|
.format(husbando=husbando))
|
||||||
|
else:
|
||||||
|
self.cur.execute('''
|
||||||
|
select
|
||||||
|
husbando
|
||||||
|
from
|
||||||
|
users
|
||||||
|
where
|
||||||
|
lower(nick) = lower(%s)
|
||||||
|
''', [nick])
|
||||||
|
result = self.cur.fetchone()
|
||||||
|
|
||||||
|
if result and result['husbando']:
|
||||||
|
return '\x02[Husbando]\x0F {nick}: {husbando}'.format(
|
||||||
|
nick=nick,
|
||||||
|
husbando=result['husbando'])
|
||||||
|
|
||||||
@command
|
@command
|
||||||
def storyofpomfface(self, mask: IrcString, target: IrcString,
|
def storyofpomfface(self, mask: IrcString, target: IrcString,
|
||||||
args: DocOptDict):
|
args: DocOptDict):
|
||||||
|
|
|
@ -46,7 +46,6 @@ create table if not exists seens (
|
||||||
create table if not exists users (
|
create table if not exists users (
|
||||||
id serial primary key,
|
id serial primary key,
|
||||||
nick varchar(30) not null,
|
nick varchar(30) not null,
|
||||||
host varchar(255) not null,
|
|
||||||
husbando varchar(255) null,
|
husbando varchar(255) null,
|
||||||
waifu varchar(255) null,
|
waifu varchar(255) null,
|
||||||
fines integer default 0,
|
fines integer default 0,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user