Initial setup
This commit is contained in:
+14
@@ -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
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# Linux installation (Arch, CachyOS)
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate.fish
|
||||
pip install python-telegram-bot
|
||||
+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))
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,6 @@
|
||||
[admin]
|
||||
ids = [CHANGE_ME, CHANGE_ME]
|
||||
|
||||
[chats]
|
||||
# allowed_chat_ids = [CHANGEME]
|
||||
# allow_dms_if_not_in_allowed_chats = True
|
||||
@@ -0,0 +1,2 @@
|
||||
[telegram]
|
||||
bot_token = 'BOT_TOKEN_HERE'
|
||||
Reference in New Issue
Block a user