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/utils.py | |
| parent | d9a6838624e78d90eba962b6004796fbfe1b4b8c (diff) | |
| download | slack-botnet-bc715b12204714dc8046f07387210852026b47b9.tar.xz slack-botnet-bc715b12204714dc8046f07387210852026b47b9.zip | |
Make it send to different channels
Diffstat (limited to 'src/utils.py')
| -rw-r--r-- | src/utils.py | 25 |
1 files changed, 25 insertions, 0 deletions
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 |
