diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..669287a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +toml~=0.10.2 +psutil~=5.8.0 \ No newline at end of file diff --git a/serverbot.py b/serverbot.py new file mode 100644 index 0000000..3cc55c7 --- /dev/null +++ b/serverbot.py @@ -0,0 +1,81 @@ +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()