|
29 | 29 | import tempfile |
30 | 30 | import threading |
31 | 31 | import time |
32 | | -from collections import namedtuple |
33 | 32 | from configparser import ConfigParser |
34 | 33 | from datetime import datetime |
35 | 34 | from hashlib import sha256, md5 |
|
59 | 58 |
|
60 | 59 | log = logging.getLogger(__name__) |
61 | 60 |
|
62 | | -ApiKey = namedtuple("ApiKey", ["api_id", "api_hash"]) |
63 | | -Proxy = namedtuple("Proxy", ["enabled", "hostname", "port", "username", "password"]) |
| 61 | + |
| 62 | +class APIKey: |
| 63 | + def __init__(self, api_id: int, api_hash: str): |
| 64 | + self.api_id = api_id |
| 65 | + self.api_hash = api_hash |
| 66 | + |
| 67 | + |
| 68 | +class Proxy: |
| 69 | + def __init__(self, enabled: bool, hostname: str, port: int, username: str, password: str): |
| 70 | + self.enabled = enabled |
| 71 | + self.hostname = hostname |
| 72 | + self.port = port |
| 73 | + self.username = username |
| 74 | + self.password = password |
64 | 75 |
|
65 | 76 |
|
66 | 77 | class Client: |
@@ -127,7 +138,7 @@ class Client: |
127 | 138 |
|
128 | 139 | def __init__(self, |
129 | 140 | session_name: str, |
130 | | - api_key: tuple or ApiKey = None, |
| 141 | + api_key: tuple or APIKey = None, |
131 | 142 | proxy: dict or Proxy = None, |
132 | 143 | test_mode: bool = False, |
133 | 144 | token: str = None, |
@@ -790,34 +801,35 @@ def load_config(self): |
790 | 801 | parser = ConfigParser() |
791 | 802 | parser.read("config.ini") |
792 | 803 |
|
793 | | - if parser.has_section("pyrogram"): |
794 | | - self.api_key = ApiKey( |
| 804 | + if self.api_key is not None: |
| 805 | + self.api_key = APIKey( |
| 806 | + api_id=int(self.api_key[0]), |
| 807 | + api_hash=self.api_key[1] |
| 808 | + ) |
| 809 | + elif parser.has_section("pyrogram"): |
| 810 | + self.api_key = APIKey( |
795 | 811 | api_id=parser.getint("pyrogram", "api_id"), |
796 | 812 | api_hash=parser.get("pyrogram", "api_hash") |
797 | 813 | ) |
798 | 814 | else: |
799 | | - self.api_key = ApiKey( |
800 | | - api_id=int(self.api_key[0]), |
801 | | - api_hash=self.api_key[1] |
802 | | - ) |
| 815 | + raise AttributeError("No API Key found") |
803 | 816 |
|
804 | | - if parser.has_section("proxy"): |
| 817 | + if self.proxy is not None: |
| 818 | + self.proxy = Proxy( |
| 819 | + enabled=True, |
| 820 | + hostname=self.proxy["hostname"], |
| 821 | + port=int(self.proxy["port"]), |
| 822 | + username=self.proxy.get("username", None), |
| 823 | + password=self.proxy.get("password", None) |
| 824 | + ) |
| 825 | + elif parser.has_section("proxy"): |
805 | 826 | self.proxy = Proxy( |
806 | 827 | enabled=parser.getboolean("proxy", "enabled"), |
807 | 828 | hostname=parser.get("proxy", "hostname"), |
808 | 829 | port=parser.getint("proxy", "port"), |
809 | 830 | username=parser.get("proxy", "username", fallback=None) or None, |
810 | 831 | password=parser.get("proxy", "password", fallback=None) or None |
811 | 832 | ) |
812 | | - else: |
813 | | - if self.proxy is not None: |
814 | | - self.proxy = Proxy( |
815 | | - enabled=True, |
816 | | - hostname=self.proxy["hostname"], |
817 | | - port=int(self.proxy["port"]), |
818 | | - username=self.proxy.get("username", None), |
819 | | - password=self.proxy.get("password", None) |
820 | | - ) |
821 | 833 |
|
822 | 834 | def load_session(self, session_name): |
823 | 835 | try: |
|
0 commit comments