|
from fastapi import FastAPI |
|
from pydantic import BaseModel |
|
import re |
|
|
|
app = FastAPI() |
|
|
|
class CommandInput(BaseModel): |
|
message: str |
|
user_id: int |
|
chat_id: int |
|
|
|
@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} |