-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
62 lines (51 loc) · 2 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from plugin import Command, InlineCommand, Setting
default_api_id = '4'
default_api_hash = '014b35b6184100b085b0d0572f9b5103'
botRoot = botHome = os.path.dirname(os.path.realpath(__file__))
commands: list['Command'] = []
inlines: list['InlineCommand'] = []
settings: list['Setting'] = []
env = os.environ
bot_home = x if (x := env.get('BOT_HOME', '')) != '.' else ''
if bot_home:
botHome = os.path.join(botRoot, bot_home)
token = env.get('token') or ''
api_id = env.get('api_id', '') or env.get('app_id', '') or default_api_id
api_hash = env.get('api_hash', '') or env.get('app_hash', '') or default_api_hash
debug = False
if env.get('debug', '') in ['true', 'T', '1', 'True', 'debug']:
debug = True
echo_chat_id = int(x) if (x := env.get('echo_chat_id', '')) else 0
superadmin = [int(x) for x in env.get('superadmin', '').split(',') if x]
telegraph_author_name = env.get('telegraph_author_name', '')
telegraph_author_url = env.get('telegraph_author_url', '')
telegraph_access_token = env.get('telegraph_access_token', '')
proxy_url = proxy = None
proxy_type = env.get('proxy_type', '') or 'http'
if (proxy_port := env.get('proxy_port', '')) != '':
proxy_port = int(proxy_port)
proxy_host = 'localhost'
if env.get('proxy_host', '') != '':
proxy_host = env.get('proxy_host')
proxy_url = f'{proxy_type}://{proxy_host}:{proxy_port}/'
proxy = {
'proxy_type': proxy_type, # (mandatory) protocol to use (see above)
'addr': proxy_host, # (mandatory) proxy IP address
'port': proxy_port, # (mandatory) proxy port number
'rdns': False, # (optional) whether to use remote or local resolve
}
proxy_username = env.get('proxy_username', '')
proxy_password = env.get('proxy_password', '')
if proxy_username and proxy_password:
proxy_url = (
f'{proxy_type}://{proxy_username}:{proxy_password}@{proxy_host}:{proxy_port}'
)
proxy.update(
{
'username': proxy_username,
'password': proxy_password,
}
)