diff options
| author | Arslaan Pathan <[email protected]> | 2026-07-16 22:43:19 +1200 |
|---|---|---|
| committer | Arslaan Pathan <[email protected]> | 2026-07-16 22:43:19 +1200 |
| commit | bc715b12204714dc8046f07387210852026b47b9 (patch) | |
| tree | 44416a04b5a6699263c18d342404a0ebfdb0beb4 /src | |
| parent | d9a6838624e78d90eba962b6004796fbfe1b4b8c (diff) | |
| download | slack-botnet-bc715b12204714dc8046f07387210852026b47b9.tar.xz slack-botnet-bc715b12204714dc8046f07387210852026b47b9.zip | |
Make it send to different channels
Diffstat (limited to 'src')
| -rw-r--r-- | src/botnet.py | 10 | ||||
| -rw-r--r-- | src/main.py | 6 | ||||
| -rw-r--r-- | src/utils.py | 25 |
3 files changed, 37 insertions, 4 deletions
diff --git a/src/botnet.py b/src/botnet.py index 377c0c2..225f7e9 100644 --- a/src/botnet.py +++ b/src/botnet.py @@ -1,5 +1,5 @@ from .db import create_deployment, get_daily_user_deployment_count, get_deployment, update_deployment_status, get_active_users, get_user, add_deployment_message, get_deployment_messages -from .utils import generate_voting_blocks +from .utils import generate_voting_blocks, get_random_channel from slack_sdk.web.async_client import AsyncWebClient import os from dotenv import load_dotenv @@ -122,8 +122,14 @@ async def execute_deployment(deployment_id: int): for user in users: try: client = AsyncWebClient(token=user["oauth_token"]) + channel = await get_random_channel(user["oauth_token"]) + if not channel: + print(f"No channels found for {user['slack_id']}, using #botnet") + channel_id = "C0BGMV1CAQG" + else: + channel_id = channel["id"] response = await client.chat_postMessage( - channel="C0BGMV1CAQG", # put it in #botnet for now, make it detect recent thread with CM approval yada yada later + channel=channel_id, # put it in #botnet for now, make it detect recent thread with CM approval yada yada later text=message, as_user=True ) diff --git a/src/main.py b/src/main.py index c2855c1..0d63190 100644 --- a/src/main.py +++ b/src/main.py @@ -4,7 +4,7 @@ import math 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, get_user, add_vote, get_vote_counts, get_user_vote, get_deployment, update_deployment_status +from .db import init_db, get_user, add_vote, get_vote_counts, get_user_vote, get_deployment, update_deployment_status, get_active_users from .utils import generate_voting_blocks from .auth import app as fastapi_app from .botnet import deploy_message, execute_deployment @@ -100,7 +100,9 @@ async def handle_vote(ack, respond, logger, context, body, client): active_users = await get_active_users() total_members = len(active_users) - THRESHOLD = math.ceil(max(3, min(15, int(total_members * 0.2)))) # min 3, max 15 - use 20% total members + # THRESHOLD = math.ceil(max(3, min(15, int(total_members * 0.2)))) # min 3, max 15 - use 20% total members + THRESHOLD = 2 # Debug hardcoded + print(f"DEBUG: Threshold is {THRESHOLD}") if approve_count >= THRESHOLD: await update_deployment_status(deployment_id, "approved") diff --git a/src/utils.py b/src/utils.py index 1efc693..a42539f 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,3 +1,6 @@ +import random +from slack_sdk.web.async_client import AsyncWebClient + def generate_voting_blocks(deployment_id: int, message: str, approve_count: int, reject_count: int, voting_enabled: bool): blocks = [ { @@ -43,3 +46,25 @@ def generate_voting_blocks(deployment_id: int, message: str, approve_count: int, }) return blocks + +async def get_random_channel(oauth_token: str): + client = AsyncWebClient(token=oauth_token) + + try: + response = await client.conversations_list(types="public_channel", limit=200, exclude_archived=True) + + channels = [c for c in response.get("channels", []) if c.get("is_member", False)] + + if not channels: + return None + + channel_approved = False + while not channel_approved: + channel = random.choice(channels) + # FIXME: Check if CM-approved here + channel_approved = True + + return channel + except Exception as e: + print(f"random channel is broken, we might be cooked: {e}") + return None |
