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 import Update
|
||||||
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
|
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
|
||||||
|
import configparser
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# Konfiguration
|
# 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
|
# Lade die Liste, falls vorhanden
|
||||||
if os.path.exists(LIST_FILE):
|
if os.path.exists(list_file):
|
||||||
with open(LIST_FILE, "r") as f:
|
with open(list_file, "r") as f:
|
||||||
event_list = json.load(f)
|
event_list = json.load(f)
|
||||||
else:
|
else:
|
||||||
event_list = []
|
event_list = []
|
||||||
|
|
||||||
# Hilfsfunktion zum Speichern
|
# Hilfsfunktion zum Speichern
|
||||||
def save_list():
|
def save_list():
|
||||||
with open(LIST_FILE, "w") as f:
|
with open(list_file, "w") as f:
|
||||||
json.dump(event_list, f)
|
json.dump(event_list, f)
|
||||||
|
|
||||||
# /anmeldung Handler
|
# /anmeldung Handler
|
||||||
@@ -47,7 +51,7 @@ async def abmeldung(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||||||
|
|
||||||
# /liste Handler (nur privat für Admins)
|
# /liste Handler (nur privat für Admins)
|
||||||
async def liste(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
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")
|
await update.message.reply_text("Epic fail, kein Zugriff für dich")
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -67,7 +71,7 @@ import datetime
|
|||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
async def reset(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
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")
|
await update.message.reply_text("Epic fail, Zugriff verweigert")
|
||||||
return
|
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")
|
timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
||||||
backup_file = f"event_list_{timestamp}.json"
|
backup_file = f"event_list_{timestamp}.json"
|
||||||
try:
|
try:
|
||||||
shutil.copy(LIST_FILE, backup_file)
|
shutil.copy(list_file, backup_file)
|
||||||
await update.message.reply_text(
|
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}`",
|
f"Ich hab die Liste mal gespeichert, falls du sie aus Versehen resettet hast, liegt jetz unter:\n`{backup_file}`",
|
||||||
parse_mode="Markdown"
|
parse_mode="Markdown"
|
||||||
@@ -115,7 +119,7 @@ async def status(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||||||
|
|
||||||
# Bot starten
|
# Bot starten
|
||||||
def main():
|
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("anmeldung", anmeldung))
|
||||||
app.add_handler(CommandHandler("abmeldung", abmeldung))
|
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