forked from TheCaduceus/WARP-UNLIMITED-ADVANCED
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
143 lines (127 loc) · 4.13 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# To get values from Environment
ENV = False # or True
# Ask for values during each run
INTERACTIVE_MODE = False # or True
# Required if ENV == False
Vars = [
# WARP_ID
"",
# SEND_LOG, Want to receive log on Telegram?
# 1 = Yes or 0 = No
"",
# CHAT_ID, required if SEND_LOG is 1
# Can be Channel/Group username or ID
"",
# BOT_TOKEN, required if SEND_LOG is 1
# Get from https://t.me/BotFather
"",
# HIDE_ID, Do you want to hide WARP_ID from log msg?
# 1 = Yes or 0 = No
"",
# DON'T EDIT THIS
INTERACTIVE_MODE
]
import os, sys
import logging as log
Log_file = 'runtime-log.txt'
if os.path.exists(Log_file):
os.remove(Log_file)
# Setup Logger
log.basicConfig(
level=log.INFO,
datefmt="%d/%m/%Y %H:%M:%S",
format="[%(asctime)s][%(levelname)s] => %(message)s",
handlers=[
log.StreamHandler(stream=sys.stdout),
log.FileHandler(Log_file, mode="a", encoding="utf-8")
],
)
log.info("---Starting---")
log.info(f"Current Log file: {Log_file}")
py_ver = sys.version_info
if py_ver[0] == 3 and py_ver[1] < 7:
log.warning(
f"You are using Python 3.{py_ver[1]}.{py_ver[2]}, please upgrade it to 3.11.x to avoid any error."
)
elif py_ver[0] > 3:
log.warning(
f"You are using Python {py_ver[0]}.{py_ver[1]}.{py_ver[2]}, please use 3.11.x to avoid any error."
)
else:
log.info(f"Python Version: {py_ver[0]}.{py_ver[1]}.{py_ver[2]}")
def check():
if not Vars[0]:
log.error("WARP_ID not found!")
raise ValueError('WARP_ID cannot be empty!')
else:
key_length = len(Vars[0]) - 11
hidden_key = "*" * key_length + Vars[0][-11:]
log.info(f"Found WARP_CLIENT_ID: {hidden_key}")
if not Vars[1]:
log.warning("SEND_LOG value is empty, hence disabled.")
Vars[1] = "0"
elif Vars[1] in ["0","1"]:
log.info(f"SEND_LOG: {Vars[1]}")
else:
log.info(
"Provided SEND_LOG value is invalid! hence changed to 0 (disabled).")
Vars[1] = "0"
if not Vars[2] and Vars[1] == "1":
log.warning(
"SEND_LOG is enabled but CHAT_ID not provided! hence disabled.")
Vars[1] = "0"
elif Vars[2] or Vars[1] != "0":
log.info(f"Found CHAT_ID: {Vars[2]}")
if not Vars[3] and Vars[1] == "1":
log.warning(
"SEND_LOG is enabled but BOT_TOKEN not provided! hence disabled.")
Vars[1] = "0"
elif Vars[3] or Vars[1] != "0":
log.info("Found BOT_TOKEN")
if not Vars[4] and Vars[1] == "1":
log.warning(
"HIDE_ID value not provided! hence value changed to default (0).")
elif Vars[4] in ["0","1"]:
log.info(f"Found HIDE_ID: {Vars[4]}")
elif Vars[4] and SEND_LOG == "1":
log.warning("HIDE_ID value is invalid! hence changed to default (0).")
if ENV == False:
log.info("Got Values from config.py file!")
else:
log.info("Got Values from System Environment!")
if ENV == False and INTERACTIVE_MODE == False:
log.info("Getting Values from config.py file...")
check()
elif ENV == True and INTERACTIVE_MODE == True:
log.info("ENV & INTERACTIVE MODE both are active, hence disabled ENV MODE.")
ENV = False
elif ENV == False and INTERACTIVE_MODE == True:
log.info("INTERACTIVE MODE is active!")
elif ENV == True and INTERACTIVE_MODE == False:
log.info("Getting Values from System Environment...")
WARP_ID = os.environ.get("WARP_ID", "")
SEND_LOG = os.environ.get("SEND_LOG", "")
CHAT_ID = os.environ.get("CHAT_ID", "")
BOT_TOKEN = os.environ.get("BOT_TOKEN", "")
HIDE_ID = os.environ.get("HIDE_ID", "")
INTERACTIVE_MODE = os.environ.get("INTERACTIVE_MODE", False)
Vars = [WARP_ID, SEND_LOG, CHAT_ID, BOT_TOKEN, HIDE_ID, INTERACTIVE_MODE]
check()
elif ENV not in [True,False]:
log.warning(
"Given ENV value is invalid, it can be True or False (bool) only!"
)
log.info(f"{ENV}: {type(ENV)}")
raise ValueError(
"ENV value is invalid! should be True or False (bool) only!"
)
elif INTERACTIVE_MODE not in [True,False]:
log.warning(
"Given INTERACTIVE_MODE value in invalid, it can be True or False (bool) only!"
)
log.info(f"{INTERACTIVE_MODE}: {type(INTERACTIVE_MODE)}")
raise ValueError(
"INTERACTIVE_MODE value is invalid! should be True or False (bool) only"
)
else:
log.warning("Something went wrong!") # 0.1% still XD