diff options
Diffstat (limited to 'src/main.py')
| -rw-r--r-- | src/main.py | 59 |
1 files changed, 50 insertions, 9 deletions
diff --git a/src/main.py b/src/main.py index 0d63190..c2980a7 100644 --- a/src/main.py +++ b/src/main.py @@ -4,8 +4,8 @@ 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, get_active_users -from .utils import generate_voting_blocks +from .db import init_db, get_user, add_vote, get_vote_counts, get_user_vote, get_deployment, update_deployment_status, get_active_users, approve_channel, is_channel_approved, revoke_channel_approval +from .utils import generate_voting_blocks, is_user_cm from .auth import app as fastapi_app from .botnet import deploy_message, execute_deployment import threading @@ -31,9 +31,9 @@ async def handle_messages(message, say): if message.get("user") == selfbot_user_id: return - if message.get("user") not in ["U0AKCBZHHMH"]: - await say("Botnet is temporarily disabled for users other than <@U0AKCBZHHMH> for debugging and the safety of all OAuth-authorized users. Please DM <@U0AKCBZHHMH> if this is not resolved within a few days.") - return + # if message.get("user") not in ["U0AKCBZHHMH"]: + # await say("Botnet is temporarily disabled for users other than <@U0AKCBZHHMH> for debugging and the safety of all OAuth-authorized users. Please DM <@U0AKCBZHHMH> if this is not resolved within a few days.") + # return text = message.get("text", "").strip() @@ -51,7 +51,7 @@ async def handle_messages(message, say): args = parts[2:] if command == "help": - await say("*Botnet Commands*:\n---\n*botnet help*: shows this message\n*botnet deploy <message>*: sends a message into the deploy queue for review/voting\n*botnet approve <channel>*: approve Botnet to function in a channel (must be CM)", mrkdwn=True) + await say("*Botnet Commands*:\n---\n*botnet help*: shows this message\n*botnet deploy <message>*: sends a message into the deploy queue for review/voting\n*botnet approve <channel>*: approve Botnet to function in a channel (must be CM)\n*botnet revoke <channel>*: revoke approval for Botnet to unction in a channel (must be CM)", mrkdwn=True) elif command == "deploy": if not args: await say("Please provide a message to deploy!") @@ -63,7 +63,49 @@ async def handle_messages(message, say): else: await say(f"T_T {result['error']}") elif command == "approve": - await say("Not implemented yet") + user_id = message.get("user") + if not args: + await say(f"Please provide a channel to approve!") + return + + channel_pattern = re.compile(r"^<#([A-Z0-9]+)(?:\|[^>]+)?>$") + match = channel_pattern.match(args[0].strip()) + channel_id = match.group(1) + + if not channel_id: + await say(f"Please provide a valid channel.") + return + + if not await is_user_cm(channel_id, user_id): + await say(f"You must be a CM of that channel to perform this action!") + return + + await approve_channel(channel_id, user_id) + await say(f"^_^ Approved channel {args[0].strip()}!") + elif command == "revoke": + user_id = message.get("user") + if not args: + await say(f"Please provide a channel to revoke approval!") + return + + channel_pattern = re.compile(r"^<#([A-Z0-9]+)(?:\|[^>]+)?>$") + match = channel_pattern.match(args[0].strip()) + channel_id = match.group(1) + + if not channel_id: + await say(f"Please provide a valid channel.") + return + + if not await is_channel_approved(channel_id): + await say(f"T_T Channel {args[0].strip()} is not currently approved for Botnet!") + return + + if not await is_user_cm(channel_id, user_id): + await say(f"You must be a CM of that channel to perform this action!") + return + + await revoke_channel_approval(channel_id) + await say(f"T_T Channel {args[0].strip()} has been revoked approval for Botnet!") else: await say(f"Unknown command: {command}") except Exception as e: @@ -100,8 +142,7 @@ 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 = 2 # Debug hardcoded + THRESHOLD = math.ceil(max(3, min(15, int(total_members * 0.2)))) # min 3, max 15 - use 20% total members print(f"DEBUG: Threshold is {THRESHOLD}") if approve_count >= THRESHOLD: |
