Chatgpt / app.py
Dragdev's picture
Update app.py
068c61e verified
raw
history blame contribute delete
964 Bytes
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}