Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
5hojib committed Dec 3, 2024
1 parent cc9ffd4 commit d9c4d1b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
67 changes: 36 additions & 31 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
basicConfig,
)
from logging import (
info as log_info,
)
from logging import (
error as log_error,
)
from logging import (
warning as log_warning,
INFO,
ERROR,
Formatter,
FileHandler,
StreamHandler,
info,
error,
warning,
getLogger,
basicConfig,
)
from subprocess import Popen, run, check_output

Expand Down Expand Up @@ -54,12 +57,23 @@
bot_loop = new_event_loop()
set_event_loop(bot_loop)

basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
handlers=[FileHandler("log.txt"), StreamHandler()],
level=INFO,
class CustomFormatter(Formatter):
def format(self, record):
return super().format(record).replace(record.levelname, record.levelname[:1])


formatter = CustomFormatter(
"[%(asctime)s] [%(levelname)s] - %(message)s", datefmt="%d-%b-%y %I:%M:%S %p"
)

file_handler = FileHandler("log.txt")
file_handler.setFormatter(formatter)

stream_handler = StreamHandler()
stream_handler.setFormatter(formatter)

basicConfig(handlers=[file_handler, stream_handler], level=INFO)

LOGGER = getLogger(__name__)

load_dotenv("config.env", override=True)
Expand All @@ -81,7 +95,7 @@

try:
if bool(environ.get("_____REMOVE_THIS_LINE_____")):
log_error("The README.md file there to be read! Exiting now!")
error("The README.md file there to be read! Exiting now!")
bot_loop.stop()
exit(1)
except:
Expand All @@ -99,7 +113,7 @@

BOT_TOKEN = environ.get("BOT_TOKEN", "")
if len(BOT_TOKEN) == 0:
log_error("BOT_TOKEN variable is missing! Exiting now")
error("BOT_TOKEN variable is missing! Exiting now")
bot_loop.stop()
exit(1)

Expand Down Expand Up @@ -151,40 +165,32 @@
else:
config_dict = {}

if not ospath.exists(".netrc"):
with open(".netrc", "w"):
pass
run(
"chmod 600 .netrc && cp .netrc /root/.netrc && chmod +x aria-nox-nzb.sh && ./aria-nox-nzb.sh",
shell=True,
check=False,
)

OWNER_ID = environ.get("OWNER_ID", "")
if len(OWNER_ID) == 0:
log_error("OWNER_ID variable is missing! Exiting now")
error("OWNER_ID variable is missing! Exiting now")
bot_loop.stop()
exit(1)
else:
OWNER_ID = int(OWNER_ID)

TELEGRAM_API = environ.get("TELEGRAM_API", "")
if len(TELEGRAM_API) == 0:
log_error("TELEGRAM_API variable is missing! Exiting now")
error("TELEGRAM_API variable is missing! Exiting now")
bot_loop.stop()
exit(1)
else:
TELEGRAM_API = int(TELEGRAM_API)

TELEGRAM_HASH = environ.get("TELEGRAM_HASH", "")
if len(TELEGRAM_HASH) == 0:
log_error("TELEGRAM_HASH variable is missing! Exiting now")
error("TELEGRAM_HASH variable is missing! Exiting now")
bot_loop.stop()
exit(1)

USER_SESSION_STRING = environ.get("USER_SESSION_STRING", "")
if len(USER_SESSION_STRING) != 0:
log_info("Creating client from USER_SESSION_STRING")
info("Creating client from USER_SESSION_STRING")
try:
user = TgClient(
"user",
Expand All @@ -196,7 +202,7 @@
).start()
IS_PREMIUM_USER = user.me.is_premium
except:
log_error("Failed to start client from USER_SESSION_STRING")
error("Failed to start client from USER_SESSION_STRING")
IS_PREMIUM_USER = False
user = ""
else:
Expand Down Expand Up @@ -277,7 +283,7 @@
try:
SEARCH_PLUGINS = eval(SEARCH_PLUGINS)
except:
log_error(f"Wrong USENET_SERVERS format: {SEARCH_PLUGINS}")
error(f"Wrong USENET_SERVERS format: {SEARCH_PLUGINS}")
SEARCH_PLUGINS = ""

MAX_SPLIT_SIZE = 4194304000 if IS_PREMIUM_USER else 2097152000
Expand Down Expand Up @@ -363,7 +369,7 @@

BASE_URL = environ.get("BASE_URL", "").rstrip("/")
if len(BASE_URL) == 0:
log_warning("BASE_URL not provided!")
warning("BASE_URL not provided!")
BASE_URL = ""

UPSTREAM_REPO = environ.get("UPSTREAM_REPO", "")
Expand Down Expand Up @@ -402,7 +408,7 @@
try:
FFMPEG_CMDS = [] if len(FFMPEG_CMDS) == 0 else eval(FFMPEG_CMDS)
except:
log_error(f"Wrong FFMPEG_CMDS format: {FFMPEG_CMDS}")
error(f"Wrong FFMPEG_CMDS format: {FFMPEG_CMDS}")
FFMPEG_CMDS = []

config_dict = {
Expand Down Expand Up @@ -456,7 +462,6 @@
"USER_TRANSMISSION": USER_TRANSMISSION,
"UPSTREAM_REPO": UPSTREAM_REPO,
"UPSTREAM_BRANCH": UPSTREAM_BRANCH,
"USENET_SERVERS": USENET_SERVERS,
"USER_SESSION_STRING": USER_SESSION_STRING,
"USE_SERVICE_ACCOUNTS": USE_SERVICE_ACCOUNTS,
"WEB_PINCODE": WEB_PINCODE,
Expand Down Expand Up @@ -589,7 +594,7 @@ def aria2c_init():
xnox_client.app_set_preferences(qb_opt)


log_info("Creating client from BOT_TOKEN")
info("Creating client from BOT_TOKEN")
bot = TgClient(
"bot",
TELEGRAM_API,
Expand Down
1 change: 0 additions & 1 deletion bot/modules/bot_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,6 @@ async def load_config():
"USER_TRANSMISSION": USER_TRANSMISSION,
"UPSTREAM_REPO": UPSTREAM_REPO,
"UPSTREAM_BRANCH": UPSTREAM_BRANCH,
"USENET_SERVERS": USENET_SERVERS,
"USER_SESSION_STRING": USER_SESSION_STRING,
"USE_SERVICE_ACCOUNTS": USE_SERVICE_ACCOUNTS,
"WEB_PINCODE": WEB_PINCODE,
Expand Down

0 comments on commit d9c4d1b

Please sign in to comment.