Compare commits
6 Commits
f5e3cd5a50
...
v1.1
Author | SHA1 | Date | |
---|---|---|---|
234b73add0 | |||
f4fb85f7a4 | |||
4fba305b05 | |||
68c7cc0ada | |||
79304816b0 | |||
2cfa5a8f8d |
@@ -1,5 +1,4 @@
|
||||
from datetime import datetime
|
||||
from asyncio import sleep
|
||||
from traceback import format_exc
|
||||
from app import app, isAnAdmin
|
||||
from typing import Any, List, Literal, Union
|
||||
@@ -124,11 +123,11 @@ class HoloUser():
|
||||
|
||||
# Check if any text available and log message sending
|
||||
if text is not None:
|
||||
logWrite(f"{context.from_user.id} sent message '{text}' to {self.id} (source message: {context.id})")
|
||||
logWrite(f"{context.from_user.id} sent message '{text}' to {self.id}")
|
||||
elif caption is not None:
|
||||
logWrite(f"{context.from_user.id} sent message '{caption}' to {self.id} (source message: {context.id})")
|
||||
logWrite(f"{context.from_user.id} sent message '{caption}' to {self.id}")
|
||||
else:
|
||||
logWrite(f"{context.from_user.id} sent message to {self.id} (source message: {context.id})")
|
||||
logWrite(f"{context.from_user.id} sent message to {self.id}")
|
||||
|
||||
# Add notices for admin or user
|
||||
if text is not None:
|
||||
@@ -165,7 +164,7 @@ class HoloUser():
|
||||
elif file is not None:
|
||||
if isinstance(file, Document):
|
||||
file = file.file_id
|
||||
new_message = await origin.reply_cached_media(file, caption=caption, quote=True)
|
||||
new_message = await origin.reply_document(file, caption=caption, quote=True)
|
||||
elif animation is not None:
|
||||
if isinstance(animation, Animation):
|
||||
animation = animation.file_id
|
||||
@@ -190,7 +189,7 @@ class HoloUser():
|
||||
elif file is not None:
|
||||
if isinstance(file, Document):
|
||||
file = file.file_id
|
||||
new_message = await app.send_cached_media(self.id, file, caption=caption)
|
||||
new_message = await app.send_document(self.id, file, caption=caption)
|
||||
elif animation is not None:
|
||||
if isinstance(animation, Animation):
|
||||
animation = animation.file_id
|
||||
@@ -228,7 +227,6 @@ class HoloUser():
|
||||
try:
|
||||
await app.promote_chat_member(configGet("users", "groups"), self.id, privileges=ChatPrivileges(can_pin_messages=True, can_manage_video_chats=True))
|
||||
if not await isAnAdmin(self.id):
|
||||
await sleep(0.5)
|
||||
await app.set_administrator_title(configGet("users", "groups"), self.id, label)
|
||||
self.set("label", label)
|
||||
except Exception as exp:
|
||||
|
@@ -114,6 +114,7 @@
|
||||
"permissions": [
|
||||
"users",
|
||||
"admins",
|
||||
"group_users",
|
||||
"group_admins"
|
||||
],
|
||||
"modules": [
|
||||
@@ -122,7 +123,7 @@
|
||||
},
|
||||
"warn": {
|
||||
"permissions": [
|
||||
"group_users_admins"
|
||||
"group_users"
|
||||
],
|
||||
"modules": [
|
||||
"warnings"
|
||||
|
@@ -3,7 +3,6 @@ from pyrogram import filters
|
||||
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, Message
|
||||
from pyrogram.client import Client
|
||||
from classes.holo_user import HoloUser
|
||||
from modules.logging import logWrite
|
||||
from modules.utils import configGet, locale, should_quote
|
||||
from modules.handlers.welcome import welcome_pass
|
||||
from modules.database import col_tmp
|
||||
@@ -35,22 +34,14 @@ async def cmd_reapply(app: Client, msg: Message):
|
||||
await welcome_pass(app, msg, once_again=True)
|
||||
|
||||
else:
|
||||
|
||||
if holo_user.application_state()[1] is True and holo_user.application_state()[0] != "fill":
|
||||
|
||||
await msg.reply_text(locale("reapply_left_chat", "message", locale=holo_user), reply_markup=InlineKeyboardMarkup([
|
||||
[
|
||||
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)
|
||||
await msg.reply_text(locale("reapply_left_chat", "message", locale=holo_user), reply_markup=InlineKeyboardMarkup([
|
||||
[
|
||||
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:
|
||||
|
||||
|
@@ -24,35 +24,42 @@ async def cmd_resetcommands(app: Client, msg: Message):
|
||||
if entry.endswith(".json"):
|
||||
valid_locales.append(".".join(entry.split(".")[:-1]))
|
||||
|
||||
logWrite(f'Resetting commands in groups {configGet("admin", "groups")} and {configGet("users", "groups")}', debug=True)
|
||||
if configGet("debug") is 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("users", "groups")))
|
||||
|
||||
for admin in configGet("admins"):
|
||||
try:
|
||||
logWrite(f'Resetting commands for admin {admin}', debug=True)
|
||||
if configGet("debug") is True:
|
||||
logWrite(f'Resetting commands for admin {admin}')
|
||||
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=admin))
|
||||
except bad_request_400.PeerIdInvalid:
|
||||
pass
|
||||
|
||||
try:
|
||||
logWrite(f'Resetting commands for owner {configGet("owner")}', debug=True)
|
||||
if configGet("debug") is True:
|
||||
logWrite(f'Resetting commands for owner {configGet("owner")}')
|
||||
for lc in valid_locales:
|
||||
logWrite(f'Resetting commands for owner {configGet("owner")} [{lc}]', debug=True)
|
||||
if configGet("debug") is 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")))
|
||||
except bad_request_400.PeerIdInvalid:
|
||||
pass
|
||||
|
||||
for lc in valid_locales:
|
||||
logWrite(f'Resetting commands for locale {lc}', debug=True)
|
||||
if configGet("debug") is True:
|
||||
logWrite(f'Resetting commands for locale {lc}')
|
||||
await app.delete_bot_commands(scope=BotCommandScopeDefault(), language_code=lc)
|
||||
|
||||
logWrite(f'Resetting default commands', debug=True)
|
||||
if configGet("debug") is True:
|
||||
logWrite(f'Resetting default commands')
|
||||
await app.delete_bot_commands()
|
||||
|
||||
await msg.reply_text("OK", quote=should_quote(msg))
|
||||
|
||||
logWrite(str(await app.get_bot_commands()), debug=True)
|
||||
logWrite(str(await app.get_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner")))), debug=True)
|
||||
if configGet("debug") is True:
|
||||
logWrite(str(await app.get_bot_commands()))
|
||||
logWrite(str(await app.get_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("owner")))))
|
||||
# ==============================================================================================================================
|
@@ -33,13 +33,13 @@ async def cmd_start(app: Client, msg: Message):
|
||||
try:
|
||||
spoiler = col_spoilers.find_one( {"_id": ObjectId(msg.command[1])} )
|
||||
if spoiler["photo"] is not None:
|
||||
await msg.reply_cached_media(spoiler["photo"], caption=spoiler["caption"])
|
||||
await msg.reply_document(spoiler["photo"], caption=spoiler["caption"])
|
||||
if spoiler["video"] is not None:
|
||||
await msg.reply_cached_media(spoiler["video"], caption=spoiler["caption"])
|
||||
if spoiler["animation"] is not None:
|
||||
await msg.reply_cached_media(spoiler["animation"], caption=spoiler["caption"])
|
||||
if spoiler["document"] is not None:
|
||||
await msg.reply_cached_media(spoiler["document"], caption=spoiler["caption"])
|
||||
await msg.reply_document(spoiler["document"], caption=spoiler["caption"])
|
||||
if spoiler["text"] is not None:
|
||||
await msg.reply_text(spoiler["text"])
|
||||
except InvalidId:
|
||||
|
@@ -15,11 +15,7 @@ async def member_func(_, __, msg: Message):
|
||||
return True if (msg.from_user.id in jsonLoad(path.join(configGet("cache", "locations"), "group_members"))) else False
|
||||
|
||||
async def allowed_func(_, __, msg: Message):
|
||||
output = False
|
||||
output = True if (col_applications.find_one({"user": msg.from_user.id}) is not None) else False
|
||||
if path.exists(path.join(configGet("cache", "locations"), "group_members")) and (msg.from_user.id not in jsonLoad(path.join(configGet("cache", "locations"), "group_members"))):
|
||||
output = False
|
||||
return output
|
||||
return True if (col_applications.find_one({"user": msg.from_user.id}) is not None) else False
|
||||
|
||||
async def enabled_general_func(_, __, msg: Message):
|
||||
return configGet("enabled", "features", "general")
|
||||
|
@@ -117,7 +117,7 @@ async def confirm_yes(app: Client, msg: Message, kind: Literal["application", "s
|
||||
else:
|
||||
sponsorship_content.append(f"{locale(f'question_{question}', 'message', 'sponsor_titles')} {tmp_sponsorship['sponsorship'][question]}")
|
||||
|
||||
await app.send_cached_media(configGet("admin", "groups"), tmp_sponsorship["sponsorship"]["proof"], caption=(locale("sponsor_got", "message")).format(str(holo_user.id), msg.from_user.first_name, msg.from_user.username, "\n".join(sponsorship_content)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(
|
||||
await app.send_cached_media(chat_id=configGet("admin", "groups"), photo=tmp_sponsorship["sponsorship"]["proof"], caption=(locale("sponsor_got", "message")).format(str(holo_user.id), msg.from_user.first_name, msg.from_user.username, "\n".join(sponsorship_content)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton(text=str(locale("sponsor_yes", "button")), callback_data=f"sponsor_yes_{holo_user.id}")
|
||||
|
@@ -11,8 +11,7 @@ from pyrogram.enums.chat_members_filter import ChatMembersFilter
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from classes.errors.holo_user import UserNotFoundError, UserInvalidError
|
||||
from classes.holo_user import HoloUser
|
||||
from modules.logging import logWrite
|
||||
from modules.utils import configGet, jsonLoad, locale
|
||||
from modules.utils import configGet, locale
|
||||
from modules.database import col_applications, col_spoilers
|
||||
from bson.objectid import ObjectId
|
||||
from bson.errors import InvalidId
|
||||
@@ -65,33 +64,22 @@ async def inline_answer(client: Client, inline_query: InlineQuery):
|
||||
)
|
||||
return
|
||||
|
||||
results_forbidden = [
|
||||
InlineQueryResultArticle(
|
||||
title=locale("title", "inline", "forbidden", locale=inline_query.from_user),
|
||||
input_message_content=InputTextMessageContent(
|
||||
locale("message_content", "inline", "forbidden", locale=inline_query.from_user)
|
||||
),
|
||||
description=locale("description", "inline", "forbidden", locale=inline_query.from_user)
|
||||
)
|
||||
]
|
||||
|
||||
try:
|
||||
holo_user = HoloUser(inline_query.from_user)
|
||||
except (UserNotFoundError, UserInvalidError):
|
||||
logWrite(f"Could not find application of {inline_query.from_user.id}, ignoring inline query", debug=True)
|
||||
await inline_query.answer(
|
||||
results=results_forbidden
|
||||
results=[
|
||||
InlineQueryResultArticle(
|
||||
title=locale("title", "inline", "forbidden", locale=inline_query.from_user),
|
||||
input_message_content=InputTextMessageContent(
|
||||
locale("message_content", "inline", "forbidden", locale=inline_query.from_user)
|
||||
),
|
||||
description=locale("description", "inline", "forbidden", locale=inline_query.from_user)
|
||||
)
|
||||
]
|
||||
)
|
||||
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"), "admins")) and (inline_query.from_user.id not in jsonLoad(path.join(configGet("cache", "locations"), "admins"))):
|
||||
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(
|
||||
results=results_forbidden
|
||||
)
|
||||
return
|
||||
|
||||
if holo_user.application_approved() or (await isAnAdmin(holo_user.id) is True):
|
||||
|
||||
max_results = configGet("inline_preview_count") if inline_query.query != "" else 200
|
||||
@@ -173,6 +161,5 @@ async def inline_answer(client: Client, inline_query: InlineQuery):
|
||||
|
||||
await inline_query.answer(
|
||||
results=results,
|
||||
cache_time=10,
|
||||
is_personal=True
|
||||
)
|
||||
cache_time=10
|
||||
)
|
||||
|
@@ -6,7 +6,7 @@ from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
from datetime import datetime, timedelta
|
||||
from ujson import dumps
|
||||
from app import app
|
||||
from pyrogram.types import BotCommand, BotCommandScopeChat, BotCommandScopeChatAdministrators
|
||||
from pyrogram.types import BotCommand, BotCommandScopeChat
|
||||
from pyrogram.errors import bad_request_400
|
||||
from pyrogram.enums.chat_members_filter import ChatMembersFilter
|
||||
from classes.holo_user import HoloUser
|
||||
@@ -22,10 +22,8 @@ if configGet("enabled", "scheduler", "cache_members"):
|
||||
list_of_users = []
|
||||
async for member in app.get_chat_members(configGet("users", "groups")):
|
||||
list_of_users.append(member.user.id)
|
||||
makedirs(configGet("cache", "locations"), exist_ok=True)
|
||||
makedirs("cache", exist_ok=True)
|
||||
jsonSave(list_of_users, path.join(configGet("cache", "locations"), "group_members"))
|
||||
if configGet("debug") is True:
|
||||
logWrite("User group caching performed", debug=True)
|
||||
|
||||
if configGet("enabled", "scheduler", "cache_admins"):
|
||||
@scheduler.scheduled_job(trigger="interval", seconds=configGet("interval", "scheduler", "cache_admins"))
|
||||
@@ -33,14 +31,12 @@ if configGet("enabled", "scheduler", "cache_admins"):
|
||||
list_of_users = []
|
||||
async for member in app.get_chat_members(configGet("admin", "groups")):
|
||||
list_of_users.append(member.user.id)
|
||||
makedirs(configGet("cache", "locations"), exist_ok=True)
|
||||
makedirs("cache", exist_ok=True)
|
||||
jsonSave(list_of_users, path.join(configGet("cache", "locations"), "admins"))
|
||||
if configGet("debug") is True:
|
||||
logWrite("Admin group caching performed", debug=True)
|
||||
|
||||
# Cache the avatars of group members
|
||||
if configGet("enabled", "scheduler", "cache_avatars"):
|
||||
@scheduler.scheduled_job(trigger="date", run_date=datetime.now()+timedelta(seconds=15))
|
||||
@scheduler.scheduled_job(trigger="date", run_date=datetime.now()+timedelta(seconds=10))
|
||||
@scheduler.scheduled_job(trigger="interval", hours=configGet("interval", "scheduler", "cache_avatars"))
|
||||
async def cache_avatars():
|
||||
list_of_users = []
|
||||
@@ -80,7 +76,7 @@ if configGet("enabled", "features", "sponsorships") is True:
|
||||
try:
|
||||
tg_user = await app.get_users(entry["user"])
|
||||
until_expiry = relativedelta(datetime.now(), entry["sponsorship"]["expires"]).days
|
||||
await app.send_message( tg_user.id, locale("sponsorships_expires", "message").format(until_expiry) ) # type: ignore
|
||||
await app.send_message( tg_user, locale("sponsorships_expires", "message").format(until_expiry) ) # type: ignore
|
||||
logWrite(f"Notified user that sponsorship expires in {until_expiry} days")
|
||||
except Exception as exp:
|
||||
logWrite(f"Could not find user {entry['user']} notify about sponsorship expiry due to '{exp}'")
|
||||
@@ -103,7 +99,7 @@ if configGet("enabled", "features", "sponsorships") is True:
|
||||
|
||||
|
||||
# Register all bot commands
|
||||
@scheduler.scheduled_job(trigger="date", run_date=datetime.now()+timedelta(seconds=10))
|
||||
@scheduler.scheduled_job(trigger="date", run_date=datetime.now()+timedelta(seconds=3))
|
||||
async def commands_register():
|
||||
|
||||
commands = {
|
||||
@@ -112,7 +108,6 @@ async def commands_register():
|
||||
"owner": [],
|
||||
"group_users": [],
|
||||
"group_admins": [],
|
||||
"group_users_admins": [],
|
||||
"locales": {}
|
||||
}
|
||||
|
||||
@@ -122,7 +117,6 @@ async def commands_register():
|
||||
"owner": [],
|
||||
"group_users": [],
|
||||
"group_admins": [],
|
||||
"group_users_admins": [],
|
||||
"locales": {}
|
||||
}
|
||||
|
||||
@@ -137,8 +131,7 @@ async def commands_register():
|
||||
"admins": [],
|
||||
"owner": [],
|
||||
"group_users": [],
|
||||
"group_admins": [],
|
||||
"group_users_admins": []
|
||||
"group_admins": []
|
||||
}
|
||||
if configGet("debug") is True:
|
||||
commands_raw["locales"][".".join(entry.split(".")[:-1])] = {
|
||||
@@ -146,8 +139,7 @@ async def commands_register():
|
||||
"admins": [],
|
||||
"owner": [],
|
||||
"group_users": [],
|
||||
"group_admins": [],
|
||||
"group_users_admins": []
|
||||
"group_admins": []
|
||||
}
|
||||
|
||||
config_modules = configGet("features")
|
||||
@@ -163,7 +155,8 @@ async def commands_register():
|
||||
enabled = True
|
||||
|
||||
if enabled is False:
|
||||
logWrite(f"Not registering {command} at all", debug=True)
|
||||
if configGet("debug") is True:
|
||||
logWrite(f"Not registering {command} at all")
|
||||
continue
|
||||
|
||||
for permission in config_commands[command]["permissions"]:
|
||||
@@ -223,14 +216,7 @@ async def commands_register():
|
||||
except bad_request_400.ChannelInvalid:
|
||||
logWrite(f"Could not register commands for destination group. Bot is likely not in the group.")
|
||||
|
||||
# Registering destination group admin commands
|
||||
try:
|
||||
await app.set_bot_commands(commands["group_users_admins"], scope=BotCommandScopeChatAdministrators(chat_id=configGet("users", "groups")))
|
||||
logWrite("Registered destination group admin commands")
|
||||
except bad_request_400.ChannelInvalid:
|
||||
logWrite(f"Could not register admin commands for destination group. Bot is likely not in the group.")
|
||||
|
||||
|
||||
if configGet("debug") is True:
|
||||
print(commands, flush=True)
|
||||
logWrite(f"Complete commands registration:\n{dumps(commands_raw, indent=4, ensure_ascii=False, encode_html_chars=False)}", debug=True)
|
||||
logWrite(f"Complete commands registration:\n{dumps(commands_raw, indent=4, ensure_ascii=False, encode_html_chars=False)}")
|
@@ -1,10 +1,10 @@
|
||||
APScheduler==3.9.1.post1
|
||||
fastapi~=0.88.0
|
||||
fastapi==0.88.0
|
||||
psutil==5.9.4
|
||||
pymongo==4.3.3
|
||||
Pyrogram~=2.0.95
|
||||
Pyrogram~=2.0.93
|
||||
requests==2.28.1
|
||||
tgcrypto==1.2.5
|
||||
python_dateutil==2.8.2
|
||||
starlette~=0.22.0
|
||||
ujson~=5.7.0
|
||||
starlette==0.23.0
|
||||
ujson==5.6.0
|
Reference in New Issue
Block a user