From 2eb0e1197b40c07de4a57701504f77345d77dc36 Mon Sep 17 00:00:00 2001 From: Arslaan Pathan Date: Fri, 17 Jul 2026 00:03:03 +1200 Subject: IT WORKS YES YES YES IM SAVED --- src/db.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/db.py') diff --git a/src/db.py b/src/db.py index 3ff226e..f48960d 100644 --- a/src/db.py +++ b/src/db.py @@ -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() -- cgit v1.2.3