Compare commits
5 Commits
0bf5ae70eb
...
da3dd3a2fe
Author | SHA1 | Date | |
---|---|---|---|
da3dd3a2fe | |||
3e166a3fca | |||
d090b18655 | |||
e2d28f442c | |||
496240c48b |
@@ -34,14 +34,21 @@ async def cmd_reapply(app: Client, msg: Message):
|
|||||||
await welcome_pass(app, msg, once_again=True)
|
await welcome_pass(app, msg, once_again=True)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
await msg.reply_text(locale("reapply_left_chat", "message", locale=holo_user), reply_markup=InlineKeyboardMarkup([
|
|
||||||
[
|
if holo_user.sponsorship_state()[1] is True:
|
||||||
InlineKeyboardButton(locale("reapply_old_one", "button", locale=holo_user), f"reapply_old_{msg.id}")
|
|
||||||
],
|
await msg.reply_text(locale("reapply_left_chat", "message", locale=holo_user), reply_markup=InlineKeyboardMarkup([
|
||||||
[
|
[
|
||||||
InlineKeyboardButton(locale("reapply_new_one", "button", locale=holo_user), f"reapply_new_{msg.id}")
|
InlineKeyboardButton(locale("reapply_old_one", "button", locale=holo_user), f"reapply_old_{msg.id}")
|
||||||
]
|
],
|
||||||
]))
|
[
|
||||||
|
InlineKeyboardButton(locale("reapply_new_one", "button", locale=holo_user), f"reapply_new_{msg.id}")
|
||||||
|
]
|
||||||
|
]))
|
||||||
|
|
||||||
|
else:
|
||||||
|
holo_user.application_restart(reapply=True)
|
||||||
|
await welcome_pass(app, msg, once_again=True)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
@@ -24,42 +24,35 @@ async def cmd_resetcommands(app: Client, msg: Message):
|
|||||||
if entry.endswith(".json"):
|
if entry.endswith(".json"):
|
||||||
valid_locales.append(".".join(entry.split(".")[:-1]))
|
valid_locales.append(".".join(entry.split(".")[:-1]))
|
||||||
|
|
||||||
if configGet("debug") is True:
|
logWrite(f'Resetting commands in groups {configGet("admin", "groups")} and {configGet("users", "groups")}', debug=True)
|
||||||
logWrite(f'Resetting commands in groups {configGet("admin", "groups")} and {configGet("users", "groups")}')
|
|
||||||
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("admin", "groups")))
|
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("admin", "groups")))
|
||||||
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("users", "groups")))
|
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("users", "groups")))
|
||||||
|
|
||||||
for admin in configGet("admins"):
|
for admin in configGet("admins"):
|
||||||
try:
|
try:
|
||||||
if configGet("debug") is True:
|
logWrite(f'Resetting commands for admin {admin}', debug=True)
|
||||||
logWrite(f'Resetting commands for admin {admin}')
|
|
||||||
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=admin))
|
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=admin))
|
||||||
except bad_request_400.PeerIdInvalid:
|
except bad_request_400.PeerIdInvalid:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if configGet("debug") is True:
|
logWrite(f'Resetting commands for owner {configGet("owner")}', debug=True)
|
||||||
logWrite(f'Resetting commands for owner {configGet("owner")}')
|
|
||||||
for lc in valid_locales:
|
for lc in valid_locales:
|
||||||
if configGet("debug") is True:
|
logWrite(f'Resetting commands for owner {configGet("owner")} [{lc}]', debug=True)
|
||||||
logWrite(f'Resetting commands for owner {configGet("owner")} [{lc}]')
|
|
||||||
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner")), language_code=lc)
|
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner")), language_code=lc)
|
||||||
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner")))
|
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner")))
|
||||||
except bad_request_400.PeerIdInvalid:
|
except bad_request_400.PeerIdInvalid:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for lc in valid_locales:
|
for lc in valid_locales:
|
||||||
if configGet("debug") is True:
|
logWrite(f'Resetting commands for locale {lc}', debug=True)
|
||||||
logWrite(f'Resetting commands for locale {lc}')
|
|
||||||
await app.delete_bot_commands(scope=BotCommandScopeDefault(), language_code=lc)
|
await app.delete_bot_commands(scope=BotCommandScopeDefault(), language_code=lc)
|
||||||
|
|
||||||
if configGet("debug") is True:
|
logWrite(f'Resetting default commands', debug=True)
|
||||||
logWrite(f'Resetting default commands')
|
|
||||||
await app.delete_bot_commands()
|
await app.delete_bot_commands()
|
||||||
|
|
||||||
await msg.reply_text("OK", quote=should_quote(msg))
|
await msg.reply_text("OK", quote=should_quote(msg))
|
||||||
|
|
||||||
if configGet("debug") is True:
|
logWrite(str(await app.get_bot_commands()), debug=True)
|
||||||
logWrite(str(await app.get_bot_commands()))
|
logWrite(str(await app.get_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner")))), debug=True)
|
||||||
logWrite(str(await app.get_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner")))))
|
|
||||||
# ==============================================================================================================================
|
# ==============================================================================================================================
|
@@ -11,6 +11,7 @@ from pyrogram.enums.chat_members_filter import ChatMembersFilter
|
|||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from classes.errors.holo_user import UserNotFoundError, UserInvalidError
|
from classes.errors.holo_user import UserNotFoundError, UserInvalidError
|
||||||
from classes.holo_user import HoloUser
|
from classes.holo_user import HoloUser
|
||||||
|
from modules.logging import logWrite
|
||||||
from modules.utils import configGet, jsonLoad, locale
|
from modules.utils import configGet, jsonLoad, locale
|
||||||
from modules.database import col_applications, col_spoilers
|
from modules.database import col_applications, col_spoilers
|
||||||
from bson.objectid import ObjectId
|
from bson.objectid import ObjectId
|
||||||
@@ -77,16 +78,19 @@ async def inline_answer(client: Client, inline_query: InlineQuery):
|
|||||||
try:
|
try:
|
||||||
holo_user = HoloUser(inline_query.from_user)
|
holo_user = HoloUser(inline_query.from_user)
|
||||||
except (UserNotFoundError, UserInvalidError):
|
except (UserNotFoundError, UserInvalidError):
|
||||||
|
logWrite(f"Could not find application of {inline_query.from_user.id}, ignoring inline query", debug=True)
|
||||||
await inline_query.answer(
|
await inline_query.answer(
|
||||||
results=results_forbidden
|
results=results_forbidden
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
if path.exists(path.join(configGet("cache", "locations"), "group_members")) and (inline_query.from_user.id not in jsonLoad(path.join(configGet("cache", "locations"), "group_members"))):
|
if path.exists(path.join(configGet("cache", "locations"), "group_members")) and (inline_query.from_user.id not in jsonLoad(path.join(configGet("cache", "locations"), "group_members"))):
|
||||||
await inline_query.answer(
|
if path.exists(path.join(configGet("cache", "locations"), "admins")) and (inline_query.from_user.id not in jsonLoad(path.join(configGet("cache", "locations"), "admins"))):
|
||||||
results=results_forbidden
|
logWrite(f"{inline_query.from_user.id} is not an admin and not in members group, ignoring inline query", debug=True)
|
||||||
)
|
await inline_query.answer(
|
||||||
return
|
results=results_forbidden
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
if holo_user.application_approved() or (await isAnAdmin(holo_user.id) is True):
|
if holo_user.application_approved() or (await isAnAdmin(holo_user.id) is True):
|
||||||
|
|
||||||
@@ -169,5 +173,6 @@ async def inline_answer(client: Client, inline_query: InlineQuery):
|
|||||||
|
|
||||||
await inline_query.answer(
|
await inline_query.answer(
|
||||||
results=results,
|
results=results,
|
||||||
cache_time=10
|
cache_time=10,
|
||||||
|
is_personal=True
|
||||||
)
|
)
|
@@ -22,8 +22,9 @@ if configGet("enabled", "scheduler", "cache_members"):
|
|||||||
list_of_users = []
|
list_of_users = []
|
||||||
async for member in app.get_chat_members(configGet("users", "groups")):
|
async for member in app.get_chat_members(configGet("users", "groups")):
|
||||||
list_of_users.append(member.user.id)
|
list_of_users.append(member.user.id)
|
||||||
makedirs("cache", exist_ok=True)
|
makedirs(configGet("cache", "locations"), exist_ok=True)
|
||||||
jsonSave(list_of_users, path.join(configGet("cache", "locations"), "group_members"))
|
jsonSave(list_of_users, path.join(configGet("cache", "locations"), "group_members"))
|
||||||
|
logWrite("User group caching performed", debug=True)
|
||||||
|
|
||||||
if configGet("enabled", "scheduler", "cache_admins"):
|
if configGet("enabled", "scheduler", "cache_admins"):
|
||||||
@scheduler.scheduled_job(trigger="interval", seconds=configGet("interval", "scheduler", "cache_admins"))
|
@scheduler.scheduled_job(trigger="interval", seconds=configGet("interval", "scheduler", "cache_admins"))
|
||||||
@@ -31,8 +32,9 @@ if configGet("enabled", "scheduler", "cache_admins"):
|
|||||||
list_of_users = []
|
list_of_users = []
|
||||||
async for member in app.get_chat_members(configGet("admin", "groups")):
|
async for member in app.get_chat_members(configGet("admin", "groups")):
|
||||||
list_of_users.append(member.user.id)
|
list_of_users.append(member.user.id)
|
||||||
makedirs("cache", exist_ok=True)
|
makedirs(configGet("cache", "locations"), exist_ok=True)
|
||||||
jsonSave(list_of_users, path.join(configGet("cache", "locations"), "admins"))
|
jsonSave(list_of_users, path.join(configGet("cache", "locations"), "admins"))
|
||||||
|
logWrite("Admin group caching performed", debug=True)
|
||||||
|
|
||||||
# Cache the avatars of group members
|
# Cache the avatars of group members
|
||||||
if configGet("enabled", "scheduler", "cache_avatars"):
|
if configGet("enabled", "scheduler", "cache_avatars"):
|
||||||
@@ -76,7 +78,7 @@ if configGet("enabled", "features", "sponsorships") is True:
|
|||||||
try:
|
try:
|
||||||
tg_user = await app.get_users(entry["user"])
|
tg_user = await app.get_users(entry["user"])
|
||||||
until_expiry = relativedelta(datetime.now(), entry["sponsorship"]["expires"]).days
|
until_expiry = relativedelta(datetime.now(), entry["sponsorship"]["expires"]).days
|
||||||
await app.send_message( tg_user, locale("sponsorships_expires", "message").format(until_expiry) ) # type: ignore
|
await app.send_message( tg_user.id, locale("sponsorships_expires", "message").format(until_expiry) ) # type: ignore
|
||||||
logWrite(f"Notified user that sponsorship expires in {until_expiry} days")
|
logWrite(f"Notified user that sponsorship expires in {until_expiry} days")
|
||||||
except Exception as exp:
|
except Exception as exp:
|
||||||
logWrite(f"Could not find user {entry['user']} notify about sponsorship expiry due to '{exp}'")
|
logWrite(f"Could not find user {entry['user']} notify about sponsorship expiry due to '{exp}'")
|
||||||
@@ -155,8 +157,7 @@ async def commands_register():
|
|||||||
enabled = True
|
enabled = True
|
||||||
|
|
||||||
if enabled is False:
|
if enabled is False:
|
||||||
if configGet("debug") is True:
|
logWrite(f"Not registering {command} at all", debug=True)
|
||||||
logWrite(f"Not registering {command} at all")
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for permission in config_commands[command]["permissions"]:
|
for permission in config_commands[command]["permissions"]:
|
||||||
@@ -219,4 +220,4 @@ async def commands_register():
|
|||||||
|
|
||||||
if configGet("debug") is True:
|
if configGet("debug") is True:
|
||||||
print(commands, flush=True)
|
print(commands, flush=True)
|
||||||
logWrite(f"Complete commands registration:\n{dumps(commands_raw, indent=4, ensure_ascii=False, encode_html_chars=False)}")
|
logWrite(f"Complete commands registration:\n{dumps(commands_raw, indent=4, ensure_ascii=False, encode_html_chars=False)}", debug=True)
|
Reference in New Issue
Block a user