diff options
| author | Arslaan Pathan <[email protected]> | 2026-07-17 00:03:03 +1200 |
|---|---|---|
| committer | Arslaan Pathan <[email protected]> | 2026-07-17 00:03:03 +1200 |
| commit | 2eb0e1197b40c07de4a57701504f77345d77dc36 (patch) | |
| tree | 53e6fe85f9ce6be91ab0cddc9a1dfb44969d35af /src/db.py | |
| parent | bc715b12204714dc8046f07387210852026b47b9 (diff) | |
| download | slack-botnet-2eb0e1197b40c07de4a57701504f77345d77dc36.tar.xz slack-botnet-2eb0e1197b40c07de4a57701504f77345d77dc36.zip | |
IT WORKS YES YES YES IM SAVED
Diffstat (limited to 'src/db.py')
| -rw-r--r-- | src/db.py | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -47,6 +47,14 @@ async def init_db(): PRIMARY KEY (deployment_id, voter_id) ) """) + await db.execute(""" + CREATE TABLE IF NOT EXISTS ChannelApprovals ( + channel_id TEXT PRIMARY KEY, + approved_by TEXT NOT NULL, + approved_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (approved_by) REFERENCES Users(slack_id) + ) + """) await db.commit() async def add_user(slack_id: str, oauth_token: str): @@ -175,3 +183,34 @@ async def update_voting_message_ts(deployment_id: int, message_ts: str): (message_ts, deployment_id) ) await db.commit() + +async def approve_channel(channel_id: str, approver_id: str): + async with aiosqlite.connect(DB_PATH) as db: + await db.execute( + "INSERT OR REPLACE INTO ChannelApprovals (channel_id, approved_by) VALUES (?, ?)", + (channel_id, approver_id) + ) + await db.commit() + +async def is_channel_approved(channel_id: str) -> bool: + async with aiosqlite.connect(DB_PATH) as db: + cursor = await db.execute( + "SELECT channel_id FROM ChannelApprovals WHERE channel_id = ?", + (channel_id,) + ) + row = await cursor.fetchone() + return row is not None + +async def get_approved_channels() -> list[str]: + async with aiosqlite.connect(DB_PATH) as db: + cursor = await db.execute("SELECT channel_id FROM ChannelApprovals") + rows = await cursor.fetchall() + return [row[0] for row in rows] + +async def revoke_channel_approval(channel_id: str): + async with aiosqlite.connect(DB_PATH) as db: + await db.execute( + "DELETE FROM ChannelApprovals WHERE channel_id = ?", + (channel_id,) + ) + await db.commit() |
