Compare commits
2 Commits
f0c333968b
...
0e14ca600f
Author | SHA1 | Date | |
---|---|---|---|
|
0e14ca600f | ||
|
c4177d1575 |
@ -5,11 +5,11 @@ except ModuleNotFoundError:
|
|||||||
from json import JSONDecodeError as JSONDecodeError
|
from json import JSONDecodeError as JSONDecodeError
|
||||||
from json import loads, dumps
|
from json import loads, dumps
|
||||||
|
|
||||||
import os
|
from sys import exit
|
||||||
import sys
|
from os import sep, kill
|
||||||
import traceback
|
from os import name as osname
|
||||||
|
from traceback import print_exc
|
||||||
|
|
||||||
from signal import SIGKILL # type: ignore
|
|
||||||
from modules.logging import logWrite
|
from modules.logging import logWrite
|
||||||
|
|
||||||
def jsonLoad(filename):
|
def jsonLoad(filename):
|
||||||
@ -18,10 +18,10 @@ def jsonLoad(filename):
|
|||||||
try:
|
try:
|
||||||
output = loads(file.read())
|
output = loads(file.read())
|
||||||
except JSONDecodeError:
|
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
|
raise
|
||||||
except FileNotFoundError:
|
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
|
raise
|
||||||
file.close()
|
file.close()
|
||||||
return output
|
return output
|
||||||
@ -33,7 +33,7 @@ def jsonSave(contents, filename):
|
|||||||
file.write(dumps(contents, ensure_ascii=False, indent=4))
|
file.write(dumps(contents, ensure_ascii=False, indent=4))
|
||||||
file.close()
|
file.close()
|
||||||
except Exception as exp:
|
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
|
return
|
||||||
|
|
||||||
|
|
||||||
@ -83,13 +83,13 @@ def locale(key: str, *args: str, locale=configGet("locale")):
|
|||||||
locale = configGet("locale")
|
locale = configGet("locale")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
this_dict = jsonLoad(f'{configGet("locale", "locations")}{os.sep}{locale}.json')
|
this_dict = jsonLoad(f'{configGet("locale", "locations")}{sep}{locale}.json')
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
try:
|
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:
|
except FileNotFoundError:
|
||||||
try:
|
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:
|
except:
|
||||||
return f'⚠️ Locale in config is invalid: could not get "{key}" in {str(args)} from locale "{locale}"'
|
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}"'
|
return f'⚠️ Locale in config is invalid: could not get "{key}" in {str(args)} from locale "{locale}"'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import psutil
|
from psutil import Process
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
print(locale("deps_missing", "console", locale=configGet("locale")), flush=True)
|
print(locale("deps_missing", "console", locale=configGet("locale")), flush=True)
|
||||||
sys.exit()
|
exit()
|
||||||
|
|
||||||
def killProc(pid):
|
def killProc(pid):
|
||||||
if os.name == "posix":
|
if osname == "posix":
|
||||||
os.kill(pid, SIGKILL)
|
from signal import SIGKILL # type: ignore
|
||||||
|
kill(pid, SIGKILL)
|
||||||
else:
|
else:
|
||||||
p = psutil.Process(pid)
|
p = Process(pid)
|
||||||
p.kill()
|
p.kill()
|
14
poster.py
14
poster.py
@ -58,11 +58,11 @@ if "--norun" in argv:
|
|||||||
|
|
||||||
# Import ===================================================================================================================================
|
# Import ===================================================================================================================================
|
||||||
try:
|
try:
|
||||||
import schedule # type: ignore
|
import schedule
|
||||||
from pyrogram import Client, filters, idle # type: ignore
|
from pyrogram.sync import idle
|
||||||
from pyrogram.types import ChatPermissions, ReplyKeyboardMarkup, InlineKeyboardMarkup, InlineKeyboardButton, BotCommand, BotCommandScopeChat # type: ignore
|
from pyrogram.client import Client
|
||||||
from pyrogram.raw.types import UpdateChannelMessageForwards, InputChannel, InputPeerChannel
|
from pyrogram import filters
|
||||||
from pyrogram.raw.functions.stats import GetMessagePublicForwards
|
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, BotCommand, BotCommandScopeChat
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
print(locale("deps_missing", "console", locale=configGet("locale_log")), flush=True)
|
print(locale("deps_missing", "console", locale=configGet("locale_log")), flush=True)
|
||||||
exit()
|
exit()
|
||||||
@ -181,7 +181,7 @@ def send_content():
|
|||||||
return
|
return
|
||||||
|
|
||||||
index["sent"].append(candidate_file)
|
index["sent"].append(candidate_file)
|
||||||
index["last_id"] = sent.id
|
index["last_id"] = sent.id # type: ignore
|
||||||
|
|
||||||
jsonSave(index, configGet("index", "locations"))
|
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
|
app.send_message(configGet("admin"), locale("startup", "message", locale=configGet("locale")).format(str(pid))) # type: ignore
|
||||||
|
|
||||||
if configGet("post", "mode"):
|
if configGet("post", "mode"):
|
||||||
t = Thread(target=background_task)
|
t = Thread(target=background_task) # type: ignore
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
if configGet("submit", "mode"):
|
if configGet("submit", "mode"):
|
||||||
|
Reference in New Issue
Block a user