Skip to content

Commit

Permalink
Minor Fixes & Enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
kaif-00z committed Sep 3, 2024
1 parent f7a2a59 commit 5ac1e1b
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 18 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ FROM python:3.10-slim-buster
WORKDIR /usr/src/app
RUN chmod 777 /usr/src/app

RUN apt-get update && apt-get upgrade -y
RUN apt-get install git wget pv jq python3-dev mediainfo gcc aria2 libsm6 libxext6 libfontconfig1 libxrender1 libgl1-mesa-glx -y
RUN apt -qq update && apt -qq install -y git wget pv jq python3-dev mediainfo gcc aria2 libsm6 libxext6 libfontconfig1 libxrender1 libgl1-mesa-glx

COPY --from=mwader/static-ffmpeg:6.0 /ffmpeg /bin/ffmpeg
COPY --from=mwader/static-ffmpeg:6.0 /ffprobe /bin/ffprobe
Expand Down
6 changes: 3 additions & 3 deletions core/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ async def start_client(self, **kwargs):
await self.pyro_client.start()
except ApiIdInvalidError:
self.logger.critical("API ID and API_HASH combination does not match!")
sys.exit()
sys.exit(1)
except (AuthKeyDuplicatedError, EOFError):
if self._handle_error:
self.logger.critical("String session expired. Create new!")
return sys.exit()
sys.exit(1)
self.logger.critical("String session expired.")
except (AccessTokenExpiredError, AccessTokenInvalidError):
self.logger.critical(
"Bot token is expired or invalid. Create new from @Botfather and add in BOT_TOKEN env variable!"
)
sys.exit()
sys.exit(1)
self.me = await self.get_me()
if self.me.bot:
me = f"@{self.me.username}"
Expand Down
3 changes: 2 additions & 1 deletion database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from libs.firebasewarp import FireDB
from libs.logger import LOGS

import sys

class DataBase:
def __init__(self):
Expand All @@ -32,7 +33,7 @@ def __init__(self):
except Exception as error:
LOGS.exception(format_exc())
LOGS.critical(str(error))
exit()
sys.exit(1)
self.cache = self.dB.getall()
LOGS.info(f"Succesfully Sync Database!!!")

Expand Down
9 changes: 5 additions & 4 deletions functions/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ class ScheduleTasks:
def __init__(self, bot: TelegramClient):
self.tools = Tools()
self.bot = bot
if Var.SEND_SCHEDULE:
if Var.SEND_SCHEDULE or Var.RESTART_EVERDAY:
self.sch = AsyncIOScheduler(timezone="Asia/Kolkata")
self.sch.add_job(self.anime_timing, "cron", hour=0, minute=30)
if Var.SEND_SCHEDULE:
self.sch.add_job(self.anime_timing, "cron", hour=0, minute=30) # 12:30 AM IST
if Var.RESTART_EVERDAY:
self.sch.add_job(self.restart, "corn", hour=2, minute=1) # 2:01 AM IST
self.sch.start()

async def anime_timing(self):
Expand All @@ -53,8 +56,6 @@ async def anime_timing(self):
await mssg.pin(notify=True)
except Exception as error:
LOGS.error(str(error))
if Var.RESTART_EVERDAY:
self.restart()

def restart(self):
os.execl(sys.executable, sys.executable, "bot.py")
6 changes: 4 additions & 2 deletions functions/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# if you are using this following code then don't forgot to give proper
# credit to t.me/kAiF_00z (github.com/kaif-00z)

import asyncio
import asyncio, requests
import json
import math
import os
Expand Down Expand Up @@ -131,7 +131,9 @@ async def get_chat_info(self, bot, anime_info, dB):

def init_dir(self):
if not os.path.exists("thumb.jpg"):
os.system(f"wget {Var.THUMB} -O thumb.jpg")
content = requests.get(Var.THUMB).content
with open("thumb.jpg", "wb") as f:
f.write(content)
if not os.path.isdir("encode/"):
os.mkdir("encode/")
if not os.path.isdir("thumbs/"):
Expand Down
7 changes: 4 additions & 3 deletions libs/firebasewarp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from traceback import format_exc
import sys

import firebase_admin
import requests
Expand All @@ -11,7 +12,7 @@ def firebase_auth(Var):
if Var.FIREBASE_SERVICE_ACCOUNT_FILE and Var.FIREBASE_URL:
if not Var.FIREBASE_SERVICE_ACCOUNT_FILE.startswith("https://"):
LOGS.error("Firebase Service Account File Link is Wrong!")
exit()
sys.exit(1)

service_acc = requests.get(Var.FIREBASE_SERVICE_ACCOUNT_FILE).json()

Expand All @@ -24,15 +25,15 @@ def firebase_auth(Var):
return db.reference()
except BaseException:
LOGS.error(str(format_exc()))
exit()
sys.exit(1)


class FireDB:
def __init__(self, Var):
self.db = firebase_auth(Var)
if not self.db:
LOGS.info("Something Went Wrong With FireBase")
exit()
sys.exit(1)

def getall(self):
return self.db.get() or {}
Expand Down
2 changes: 1 addition & 1 deletion libs/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"""
Auto Anime Bot
©️ t.me/kAiF_00z (github.com/kaif-00z)
v0.0.7 (original)
v0.0.8 (original)
(2023-24)
[All Rigth Reserved]
Expand Down
4 changes: 2 additions & 2 deletions libs/subsplease.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# if you are using this following code then don't forgot to give proper
# credit to t.me/kAiF_00z (github.com/kaif-00z)

import asyncio
import asyncio, sys
import hashlib
import shutil
from itertools import count
Expand All @@ -41,7 +41,7 @@ def _exit(self):
[shutil.rmtree(fold) for fold in ["downloads", "thumbs", "encode"]]
except BaseException:
LOGS.error(format_exc())
exit()
sys.exit(0)

def rss_feed_data(self):
try:
Expand Down

0 comments on commit 5ac1e1b

Please sign in to comment.