From d9499138aeaf32faee65640e624719df83f465eb Mon Sep 17 00:00:00 2001 From: Arslaan Pathan Date: Thu, 9 Jul 2026 12:49:22 +1200 Subject: Make OAuth work and send a welcome message! --- src/db.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/db.py (limited to 'src/db.py') diff --git a/src/db.py b/src/db.py new file mode 100644 index 0000000..6dd5cad --- /dev/null +++ b/src/db.py @@ -0,0 +1,32 @@ +from slack_sdk.web.async_client import AsyncWebClient +import aiosqlite + +DB_PATH = "botnet.db" + +async def init_db(): + async with aiosqlite.connect(DB_PATH) as db: + await db.execute(""" + CREATE TABLE IF NOT EXISTS Users ( + slack_id TEXT PRIMARY KEY, + oauth_token TEXT NOT NULL, + joined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ) + """) + await db.commit() + +async def add_user(slack_id: str, oauth_token: str): + async with aiosqlite.connect(DB_PATH) as db: + await db.execute( + "INSERT OR REPLACE INTO Users (slack_id, oauth_token) VALUES (?, ?)", + (slack_id, oauth_token) + ) + await db.commit() + client = AsyncWebClient(token=oauth_token) + try: + await client.chat_postMessage( + channel="C0BGMV1CAQG", + text="I've joined the botnet!", + as_user=True + ) + except Exception as e: + print(f"Failed to send welcome message: {e}") -- cgit v1.2.3