Removing previous code, adding register and cancelRegister buttons with DM replies
This commit is contained in:
+24
-51
@@ -1,56 +1,29 @@
|
||||
from telegram import Update
|
||||
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
|
||||
import configparser
|
||||
import json
|
||||
import os
|
||||
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
|
||||
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes, Updater, CallbackQueryHandler, CallbackContext
|
||||
|
||||
# /anmeldung Handler
|
||||
async def anmeldung(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
if not context.args:
|
||||
await update.message.reply_text("Bitte Namen angeben: /anmeldung Name")
|
||||
return
|
||||
name = " ".join(context.args)
|
||||
if name in event_list:
|
||||
await update.message.reply_text(f"{name}, du bist doch schon angemeldet.")
|
||||
else:
|
||||
event_list.append(name)
|
||||
save_list()
|
||||
await update.message.reply_text(f"{name} will unbedingt auch dabei sein!")
|
||||
|
||||
# /abmeldung Handler
|
||||
async def abmeldung(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
if not context.args:
|
||||
await update.message.reply_text("Bitte Namen angeben: /abmeldung Name")
|
||||
return
|
||||
name = " ".join(context.args)
|
||||
if name in event_list:
|
||||
event_list.remove(name)
|
||||
save_list()
|
||||
await update.message.reply_text(f"{name} kann nich mehr oder hat kein Bock auf uns.")
|
||||
else:
|
||||
await update.message.reply_text(f"{name}, du warst eh nich auf der Liste.")
|
||||
# Function to handle button clicks (callback queries)
|
||||
async def button(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
query = update.callback_query
|
||||
|
||||
# /hilfe Handler
|
||||
async def hilfe(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
text = (
|
||||
"Dude, ich erklär dir mal wie das hier läuft:\n\n"
|
||||
"In der Gruppe:\n"
|
||||
"/anmeldung Name - zum Anmelden\n"
|
||||
"/abmeldung Name - zum Abmelden\n"
|
||||
"/status - check wie viele Fussel dabei sind\n\n"
|
||||
)
|
||||
await update.message.reply_text(text)
|
||||
user = query.from_user
|
||||
|
||||
await query.answer() # Acknowledge the button press
|
||||
|
||||
if query.data == 'register':
|
||||
try:
|
||||
keyboard = [[InlineKeyboardButton("Abmelden", callback_data='cancelRegister')]]
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
await context.bot.send_message(user.id, "Registered", reply_markup=reply_markup)
|
||||
except Exception as e:
|
||||
await context.bot.send_message(query.message.chat_id, f"@{user.username} Leider kam es zu einem Fehler: {str(e)}")
|
||||
|
||||
if query.data == 'cancelRegister':
|
||||
try:
|
||||
await context.bot.send_message(user.id, "Cancelled")
|
||||
except Exception as e:
|
||||
await context.bot.send_message(query.message.chat_id, f"@{user.username} Leider kam es zu einem Fehler: {str(e)}")
|
||||
|
||||
return
|
||||
|
||||
# /status Handler (für alle)
|
||||
async def status(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
count = len(event_list)
|
||||
if count == 0:
|
||||
text = "Is noch keiner eingecheckt..."
|
||||
elif count == 1:
|
||||
text = "Es ist aktuell *1 Fussel* dabei!"
|
||||
else:
|
||||
text = f"Es sind aktuell *{count} Fussel* dabei!"
|
||||
await update.message.reply_text(text, parse_mode="Markdown")
|
||||
|
||||
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
await hilfe(update, context)
|
||||
|
||||
Reference in New Issue
Block a user