From 9116e21d0676b84acf70df7a8612f5dc604ace85 Mon Sep 17 00:00:00 2001 From: Nick80835 Date: Thu, 8 Jun 2023 08:05:57 -0400 Subject: [PATCH] remove cli api id and bot token input --- example_settings.ini | 2 +- ubot/__init__.py | 33 ++++++++------------------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/example_settings.ini b/example_settings.ini index e54d184..baef470 100644 --- a/example_settings.ini +++ b/example_settings.ini @@ -1,5 +1,5 @@ [DEFAULT] -api_key = Telegram API key +api_id = Telegram API ID api_hash = Telegram API hash bot_token = Your Telegram bot token session_name = bot0 diff --git a/ubot/__init__.py b/ubot/__init__.py index 576fab0..0071c05 100644 --- a/ubot/__init__.py +++ b/ubot/__init__.py @@ -38,33 +38,16 @@ class MicroBot(): await self.client.run_until_disconnected() await self.stop_client(reason="Bot disconnected.") - def _check_config(self): - api_key = self.settings.get_config("api_key") - api_hash = self.settings.get_config("api_hash") - bot_token = self.settings.get_config("bot_token") - - while not api_key: - api_key = input("Enter your API key: ") - - self.settings.set_config("api_key", api_key) - - while not api_hash: - api_hash = input("Enter your API hash: ") - - self.settings.set_config("api_hash", api_hash) - - while not bot_token: - bot_token = input("Enter your bot token: ") - - self.settings.set_config("bot_token", bot_token) - - return api_key, api_hash, bot_token - def start_client(self): - api_key, api_hash, bot_token = self._check_config() - try: - self.client = telethon.TelegramClient(self.settings.get_config("session_name", "bot0"), api_key, api_hash, connection=CTA).start(bot_token=bot_token) + self.client = telethon.TelegramClient( + self.settings.get_config("session_name", "bot0") or "bot0", + self.settings.get_config("api_id"), + self.settings.get_config("api_hash"), + connection=CTA + ).start( + bot_token=self.settings.get_config("bot_token") + ) except (TokenInvalidError, AccessTokenExpiredError, AccessTokenInvalidError): self.logger.error("The bot token provided is invalid, exiting.") sys.exit(1)