Compare commits

...

2 Commits

Author SHA1 Message Date
Profitroll
0e14ca600f Changed some imports' paths 2022-09-18 18:27:25 +02:00
Profitroll
c4177d1575 Optimized imports 2022-09-18 18:27:13 +02:00
2 changed files with 23 additions and 22 deletions

@ -5,11 +5,11 @@ except ModuleNotFoundError:
from json import JSONDecodeError as JSONDecodeError
from json import loads, dumps
import os
import sys
import traceback
from sys import exit
from os import sep, kill
from os import name as osname
from traceback import print_exc
from signal import SIGKILL # type: ignore
from modules.logging import logWrite
def jsonLoad(filename):
@ -18,10 +18,10 @@ def jsonLoad(filename):
try:
output = loads(file.read())
except JSONDecodeError:
logWrite(f"Could not load json file {filename}: file seems to be incorrect!\n{traceback.print_exc()}")
logWrite(f"Could not load json file {filename}: file seems to be incorrect!\n{print_exc()}")
raise
except FileNotFoundError:
logWrite(f"Could not load json file {filename}: file does not seem to exist!\n{traceback.print_exc()}")
logWrite(f"Could not load json file {filename}: file does not seem to exist!\n{print_exc()}")
raise
file.close()
return output
@ -33,7 +33,7 @@ def jsonSave(contents, filename):
file.write(dumps(contents, ensure_ascii=False, indent=4))
file.close()
except Exception as exp:
logWrite(f"Could not save json file {filename}: {exp}\n{traceback.print_exc()}")
logWrite(f"Could not save json file {filename}: {exp}\n{print_exc()}")
return
@ -83,13 +83,13 @@ def locale(key: str, *args: str, locale=configGet("locale")):
locale = configGet("locale")
try:
this_dict = jsonLoad(f'{configGet("locale", "locations")}{os.sep}{locale}.json')
this_dict = jsonLoad(f'{configGet("locale", "locations")}{sep}{locale}.json')
except FileNotFoundError:
try:
this_dict = jsonLoad(f'{configGet("locale", "locations")}{os.sep}{configGet("locale")}.json')
this_dict = jsonLoad(f'{configGet("locale", "locations")}{sep}{configGet("locale")}.json')
except FileNotFoundError:
try:
this_dict = jsonLoad(f'{configGet("locale_fallback", "locations")}{os.sep}{configGet("locale")}.json')
this_dict = jsonLoad(f'{configGet("locale_fallback", "locations")}{sep}{configGet("locale")}.json')
except:
return f'⚠️ Locale in config is invalid: could not get "{key}" in {str(args)} from locale "{locale}"'
@ -103,14 +103,15 @@ def locale(key: str, *args: str, locale=configGet("locale")):
return f'⚠️ Locale in config is invalid: could not get "{key}" in {str(args)} from locale "{locale}"'
try:
import psutil
from psutil import Process
except ModuleNotFoundError:
print(locale("deps_missing", "console", locale=configGet("locale")), flush=True)
sys.exit()
exit()
def killProc(pid):
if os.name == "posix":
os.kill(pid, SIGKILL)
if osname == "posix":
from signal import SIGKILL # type: ignore
kill(pid, SIGKILL)
else:
p = psutil.Process(pid)
p = Process(pid)
p.kill()

@ -58,11 +58,11 @@ if "--norun" in argv:
# Import ===================================================================================================================================
try:
import schedule # type: ignore
from pyrogram import Client, filters, idle # type: ignore
from pyrogram.types import ChatPermissions, ReplyKeyboardMarkup, InlineKeyboardMarkup, InlineKeyboardButton, BotCommand, BotCommandScopeChat # type: ignore
from pyrogram.raw.types import UpdateChannelMessageForwards, InputChannel, InputPeerChannel
from pyrogram.raw.functions.stats import GetMessagePublicForwards
import schedule
from pyrogram.sync import idle
from pyrogram.client import Client
from pyrogram import filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, BotCommand, BotCommandScopeChat
except ModuleNotFoundError:
print(locale("deps_missing", "console", locale=configGet("locale_log")), flush=True)
exit()
@ -181,7 +181,7 @@ def send_content():
return
index["sent"].append(candidate_file)
index["last_id"] = sent.id
index["last_id"] = sent.id # type: ignore
jsonSave(index, configGet("index", "locations"))
@ -458,7 +458,7 @@ if __name__ == "__main__":
app.send_message(configGet("admin"), locale("startup", "message", locale=configGet("locale")).format(str(pid))) # type: ignore
if configGet("post", "mode"):
t = Thread(target=background_task)
t = Thread(target=background_task) # type: ignore
t.start()
if configGet("submit", "mode"):