eee
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
from telegram import Update
|
||||
from telegram.ext import (
|
||||
Application,
|
||||
CommandHandler,
|
||||
MessageHandler,
|
||||
filters,
|
||||
ContextTypes,
|
||||
)
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
from utils import get_hashed_id, user_is_limited
|
||||
from commands import start, healthcheck
|
||||
|
||||
load_dotenv()
|
||||
TOKEN = os.getenv("BOT_TOKEN")
|
||||
CHANNEL_ID = int(os.getenv("CHANNEL_ID"))
|
||||
|
||||
|
||||
async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
user_id = str(update.effective_user.id)
|
||||
hashed_id = get_hashed_id(user_id)
|
||||
if user_is_limited(hashed_id):
|
||||
await update.message.reply_text("You are timed out. Please try again later.")
|
||||
return
|
||||
|
||||
message = update.message.text.strip()
|
||||
await context.bot.send_message(chat_id=CHANNEL_ID, text=message)
|
||||
await update.message.reply_text("Your message has been posted!")
|
||||
|
||||
|
||||
def main():
|
||||
app = Application.builder().token(TOKEN).build()
|
||||
app.add_handler(CommandHandler("start", start))
|
||||
app.add_handler(CommandHandler("health", healthcheck))
|
||||
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message))
|
||||
print("Bot is running!")
|
||||
app.run_polling()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user