diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/botnet.py | 69 | ||||
| -rw-r--r-- | src/db.py | 39 |
2 files changed, 103 insertions, 5 deletions
diff --git a/src/botnet.py b/src/botnet.py index fbf8efe..086d01f 100644 --- a/src/botnet.py +++ b/src/botnet.py @@ -13,9 +13,11 @@ selfbot_token = os.environ.get("SLACK_SELFBOT_OAUTH_XOXP") gemini_key = os.environ.get("GEMINI_API_KEY") system_prompt = """ -You are a strict content moderator for a professional Slack workspace called Hack Club. +You are a strict content moderator for a botnet-like social experiment in a professional Slack workspace called Hack Club. -Your job is to analyze messages and determine if they are SAFE or UNSAFE to be posted by a bot on behalf of multiple users. +Your job is to analyze messages and determine if they are SAFE or UNSAFE to be posted by a bot on behalf of multiple users in the Slack. +Messages will be posted on behalf of MANY USERS simultaneously. +The message must make sense coming from ANYONE, not just the submitter. A message is UNSAFE if it contains ANY of the following: - Swear words, profanity, or offensive language @@ -25,6 +27,13 @@ A message is UNSAFE if it contains ANY of the following: - Spam, excessive gibberish, or repetitive messages - Phishing, scams, or malicious links - Mentions of illegal activities (hacking, drugs, violence, etc.) +- Self-promotion, advertising, or promotional content +- Links to personal websites, products, or services +- Strong opinions or polarizing statements (politics, religion, software, licensing, etc.) +- Tech flame wars (X is better than Y, Z sucks, etc.) +- Negative statements about people, projects, or technologies +- Complaints or rants about specific tools, languages, or frameworks +- Anything that could be interpreted as speaking for others in a controversial way - Anything that would make Slack admins (FD/Fire Dept.) upset or require them to intervene A message is SAFE if it is: @@ -81,13 +90,63 @@ async def deploy_message(user_id: str, message: str): deployment_id = await create_deployment(user_id, message) - print(f"DEBUG: Executing the deployment {deployment_id} on arrival - REMOVE THIS LATER!") - await execute_deployment(deployment_id) + blocks = [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": f"Voting | Deployment #{deployment_id}" + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": f"*Message:*\n> {message}" + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": f"*Votes:*\n> Approve: 0\n> Reject: 0" + } + }, + { + "type": "actions", + "elements": [ + { + "type": "button", + "text": {"type": "plain_text", "text": "Approve ^_^"}, + "style": "primary", + "action_id": f"vote_approve_{deployment_id}" + }, + { + "type": "button", + "text": {"type": "plain_text", "text": "Reject T_T"}, + "style": "danger", + "action_id": f"vote_reject_{deployment_id}" + } + ] + } + ] + + client = AsyncWebClient(token=selfbot_token) + response = await client.chat_postMessage( + channel="C0BFEDTUFCP", + blocks=blocks, + text=f"Vote on Deployment #deployment_id" + ) + + message_ts = response["ts"] + + # print(f"DEBUG: Executing the deployment {deployment_id} on arrival - REMOVE THIS LATER!") + # await execute_deployment(deployment_id) return { "success": True, "deployment_id": deployment_id, - "message": "Your message has been deployed!" + "message": "Your message has been submitted for voting!" } async def execute_deployment(deployment_id: int): @@ -31,10 +31,22 @@ async def init_db(): message_id TEXT NOT NULL, channel_id TEXT NOT NULL, sent_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + voting_message_ts TEXT, FOREIGN KEY (deployment_id) REFERENCES Deployments(id) ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES Users(slack_id) ) """) + await db.execute(""" + CREATE TABLE IF NOT EXISTS Votes ( + deployment_id INTEGER NOT NULL, + voter_id TEXT NOT NULL, + vote TEXT NOT NULL, + voted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (deployment_id) REFERENCES Deployments(id) ON DELETE CASCADE, + FOREIGN KEY (voter_id) REFERENCES Users(slack_id) + PRIMARY KEY (deployment_id, voter_id) + ) + """) await db.commit() async def add_user(slack_id: str, oauth_token: str): @@ -129,3 +141,30 @@ async def get_active_users() -> list[dict]: cursor = await db.execute("SELECT * FROM Users") rows = await cursor.fetchall() return [dict(row) for row in rows] + + +async def add_vote(deployment_id: int, voter_id: str, vote: str): + async with aiosqlite.connect(DB_PATH) as db: + await db.execute("INSERT OR REPLACE INTO Votes (deployment_id, voter_id, vote) VALUES (?, ?, ?)", (deployment_id, voter_id, vote)) + await db.commit() + +async def get_votes(deployment_id: int): + async with aiosqlite.connect(DB_PATH) as db: + db.row_factory = aiosqlite.Row + cursor = await db.execute("SELECT voter_id, vote FROM Votes WHERE deployment_id = ?", (deployment_id,)) + rows = await cursor.fetchall() + + votes = {"approve": [], "reject": []} + for row in rows: + votes[row["vote"]].append(row["voter_id"]) + return votes + +async def get_user_vote(deployment_id: int, voter_id: str): + async with aiosqlite.connect(DB_PATH) as db: + cursor = await db.execute("SELECT vote from Votes WHERE deployment_id = ? AND voter_id = ?", (deployment_id, voter_id)) + row = await cursor.fetchone() + return row[0] if row else None + +async def get_vote_counts(deployment_id: int): + votes = await get_votes(deployment_id) + return len(votes["approve"]), len(votes["reject"]) |
