Removing previous code, adding register and cancelRegister buttons with DM replies
This commit is contained in:
+10
-40
@@ -1,4 +1,4 @@
|
||||
from telegram import Update
|
||||
from telegram import Bot, InlineKeyboardButton, InlineKeyboardMarkup, Update
|
||||
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
|
||||
import configparser
|
||||
import json
|
||||
@@ -6,45 +6,15 @@ import os
|
||||
import datetime
|
||||
import shutil
|
||||
|
||||
# /liste Handler (nur privat für Admins)
|
||||
async def liste(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
if update.effective_user.id not in config['admin']['ids']:
|
||||
await update.message.reply_text("Epic fail, kein Zugriff für dich")
|
||||
return
|
||||
# Function to send a message with inline buttons
|
||||
async def newEvent(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
keyboard = [
|
||||
[InlineKeyboardButton("Anmelden", callback_data='register')],
|
||||
[InlineKeyboardButton("Abmelden", callback_data='cancelRegister')]
|
||||
]
|
||||
|
||||
if event_list:
|
||||
antwort = "*Aktuelle Anmeldungen:*\n\n"
|
||||
for i, name in enumerate(event_list, start=1):
|
||||
antwort += f"{i}. {name}\n"
|
||||
antwort += f"\n Insgesamt angemeldet: *{len(event_list)}*"
|
||||
await update.message.reply_text(
|
||||
antwort, parse_mode="Markdown"
|
||||
)
|
||||
else:
|
||||
await update.message.reply_text("Chill, es is noch gar keiner angemeldet.")
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
|
||||
# /reset Handler (nur privat für Admins, mit Archivierung)
|
||||
async def reset(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
if update.effective_user.id not in config['admin']['ids']:
|
||||
await update.message.reply_text("Epic fail, Zugriff verweigert")
|
||||
return
|
||||
await update.message.reply_text("choose below", reply_markup=reply_markup)
|
||||
return
|
||||
|
||||
# Nur archivieren, wenn es überhaupt etwas gibt
|
||||
if event_list:
|
||||
timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
||||
backup_file = f"event_list_{timestamp}.json"
|
||||
try:
|
||||
shutil.copy(list_file, backup_file)
|
||||
await update.message.reply_text(
|
||||
f"Ich hab die Liste mal gespeichert, falls du sie aus Versehen resettet hast, liegt jetz unter:\n`{backup_file}`",
|
||||
parse_mode="Markdown"
|
||||
)
|
||||
except Exception as e:
|
||||
await update.message.reply_text(f"Fehler beim Sichern: {e}")
|
||||
else:
|
||||
await update.message.reply_text("Liste ist leer, nichts zu sichern")
|
||||
|
||||
# Liste zurücksetzen (neue, leere Liste)
|
||||
event_list.clear()
|
||||
save_list()
|
||||
await update.message.reply_text("WOOOSH! Und die Liste is wieder leer.")
|
||||
Reference in New Issue
Block a user