Some refactoring, pgsql follows...soon™
This commit is contained in:
parent
e69307283d
commit
d1911ca4f2
@ -19,7 +19,15 @@ class Plugin(BasePlugin):
|
||||
|
||||
|
||||
class DatabasePlugin(Plugin):
|
||||
# @property
|
||||
# def con(self):
|
||||
# return self.bot.con
|
||||
#
|
||||
# @property
|
||||
# def cur(self):
|
||||
# return self.bot.cur
|
||||
|
||||
def __init__(self, bot):
|
||||
super().__init__(bot)
|
||||
self.con = bot.con.db
|
||||
self.cur = self.con.cursor()
|
||||
self.cur = bot.con.cur
|
||||
|
@ -9,7 +9,7 @@ from . import MODULE, Plugin
|
||||
|
||||
|
||||
@command(permission='admin', show_in_help_list=False)
|
||||
def reload(bot: irc3.IrcBot, mask: IrcString, channel: IrcString,
|
||||
def reload(bot: irc3.IrcBot, mask: IrcString, target: IrcString,
|
||||
args: DocoptDict):
|
||||
"""Reloads a plugin or the whole bot
|
||||
|
||||
@ -18,10 +18,10 @@ def reload(bot: irc3.IrcBot, mask: IrcString, channel: IrcString,
|
||||
plugin = args.get('<plugin>')
|
||||
if plugin:
|
||||
bot.reload('{module}.{plugin}'.format(plugin=plugin, module=MODULE))
|
||||
bot.privmsg(channel, 'Reloaded plugin "{}"'.format(plugin))
|
||||
bot.privmsg(target, 'Reloaded plugin "{}"'.format(plugin))
|
||||
else:
|
||||
bot.reload()
|
||||
bot.privmsg(channel, 'Reloaded the bot')
|
||||
bot.privmsg(target, 'Reloaded the bot')
|
||||
|
||||
|
||||
@irc3.plugin
|
||||
|
@ -14,7 +14,7 @@ class Coins(Plugin):
|
||||
requires = ['irc3.plugins.command']
|
||||
|
||||
@command
|
||||
def btc(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def btc(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Gets the Bitcoin values from BitStamp.
|
||||
|
||||
%%btc
|
||||
@ -28,7 +28,7 @@ class Coins(Plugin):
|
||||
'Volume: \x02฿{volume:,.2f}\x02'.format(**values)
|
||||
|
||||
@command
|
||||
def eth(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def eth(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Gets the Ethereum values from etherscan.io.
|
||||
|
||||
%%eth
|
||||
|
@ -37,7 +37,7 @@ class CTCP(Plugin):
|
||||
return self._ctcp(name, nick, reply)
|
||||
|
||||
@command
|
||||
async def ping(self, mask: IrcString, channel: IrcString,
|
||||
async def ping(self, mask: IrcString, target: IrcString,
|
||||
args: DocOptDict):
|
||||
"""Sends ping via CTCP to user and sends the time needed
|
||||
|
||||
@ -62,7 +62,7 @@ class CTCP(Plugin):
|
||||
return self._ctcp('PING', nick, reply)
|
||||
|
||||
@command
|
||||
async def finger(self, mask: IrcString, channel: IrcString,
|
||||
async def finger(self, mask: IrcString, target: IrcString,
|
||||
args: DocOptDict):
|
||||
"""Gets the client response for finger nick user via CTCP
|
||||
|
||||
@ -71,7 +71,7 @@ class CTCP(Plugin):
|
||||
return await self.ctcp('FINGER', mask, args)
|
||||
|
||||
@command
|
||||
async def time(self, mask: IrcString, channel: IrcString,
|
||||
async def time(self, mask: IrcString, target: IrcString,
|
||||
args: DocOptDict):
|
||||
"""Gets the client time from nick via CTCP
|
||||
|
||||
@ -80,7 +80,7 @@ class CTCP(Plugin):
|
||||
return await self.ctcp('TIME', mask, args)
|
||||
|
||||
@command
|
||||
async def ver(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
async def ver(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Gets the client version from nick via CTCP
|
||||
|
||||
%%ver [<nick>]
|
||||
|
@ -1,7 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
import irc3
|
||||
import psycopg2
|
||||
from psycopg2.extras import DictCursor
|
||||
|
||||
from . import Plugin
|
||||
|
||||
@ -10,13 +12,6 @@ from . import Plugin
|
||||
class Database(Plugin):
|
||||
def __init__(self, bot: irc3.IrcBot):
|
||||
super().__init__(bot)
|
||||
file = bot.config.storage.split('sqlite://', 1)[1]
|
||||
if not file:
|
||||
raise ValueError('Invalid database: {}'.format(bot.config.storage))
|
||||
# @formatter:off
|
||||
self.db = sqlite3.connect(file, detect_types=sqlite3.PARSE_DECLTYPES
|
||||
| sqlite3.PARSE_COLNAMES)
|
||||
# @formatter:on
|
||||
self.db.row_factory = sqlite3.Row
|
||||
self.bot = bot
|
||||
self.db = psycopg2.connect(os.environ['DATABASE_URI'])
|
||||
self.cur = self.db.cursor(cursor_factory=DictCursor)
|
||||
self.bot.con = self
|
||||
|
@ -21,19 +21,19 @@ GNU_LINUX = """I'd Just Like To Interject For A Moment. What you're referring
|
||||
class Linux(Plugin):
|
||||
KERNEL_FEED = 'https://www.kernel.org/feeds/kdist.xml'
|
||||
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<channel>\S+) :.*(debian|apt|dpkg).*')
|
||||
def debillian(self, channel: str):
|
||||
if random.randint(0, 3) is 0:
|
||||
self.bot.privmsg(channel, 'REEEEEEEEEEEEEEEEEEEEEEEEEEEEE')
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :.*(debian|apt|dpkg).*')
|
||||
def debillian(self, target: str):
|
||||
if random.randint(0, 12) is 0:
|
||||
self.bot.privmsg(target, 'REEEEEEEEEEEEEEEEEEEEEEEEEEEEE')
|
||||
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<channel>\S+) :'
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :'
|
||||
r'.*(?<!gnu[/+])linux(?! kernel).*')
|
||||
def linux(self, channel: str):
|
||||
if random.randint(0, 3) is 0:
|
||||
self.bot.privmsg(channel, GNU_LINUX)
|
||||
def linux(self, target: str):
|
||||
if random.randint(0, 12) is 0:
|
||||
self.bot.privmsg(target, GNU_LINUX)
|
||||
|
||||
@command
|
||||
def kernel(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def kernel(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Get Linux kernel releases.
|
||||
|
||||
%%kernel
|
||||
|
@ -16,7 +16,7 @@ class Urban(Plugin):
|
||||
URL = 'https://api.urbandictionary.com/v0/define'
|
||||
|
||||
@command
|
||||
def ud(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def ud(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Searches for a term on YouTube and returns first result.
|
||||
|
||||
%%ud <term>...
|
||||
|
@ -16,39 +16,39 @@ RAINBOW_LEN = len(RAINBOW)
|
||||
class Useless(Plugin):
|
||||
requires = ['irc3.plugins.command']
|
||||
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<channel>\S+) :(?P<msg>huehuehue)$')
|
||||
def huehuehue(self, channel: str, msg: str):
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :(?P<msg>huehuehue)$')
|
||||
def huehuehue(self, target: str, msg: str):
|
||||
"""Returns a huehuehue when someone writes it."""
|
||||
self.bot.privmsg(channel, msg)
|
||||
self.bot.privmsg(target, msg)
|
||||
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<channel>\S+) :reeeeee$')
|
||||
def reeeeee(self, channel: str):
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :reeeeee$')
|
||||
def reeeeee(self, target: str):
|
||||
"""Returns a REEEE."""
|
||||
self.bot.privmsg(channel, 'REEEEEEEEEEEEEEEEEEEEEEEEEEEE')
|
||||
self.bot.privmsg(target, 'REEEEEEEEEEEEEEEEEEEEEEEEEEEE')
|
||||
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<channel>\S+) :same$')
|
||||
def same(self, channel: str):
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :same$')
|
||||
def same(self, target: str):
|
||||
"""Returns a plain same when a user writes same."""
|
||||
self.bot.privmsg(channel, 'same')
|
||||
self.bot.privmsg(target, 'same')
|
||||
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<channel>\S+) :\[(?P<msg>.*)\]$')
|
||||
def intensifies(self, channel: str, msg: str):
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :\[(?P<msg>.*)\]$')
|
||||
def intensifies(self, target: str, msg: str):
|
||||
"""String with brackets around will be returned with INTENSIFIES."""
|
||||
self.bot.privmsg(channel, '\x02[{msg} INTENSIFIES]'.format(
|
||||
self.bot.privmsg(target, '\x02[{msg} INTENSIFIES]'.format(
|
||||
msg=msg.upper()))
|
||||
|
||||
@command
|
||||
def storyofpomfface(self, mask: IrcString, channel: IrcString,
|
||||
def storyofpomfface(self, mask: IrcString, target: IrcString,
|
||||
args: DocOptDict):
|
||||
"""Story of pomf face.
|
||||
|
||||
%%storyofpomfface
|
||||
"""
|
||||
for face in (':O C==3', ':OC==3', ':C==3', ':C=3', ':C3', ':3'):
|
||||
self.bot.privmsg(channel, face)
|
||||
self.bot.privmsg(target, face)
|
||||
|
||||
@command
|
||||
def choose(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def choose(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Decides between items separated by comma.
|
||||
|
||||
%%choose <items>...
|
||||
@ -58,7 +58,7 @@ class Useless(Plugin):
|
||||
choice=choice.strip())
|
||||
|
||||
@command
|
||||
def jn(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def jn(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Decides between yes and no (for a question).
|
||||
|
||||
%%jn <question>
|
||||
@ -69,7 +69,7 @@ class Useless(Plugin):
|
||||
choice=choice)
|
||||
|
||||
@command
|
||||
def kiss(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def kiss(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Kisses a user.
|
||||
|
||||
%%kiss <nick>
|
||||
@ -78,7 +78,7 @@ class Useless(Plugin):
|
||||
nick=args['<nick>'])
|
||||
|
||||
@command
|
||||
def hug(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def hug(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Hugs a user.
|
||||
|
||||
%%hug <nick>
|
||||
@ -86,42 +86,42 @@ class Useless(Plugin):
|
||||
return '\x034♥♡❤♡♥\x03 {nick} \x034♥♡❤♡♥'.format(nick=args['<nick>'])
|
||||
|
||||
@command
|
||||
def bier(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def bier(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Gives nick a beer.
|
||||
|
||||
%%bier [<nick>]
|
||||
"""
|
||||
self.bot.action(channel, 'schenkt ein kühles blondes an {nick} aus.'
|
||||
self.bot.action(target, 'schenkt ein kühles blondes an {nick} aus.'
|
||||
.format(nick=args.get('<nick>') or mask.nick))
|
||||
|
||||
@command
|
||||
def fucken(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def fucken(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Kills and fucks a nick.
|
||||
|
||||
%%fucken [<nick>]
|
||||
"""
|
||||
self.bot.action(channel, 'fuckt {nick} und tötet {nick} anschließend.'
|
||||
self.bot.action(target, 'fuckt {nick} und tötet {nick} anschließend.'
|
||||
.format(nick=args.get('<nick>') or mask.nick))
|
||||
|
||||
@command
|
||||
def anhero(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def anhero(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Kicks a nick.
|
||||
|
||||
%%anhero
|
||||
"""
|
||||
self.bot.privmsg(channel, 'Sayonara bonzai-chan...')
|
||||
self.bot.kick(channel, mask.nick)
|
||||
self.bot.privmsg(target, 'Sayonara bonzai-chan...')
|
||||
self.bot.kick(target, mask.nick)
|
||||
|
||||
@command
|
||||
def sudoku(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def sudoku(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Kicks a nick.
|
||||
|
||||
%%sudoku
|
||||
"""
|
||||
self.anhero(mask, channel, args)
|
||||
self.anhero(mask, target, args)
|
||||
|
||||
@command
|
||||
def hack(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def hack(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Hacks (a user).
|
||||
|
||||
%%hack [<nick>]
|
||||
@ -130,15 +130,15 @@ class Useless(Plugin):
|
||||
return 'hacking{nick}...'.format(nick=' %s' % nick if nick else '')
|
||||
|
||||
@command
|
||||
def gay(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def gay(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Make someone gay (alias to rainbow)
|
||||
|
||||
%%gay <word>...
|
||||
"""
|
||||
return self.rainbow(mask, channel, args)
|
||||
return self.rainbow(mask, target, args)
|
||||
|
||||
@command
|
||||
def rainbow(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def rainbow(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Colorize a word in rainbow colors.
|
||||
|
||||
%%rainbow <word>...
|
||||
@ -153,7 +153,7 @@ class Useless(Plugin):
|
||||
return ''.join(word)
|
||||
|
||||
@command
|
||||
def wrainbow(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def wrainbow(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Colorize words in a sentence with rainbow colors.
|
||||
|
||||
%%wrainbow <words>...
|
||||
|
@ -18,7 +18,7 @@ class Weather(Plugin):
|
||||
'(select woeid from geo.places(1) where text="{}")'
|
||||
|
||||
@command
|
||||
def weather(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def weather(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Gets the weather from Yahoo weather API.
|
||||
|
||||
%%weather <location>...
|
||||
|
@ -12,7 +12,6 @@ from . import Plugin
|
||||
from ..utils import date_from_iso
|
||||
|
||||
|
||||
# TODO: write better code lol
|
||||
@irc3.plugin
|
||||
class YouTube(Plugin):
|
||||
requires = ['irc3.plugins.command']
|
||||
@ -61,7 +60,7 @@ class YouTube(Plugin):
|
||||
self.bot.privmsg(target, data)
|
||||
|
||||
@command
|
||||
def yt(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||
def yt(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
"""Searches for query on YouTube and returns first result.
|
||||
|
||||
%%yt <query>...
|
||||
|
2
repl.py
2
repl.py
@ -5,9 +5,9 @@ import os
|
||||
import re
|
||||
|
||||
from pprint import pprint
|
||||
# noinspection PyPackageRequirements
|
||||
from dotenv import load_dotenv
|
||||
|
||||
pp = pprint
|
||||
|
||||
load_dotenv('.env')
|
||||
|
||||
|
@ -3,3 +3,4 @@ aiocron==0.6
|
||||
requests==2.14.2
|
||||
feedparser==5.2.1
|
||||
python_dotenv==0.6.4
|
||||
psycopg2==2.7.1
|
||||
|
58
schema.sql
58
schema.sql
@ -1,47 +1,47 @@
|
||||
create table if not exists quotes (
|
||||
id integer primary key autoincrement,
|
||||
nick text not null collate nocase,
|
||||
item text not null collate nocase,
|
||||
id serial primary key,
|
||||
nick varchar(30) not null,
|
||||
item text not null,
|
||||
unique (nick, item)
|
||||
);
|
||||
|
||||
create table if not exists mcmaniacs (
|
||||
id integer primary key autoincrement,
|
||||
item text not null collate nocase,
|
||||
unique (item) on conflict replace
|
||||
id serial primary key,
|
||||
item text not null,
|
||||
unique (item)
|
||||
);
|
||||
|
||||
create table if not exists timers (
|
||||
id integer primary key autoincrement,
|
||||
mask text not null,
|
||||
channel text not null,
|
||||
message text not null,
|
||||
delay text not null,
|
||||
until timestamp not null,
|
||||
created timestamp not null default current_timestamp
|
||||
id serial primary key,
|
||||
nick varchar(30) not null,
|
||||
channel varchar(32) not null,
|
||||
message text not null,
|
||||
delay varchar(10) not null,
|
||||
ends_at timestamp not null,
|
||||
created_at timestamp not null default current_timestamp
|
||||
);
|
||||
|
||||
create table if not exists tells (
|
||||
id integer primary key autoincrement,
|
||||
from_user text not null,
|
||||
to_user text not null,
|
||||
message text not null,
|
||||
created timestamp not null default current_timestamp,
|
||||
unique (to_user, message)
|
||||
id serial primary key,
|
||||
from_nick varchar(30) not null,
|
||||
to_nick varchar(30) not null,
|
||||
message text not null,
|
||||
created_at timestamp not null default current_timestamp,
|
||||
unique (to_nick, message)
|
||||
);
|
||||
|
||||
create table if not exists seens (
|
||||
id integer primary key autoincrement,
|
||||
nick text not null collate nocase,
|
||||
channel text not null collate nocase,
|
||||
message text not null,
|
||||
last_seen timestamp not null,
|
||||
unique (nick) on conflict replace
|
||||
id serial primary key,
|
||||
nick varchar(30) not null,
|
||||
channel varchar(32) not null,
|
||||
message text not null,
|
||||
seen_at timestamp not null,
|
||||
unique (nick)
|
||||
);
|
||||
|
||||
create table if not exists owes (
|
||||
id integer primary key autoincrement,
|
||||
nick text not null collate nocase,
|
||||
amount integer not null,
|
||||
unique (nick) on conflict ignore
|
||||
id serial primary key,
|
||||
nick varchar(30) not null,
|
||||
amount integer not null,
|
||||
unique (nick)
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user