From 0a19a6d138d1c7c667e89cfab6b43752204dd83a Mon Sep 17 00:00:00 2001 From: SinusFox Date: Sat, 15 Nov 2025 22:38:07 +0100 Subject: [PATCH] Initial setup --- .gitignore | 14 ++++++++++++++ install.sh | 4 ++++ pawhub-bot.py | 22 +++++++++++++--------- pyvenv.cfg | 5 +++++ telegram_bot_config.cfg | 6 ++++++ telegram_bot_token.cfg | 2 ++ 6 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 .gitignore create mode 100644 install.sh create mode 100644 pyvenv.cfg create mode 100644 telegram_bot_config.cfg create mode 100644 telegram_bot_token.cfg diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2de530 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +# Created by venv; see https://docs.python.org/3/library/venv.html + +# Python +__pycache__/ +.python-version +/venv/ + + +# IDE specific files +.vscode/ +.idea/ + +# telegram bot token config + diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..3a62fbd --- /dev/null +++ b/install.sh @@ -0,0 +1,4 @@ +# Linux installation (Arch, CachyOS) +python3 -m venv venv +source venv/bin/activate.fish +pip install python-telegram-bot diff --git a/pawhub-bot.py b/pawhub-bot.py index bbf0d8b..06efa49 100644 --- a/pawhub-bot.py +++ b/pawhub-bot.py @@ -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)) diff --git a/pyvenv.cfg b/pyvenv.cfg new file mode 100644 index 0000000..a3ca8b1 --- /dev/null +++ b/pyvenv.cfg @@ -0,0 +1,5 @@ +home = /usr/bin +include-system-site-packages = false +version = 3.13.7 +executable = /usr/bin/python3.13 +command = /usr/bin/python -m venv /home/sinusfox/GitLab/pawhub-telegram-bot diff --git a/telegram_bot_config.cfg b/telegram_bot_config.cfg new file mode 100644 index 0000000..09f61ff --- /dev/null +++ b/telegram_bot_config.cfg @@ -0,0 +1,6 @@ +[admin] +ids = [CHANGE_ME, CHANGE_ME] + +[chats] +# allowed_chat_ids = [CHANGEME] +# allow_dms_if_not_in_allowed_chats = True diff --git a/telegram_bot_token.cfg b/telegram_bot_token.cfg new file mode 100644 index 0000000..a08ed17 --- /dev/null +++ b/telegram_bot_token.cfg @@ -0,0 +1,2 @@ +[telegram] +bot_token = 'BOT_TOKEN_HERE'