2
0
mirror of https://github.com/Nick80835/microbot synced 2025-08-22 01:58:17 +00:00

remove cli api id and bot token input

This commit is contained in:
Nick80835 2023-06-08 08:05:57 -04:00
parent 42ccbfd1c4
commit 9116e21d06
2 changed files with 9 additions and 26 deletions

View File

@ -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

View File

@ -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)