diff options
Diffstat (limited to 'src/db.py')
| -rw-r--r-- | src/db.py | 32 |
1 files changed, 32 insertions, 0 deletions
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}") |
