You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.2 KiB
Python
82 lines
2.2 KiB
Python
4 years ago
|
import telegram_bot_api as api
|
||
|
import toml
|
||
|
import os
|
||
|
import psutil
|
||
|
|
||
|
SKRIPTPFAD = os.path.abspath(os.path.dirname(__file__))
|
||
|
CONFIGDATEI = "cfg.toml"
|
||
|
|
||
|
|
||
|
def load_config():
|
||
|
configfile = os.path.join(SKRIPTPFAD, CONFIGDATEI)
|
||
|
with open(configfile) as conffile:
|
||
|
config = toml.loads(conffile.read())
|
||
|
return config
|
||
|
|
||
|
|
||
|
CONFIG = load_config()
|
||
|
USERS = CONFIG["telegram"]["allowed_ids"]
|
||
|
|
||
|
|
||
|
class EmpyrionBot(api.Bot):
|
||
|
def __init__(self, token):
|
||
|
super().__init__(token)
|
||
|
|
||
|
def start(self):
|
||
|
pass
|
||
|
|
||
|
def start_server(self):
|
||
|
pass
|
||
|
|
||
|
def stop_server(self):
|
||
|
pass
|
||
|
|
||
|
def status_server(self):
|
||
|
pass
|
||
|
|
||
|
def update_server(self):
|
||
|
pass
|
||
|
|
||
|
def abbrechen(self):
|
||
|
pass
|
||
|
|
||
|
# ---------------------------------------------------------------------------------------------------------------------
|
||
|
# Ab hier kommen die Botkommandos
|
||
|
# ---------------------------------------------------------------------------------------------------------------------
|
||
|
def commands(self, nachricht, bot, telegramid):
|
||
|
"""Hier werden alle Verfügbaren Telegramkommdos angelegt"""
|
||
|
kommando = nachricht["message"]["text"]
|
||
|
if kommando == "/start":
|
||
|
self.start()
|
||
|
elif kommando == "/start_server":
|
||
|
self.status_server()
|
||
|
elif kommando == "/stop_server":
|
||
|
self.stop_server()
|
||
|
elif kommando == "/status_server":
|
||
|
self.status_server()
|
||
|
elif kommando == "/update_server":
|
||
|
self.update_server()
|
||
|
elif kommando == "/abbrechen":
|
||
|
self.abbrechen()
|
||
|
else:
|
||
|
bot.send_message(telegramid, "Command not found")
|
||
|
|
||
|
|
||
|
def nachrichten_handler(nachricht, bot):
|
||
|
"""Handling der vorliegenden Nachricht"""
|
||
|
telegramid = nachricht["message"]["from"]["id"]
|
||
|
if telegramid not in USERS.value():
|
||
|
bot.send_message(telegramid, "Permission denied")
|
||
|
if "message" in nachricht:
|
||
|
# Prüfen ob es sich um ein Botkommando handelt
|
||
|
if "bot_command" in nachricht["message"].get("entities", [{}])[0].get("type", ""):
|
||
|
bot.commands(nachricht, bot, telegramid)
|
||
|
|
||
|
|
||
|
def main():
|
||
|
bot = EmpyrionBot(CONFIG["telegram"]["token"])
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|