File size: 964 Bytes
068c61e
f2d2064
068c61e
f2d2064
 
 
068c61e
f2d2064
068c61e
 
f2d2064
068c61e
 
 
 
f2d2064
068c61e
 
 
 
 
 
 
 
 
 
 
 
f2d2064
068c61e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from fastapi import FastAPI
from pydantic import BaseModel
import re

app = FastAPI()

class CommandInput(BaseModel):
    message: str
    user_id: int  # the person who sent the command
    chat_id: int  # the chat where the command was used

@app.post("/command")
def handle_command(data: CommandInput):
    message = data.message.strip().lower()
    response = "Unknown command."

    if message.startswith("/ban"):
        match = re.search(r"@?(\w+)", message)
        if match:
            target = match.group(1)
            response = f"User @{target} has been banned in chat {data.chat_id}."
    elif message.startswith("/mute"):
        match = re.search(r"@?(\w+)", message)
        if match:
            target = match.group(1)
            response = f"User @{target} has been muted in chat {data.chat_id}."
    elif message.startswith("/help"):
        response = "Available commands: /ban @user, /mute @user, /help"

    return {"response": response}