aboutsummaryrefslogtreecommitdiff
path: root/src/db.py
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2026-07-09 12:49:22 +1200
committerArslaan Pathan <[email protected]>2026-07-09 12:49:22 +1200
commitd9499138aeaf32faee65640e624719df83f465eb (patch)
tree7e40a70858306a86b8cde5b8e329d2033893dc71 /src/db.py
parentd9d6d7ee74781da95be8b319f84fe7f0a2ea7ee0 (diff)
downloadslack-botnet-d9499138aeaf32faee65640e624719df83f465eb.tar.xz
slack-botnet-d9499138aeaf32faee65640e624719df83f465eb.zip
Make OAuth work and send a welcome message!
Diffstat (limited to 'src/db.py')
-rw-r--r--src/db.py32
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}")