main.py (view raw)
1from telegram.ext import ContextTypes, MessageHandler, ApplicationBuilder, CallbackQueryHandler, filters
2from telegram import Update
3from Config import TOKEN, INLINE_SEP
4from Replacer import replace, feedback
5from Forwarder import forward, admin_forward
6
7inline_mapping = [ ("feedback", feedback) ]
8
9async def inline_keyboard(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
10 query = update.callback_query
11 data = query.data
12
13 for t in inline_mapping:
14 if data.startswith(t[0]):
15 actual_data = data.split(INLINE_SEP, maxsplit=1)[1]
16 await t[1](update, context, actual_data)
17 return
18
19 await query.answer("Questo tasto non fa nulla.")
20 return
21
22if __name__ == "__main__":
23 application = ApplicationBuilder().token(TOKEN).build()
24 application.add_handler(CallbackQueryHandler(callback=inline_keyboard))
25 application.add_handler(MessageHandler(filters.ChatType.CHANNEL, forward))
26 application.add_handler(MessageHandler(filters.ChatType.PRIVATE, admin_forward))
27 application.add_handler(MessageHandler(filters.ChatType.GROUPS, replace))
28 application.run_polling(allowed_updates=[Update.MESSAGE, Update.CALLBACK_QUERY])