mirror of
https://github.com/Nick80835/microbot
synced 2025-08-31 06:26:04 +00:00
clean up some code
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
import sys
|
||||
from logging import INFO, basicConfig, getLogger
|
||||
from sys import version_info
|
||||
|
||||
import telethon as tt
|
||||
from telethon.errors.rpcerrorlist import PhoneNumberInvalidError
|
||||
@@ -11,9 +11,9 @@ from telethon.network.connection.tcpabridged import \
|
||||
from .loader import Loader
|
||||
from .settings import Settings
|
||||
|
||||
if version_info[0] < 3 or version_info[1] < 6:
|
||||
if sys.version_info[0] < 3 or sys.version_info[1] < 6:
|
||||
print("This program requires at least Python 3.6.0 to work correctly, exiting.")
|
||||
quit(1)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
class MicroBot():
|
||||
@@ -41,28 +41,29 @@ class MicroBot():
|
||||
basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=INFO)
|
||||
self.logger = getLogger(__name__)
|
||||
|
||||
def _check_config(self, api_key, api_hash, session_name):
|
||||
while api_key is None or api_key == "":
|
||||
def _check_config(self):
|
||||
session_name = self.settings.get_config("session_name")
|
||||
api_key = self.settings.get_config("api_key")
|
||||
api_hash = self.settings.get_config("api_hash")
|
||||
|
||||
while not api_key:
|
||||
api_key = input("Enter your API key: ")
|
||||
|
||||
while api_hash is None or api_hash == "":
|
||||
self.settings.set_config("api_key", api_key)
|
||||
|
||||
while not api_hash:
|
||||
api_hash = input("Enter your API hash: ")
|
||||
|
||||
self.settings.set_config("api_key", api_key)
|
||||
self.settings.set_config("api_hash", api_hash)
|
||||
|
||||
if session_name is None or session_name == "":
|
||||
if not session_name:
|
||||
session_name = "user0"
|
||||
self.settings.set_config("session_name", session_name)
|
||||
|
||||
return api_key, api_hash, session_name
|
||||
|
||||
def start_client(self):
|
||||
session_name = self.settings.get_config("session_name")
|
||||
api_key = self.settings.get_config("api_key")
|
||||
api_hash = self.settings.get_config("api_hash")
|
||||
|
||||
api_key, api_hash, session_name = self._check_config(api_key, api_hash, session_name)
|
||||
api_key, api_hash, session_name = self._check_config()
|
||||
|
||||
self.client = tt.TelegramClient(session_name, api_key, api_hash, connection=CTA)
|
||||
|
||||
@@ -70,7 +71,7 @@ class MicroBot():
|
||||
self.client.start()
|
||||
except PhoneNumberInvalidError:
|
||||
self.logger.error("The phone number provided is invalid, exiting.")
|
||||
exit(2)
|
||||
sys.exit(2)
|
||||
|
||||
async def stop_client(self, reason=None):
|
||||
if reason:
|
||||
|
Reference in New Issue
Block a user