Initial setup
This commit is contained in:
+13
-9
@@ -1,22 +1,26 @@
|
||||
from telegram import Update
|
||||
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
|
||||
import configparser
|
||||
import json
|
||||
import os
|
||||
|
||||
# Konfiguration
|
||||
ADMINS = [ID1, ID2, ID3] # Telegram-IDs der Admins
|
||||
LIST_FILE = "event_list.json"
|
||||
list_file = "event_list.json"
|
||||
config = configparser.ConfigParser()
|
||||
config.read('telegram_bot_token.cfg')
|
||||
config.read('telegram_bot_config.cfg')
|
||||
print("Configs loaded.")
|
||||
|
||||
# Lade die Liste, falls vorhanden
|
||||
if os.path.exists(LIST_FILE):
|
||||
with open(LIST_FILE, "r") as f:
|
||||
if os.path.exists(list_file):
|
||||
with open(list_file, "r") as f:
|
||||
event_list = json.load(f)
|
||||
else:
|
||||
event_list = []
|
||||
|
||||
# Hilfsfunktion zum Speichern
|
||||
def save_list():
|
||||
with open(LIST_FILE, "w") as f:
|
||||
with open(list_file, "w") as f:
|
||||
json.dump(event_list, f)
|
||||
|
||||
# /anmeldung Handler
|
||||
@@ -47,7 +51,7 @@ async def abmeldung(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
|
||||
# /liste Handler (nur privat für Admins)
|
||||
async def liste(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
if update.effective_user.id not in ADMINS:
|
||||
if update.effective_user.id not in config['admin']['ids']:
|
||||
await update.message.reply_text("Epic fail, kein Zugriff für dich")
|
||||
return
|
||||
|
||||
@@ -67,7 +71,7 @@ import datetime
|
||||
import shutil
|
||||
|
||||
async def reset(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
if update.effective_user.id not in ADMINS:
|
||||
if update.effective_user.id not in config['admin']['ids']:
|
||||
await update.message.reply_text("Epic fail, Zugriff verweigert")
|
||||
return
|
||||
|
||||
@@ -76,7 +80,7 @@ async def reset(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
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)
|
||||
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"
|
||||
@@ -115,7 +119,7 @@ async def status(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
|
||||
# Bot starten
|
||||
def main():
|
||||
app = ApplicationBuilder().token("hier token").build()
|
||||
app = ApplicationBuilder().token(config['telegram']['bot_token']).build()
|
||||
|
||||
app.add_handler(CommandHandler("anmeldung", anmeldung))
|
||||
app.add_handler(CommandHandler("abmeldung", abmeldung))
|
||||
|
||||
Reference in New Issue
Block a user