actually git-ize
This commit is contained in:
40
src-old/db.py
Normal file
40
src-old/db.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import aiosqlite
|
||||
import logging
|
||||
|
||||
migrations = [
|
||||
"""
|
||||
CREATE TABLE deleted_items (
|
||||
id INTEGER PRIMARY KEY,
|
||||
timestamp INTEGER NOT NULL,
|
||||
item TEXT NOT NULL
|
||||
);
|
||||
""",
|
||||
"""
|
||||
CREATE INDEX deleted_items_timestamps ON deleted_items(timestamp);
|
||||
""",
|
||||
"""
|
||||
CREATE TABLE reminders (
|
||||
id INTEGER PRIMARY KEY,
|
||||
remind_timestamp INTEGER NOT NULL,
|
||||
created_timestamp INTEGER NOT NULL,
|
||||
reminder TEXT NOT NULL,
|
||||
expired INTEGER NOT NULL,
|
||||
extra TEXT NOT NULL
|
||||
);
|
||||
"""
|
||||
]
|
||||
|
||||
async def init(db_path):
|
||||
db = await aiosqlite.connect(db_path)
|
||||
|
||||
version = (await (await db.execute("PRAGMA user_version")).fetchone())[0]
|
||||
for i in range(version, len(migrations)):
|
||||
await db.executescript(migrations[i])
|
||||
# Normally this would be a terrible idea because of SQL injection.
|
||||
# However, in this case there is not an obvious alternative (the parameter-based way apparently doesn't work)
|
||||
# and i + 1 will always be an integer anyway
|
||||
await db.execute(f"PRAGMA user_version = {i + 1}")
|
||||
await db.commit()
|
||||
logging.info(f"Migrated DB to schema {i + 1}")
|
||||
|
||||
return db
|
60
src-old/main.py
Normal file
60
src-old/main.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import irc.bot
|
||||
import irc.strings
|
||||
import jaraco.logging
|
||||
import hashlib
|
||||
import toml
|
||||
import ssl
|
||||
import string
|
||||
import random
|
||||
|
||||
conf = toml.load(open("config.toml"))
|
||||
|
||||
class Bot(irc.bot.SingleServerIRCBot):
|
||||
def __init__(self, servers, nick, channel):
|
||||
super().__init__(servers, nick, nick, **{"ipv6": True})
|
||||
print(dir(self))
|
||||
self.channel = channel
|
||||
|
||||
def on_nicknameinuse(self, c, e):
|
||||
c.nick("".join(random.choices(string.ascii_lowercase ,k=8)))
|
||||
print("nick in use, changing")
|
||||
|
||||
def on_welcome(self, c, e):
|
||||
c.join(self.channel)
|
||||
print("joined", self.channel)
|
||||
|
||||
def on_privmsg(self, c, e):
|
||||
self.do_command(e, e.arguments[0])
|
||||
|
||||
def on_pubmsg(self, c, e):
|
||||
a = e.arguments[0].split(":", 1)
|
||||
if len(a) > 1 and irc.strings.lower(a[0]) == irc.strings.lower(self.connection.get_nickname()):
|
||||
self.do_command(e, a[1].strip())
|
||||
return
|
||||
|
||||
def do_command(self, e, cmd):
|
||||
nick = e.source.nick
|
||||
c = self.connection
|
||||
|
||||
print("exec", nick, cmd)
|
||||
|
||||
if cmd == "stats":
|
||||
for chname, chobj in self.channels.items():
|
||||
c.notice(nick, "--- Channel statistics ---")
|
||||
c.notice(nick, "Channel: " + chname)
|
||||
users = sorted(chobj.users())
|
||||
c.notice(nick, "Users: " + ", ".join(users))
|
||||
opers = sorted(chobj.opers())
|
||||
c.notice(nick, "Opers: " + ", ".join(opers))
|
||||
voiced = sorted(chobj.voiced())
|
||||
c.notice(nick, "Voiced: " + ", ".join(voiced))
|
||||
elif cmd == "starch":
|
||||
c.notice(nick, "starch: it exists.")
|
||||
else:
|
||||
c.notice(nick, "Not understood: " + cmd)
|
||||
|
||||
if __name__ == "__main__":
|
||||
s = conf["server"]
|
||||
bot = Bot([(s["host"], s["port"])], conf["nickname"], "#a")
|
||||
|
||||
bot.start()
|
Reference in New Issue
Block a user