aboutsummaryrefslogtreecommitdiff
path: root/src/main.py
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2026-07-16 19:37:14 +1200
committerArslaan Pathan <[email protected]>2026-07-16 19:37:14 +1200
commitc2a74e7472beace631fcab24986d83326e4c5dd7 (patch)
treed710c8dfb865b9f0b4377c75bac2ff5847de1923 /src/main.py
parente93169c11c848f78d0411031ae2589e9d5b1fde0 (diff)
downloadslack-botnet-c2a74e7472beace631fcab24986d83326e4c5dd7.tar.xz
slack-botnet-c2a74e7472beace631fcab24986d83326e4c5dd7.zip
Almost done with voting!!
Diffstat (limited to 'src/main.py')
-rw-r--r--src/main.py41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/main.py b/src/main.py
index 1c43240..9daa8f3 100644
--- a/src/main.py
+++ b/src/main.py
@@ -1,8 +1,9 @@
import os
+import re
from slack_bolt.app.async_app import AsyncApp
from slack_bolt.adapter.socket_mode.async_handler import AsyncSocketModeHandler
from dotenv import load_dotenv
-from .db import init_db
+from .db import init_db, get_user, add_vote, get_vote_counts
from .auth import app as fastapi_app
from .botnet import deploy_message
import threading
@@ -11,6 +12,8 @@ import uvicorn
load_dotenv()
+VOTE_PATTERN = re.compile(r"^vote_(approve|reject)_(\d+)$")
+
selfbot_token = os.environ.get("SLACK_SELFBOT_OAUTH_XOXP")
app_token = os.environ.get("SLACK_APP_TOKEN")
selfbot_user_id = os.environ.get("SELFBOT_USER_ID")
@@ -64,6 +67,42 @@ async def handle_messages(message, say):
except Exception as e:
print(f"something broke, good luck LMAO {e}")
[email protected](VOTE_PATTERN)
+async def handle_vote(ack, respond, logger, context, body, client):
+ await ack()
+
+ action_id = body["actions"][0]["action_id"]
+ match = VOTE_PATTERN.match(action_id)
+
+ if not match:
+ return
+
+ vote_type = match.group(1)
+ deployment_id = int(match.group(2))
+
+ user_id = body["user"]["id"]
+ channel_id = body["channel"]["id"]
+ user = await get_user(user_id)
+ if not user:
+ # await respond(f"You must join the botnet first!", response_type="ephemeral")
+ await client.chat_postEphemeral(channel=channel_id, user=user_id, text="You must join the botnet first!")
+ return
+
+ # await respond("Not implemented yet", response_type="ephemeral")
+ # await client.chat_postEphemeral(channel=channel_id, user=user_id, text="Not implemented yet")
+
+ existing_vote = await get_user_vote(deployment_id, user_id)
+ if existing_vote:
+ await client.chat_postEphemeral(channel=channel_id, user=user_id, text=f"You already voted {existing_vote} on this deployment!")
+
+ await add_vote(deployment, user_id, vote_type)
+
+ approve_count, reject_count = await get_vote_counts(deployment_id)
+
+ THRESHOLD = 3 # FIXME: DYNAMICALLY CALCULATE THIS!!
+ deployment = await get_deployment(deployment_id)
+
+
@app.event("message")
async def shut_up_slack_bolt():
# shut up that annoying debug warning that this event is unhandled