Spoilers, major command system improvements #4
@ -284,9 +284,9 @@ class HoloUser():
|
||||
raise LabelTooLongError(label)
|
||||
self.label = label
|
||||
try:
|
||||
await app.promote_chat_member(configGet("admin", "users"), self.id, privileges=ChatPrivileges(can_pin_messages=True, can_manage_video_chats=True))
|
||||
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 app.set_administrator_title(configGet("admin", "users"), self.id, label)
|
||||
await app.set_administrator_title(configGet("users", "groups"), self.id, label)
|
||||
self.set("label", label)
|
||||
except bad_request_400.UserCreator:
|
||||
logWrite(f"Could not set {self.id}'s title to '{self.label}' because of bad_request_400.UserCreator")
|
||||
@ -301,9 +301,9 @@ class HoloUser():
|
||||
"""
|
||||
self.label = ""
|
||||
self.set("label", "")
|
||||
await app.set_administrator_title(configGet("admin", "users"), self.id, "")
|
||||
await app.set_administrator_title(configGet("users", "groups"), self.id, "")
|
||||
if not await isAnAdmin(self.id):
|
||||
await app.promote_chat_member(configGet("admin", "users"), self.id, privileges=ChatPrivileges(
|
||||
await app.promote_chat_member(configGet("users", "groups"), self.id, privileges=ChatPrivileges(
|
||||
can_manage_chat=False,
|
||||
can_pin_messages=False,
|
||||
can_manage_video_chats=False
|
||||
|
@ -32,12 +32,12 @@ async def callback_reapply_query_accept(app: Client, clb: CallbackQuery):
|
||||
|
||||
need_link = True
|
||||
|
||||
async for member in app.get_chat_members(configGet("admin", "users")):
|
||||
async for member in app.get_chat_members(configGet("users", "groups")):
|
||||
if member.user.id == holo_user.id:
|
||||
need_link = False
|
||||
|
||||
if need_link:
|
||||
link = await app.create_chat_invite_link(configGet("admin", "users"), name=f"Invite for {holo_user.id}", member_limit=1) #, expire_date=datetime.now()+timedelta(days=1))
|
||||
link = await app.create_chat_invite_link(configGet("users", "groups"), name=f"Invite for {holo_user.id}", member_limit=1) #, expire_date=datetime.now()+timedelta(days=1))
|
||||
|
||||
await app.send_message(holo_user.id, locale("read_rules", "message", locale=holo_user))
|
||||
|
||||
|
@ -67,7 +67,7 @@ async def callback_query_sponsor_yes(app: Client, clb: CallbackQuery):
|
||||
}
|
||||
)
|
||||
|
||||
await holo_user.label_set(configGet("admin", "users"), col_tmp.find_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}})["sponsorship"]["label"])
|
||||
await holo_user.label_set(configGet("users", "groups"), col_tmp.find_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}})["sponsorship"]["label"])
|
||||
|
||||
edited_markup = [[InlineKeyboardButton(text=str(locale("accepted", "button")), callback_data="nothing")]]
|
||||
|
||||
|
@ -20,12 +20,12 @@ async def callback_query_accept(app: Client, clb: CallbackQuery):
|
||||
|
||||
need_link = True
|
||||
|
||||
async for member in app.get_chat_members(configGet("admin", "users")):
|
||||
async for member in app.get_chat_members(configGet("users", "groups")):
|
||||
if member.user.id == holo_user.id:
|
||||
need_link = False
|
||||
|
||||
if need_link:
|
||||
link = await app.create_chat_invite_link(configGet("admin", "users"), name=f"Invite for {holo_user.id}", member_limit=1) #, expire_date=datetime.now()+timedelta(days=1))
|
||||
link = await app.create_chat_invite_link(configGet("users", "groups"), name=f"Invite for {holo_user.id}", member_limit=1) #, expire_date=datetime.now()+timedelta(days=1))
|
||||
|
||||
await app.send_message(holo_user.id, locale("read_rules", "message", locale=holo_user))
|
||||
|
||||
|
@ -21,7 +21,7 @@ async def callback_query_sus_allow(app: Client, clb: CallbackQuery):
|
||||
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||
await clb.answer(text=locale("sus_allowed", "callback", locale=clb.from_user).format(holo_user.id), show_alert=True)
|
||||
|
||||
await app.restrict_chat_member(configGet("admin", "users"), holo_user.id, permissions=ChatPermissions(
|
||||
await app.restrict_chat_member(configGet("users", "groups"), holo_user.id, permissions=ChatPermissions(
|
||||
can_send_messages=True,
|
||||
can_send_media_messages=True,
|
||||
can_send_other_messages=True,
|
||||
@ -43,7 +43,7 @@ async def callback_query_sus_reject(app: Client, clb: CallbackQuery):
|
||||
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||
await clb.answer(text=locale("sus_rejected", "callback", locale=clb.from_user).format(holo_user.id), show_alert=True)
|
||||
|
||||
await app.ban_chat_member(configGet("admin", "users"), holo_user.id)
|
||||
await app.ban_chat_member(configGet("users", "groups"), holo_user.id)
|
||||
|
||||
col_tmp.update_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "application"}}, {"$set": {"state": "rejected", "sent": False}})
|
||||
# ==============================================================================================================================
|
@ -60,7 +60,7 @@ async def cmd_application(app: Client, msg: Message):
|
||||
# user_id = int(msg.command[1])
|
||||
# else:
|
||||
# list_of_users = []
|
||||
# async for m in app.get_chat_members(configGet("admin", "users"), filter=ChatMembersFilter.SEARCH, query=msg.command[1]):
|
||||
# async for m in app.get_chat_members(configGet("users", "groups"), filter=ChatMembersFilter.SEARCH, query=msg.command[1]):
|
||||
# list_of_users.append(m)
|
||||
# user_id = list_of_users[0].user.id
|
||||
# try:
|
||||
|
@ -11,7 +11,7 @@ from modules.database import col_applications, col_users
|
||||
from classes.errors.geo import PlaceNotFoundError
|
||||
|
||||
# Nearby command ===============================================================================================================
|
||||
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & (filters.private | (filters.chat(configGet("admin", "groups")) | filters.chat(configGet("admin", "users")))) & filters.command(["nearby"], prefixes=["/"]) & (custom_filters.allowed | custom_filters.admin))
|
||||
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & (filters.private | (filters.chat(configGet("admin", "groups")) | filters.chat(configGet("users", "groups")))) & filters.command(["nearby"], prefixes=["/"]) & (custom_filters.allowed | custom_filters.admin))
|
||||
async def cmd_nearby(app: Client, msg: Message):
|
||||
|
||||
holo_user = HoloUser(msg.from_user)
|
||||
|
@ -22,7 +22,7 @@ async def cmd_reapply(app: Client, msg: Message):
|
||||
|
||||
left_chat = True
|
||||
|
||||
async for member in app.get_chat_members(configGet("admin", "users")):
|
||||
async for member in app.get_chat_members(configGet("users", "groups")):
|
||||
if member.user.id == msg.from_user.id:
|
||||
left_chat = False
|
||||
|
||||
|
@ -11,7 +11,7 @@ from modules import custom_filters
|
||||
@app.on_message(custom_filters.enabled_warnings & ~filters.scheduled & filters.command(["warn"], prefixes=["/"]) & custom_filters.admin)
|
||||
async def cmd_warn(app: Client, msg: Message):
|
||||
|
||||
if msg.chat.id == configGet("admin", "users"):
|
||||
if msg.chat.id == configGet("users", "groups"):
|
||||
if msg.reply_to_message_id != None:
|
||||
message = " ".join(msg.command[1:]) if len(msg.command) > 1 else ""
|
||||
col_warnings.insert_one({"user": msg.reply_to_message.from_user.id, "admin": msg.from_user.id, "date": datetime.now(), "reason": message})
|
||||
|
@ -21,7 +21,7 @@ async def cmd_warnings(app: Client, msg: Message):
|
||||
target_name = user_db["tg_name"]
|
||||
except:
|
||||
list_of_users = []
|
||||
async for m in app.get_chat_members(configGet("admin", "users"), filter=ChatMembersFilter.SEARCH, query=msg.command[1]):
|
||||
async for m in app.get_chat_members(configGet("users", "groups"), filter=ChatMembersFilter.SEARCH, query=msg.command[1]):
|
||||
list_of_users.append(m)
|
||||
|
||||
if len(list_of_users) != 0:
|
||||
|
@ -120,7 +120,7 @@ async def any_stage(app: Client, msg: Message):
|
||||
@app.on_message(~ filters.scheduled & filters.group)
|
||||
async def message_in_group(app: Client, msg: Message):
|
||||
if (msg.chat is not None) and (msg.via_bot is not None):
|
||||
if (msg.via_bot.id == (await app.get_me()).id) and (msg.chat.id == configGet("admin", "users")):
|
||||
if (msg.via_bot.id == (await app.get_me()).id) and (msg.chat.id == configGet("users", "groups")):
|
||||
if configGet("remove_application_time") > 0:
|
||||
logWrite(f"User {msg.from_user.id} requested application in destination group, removing in {configGet('remove_application_time')} minutes")
|
||||
await asyncio.sleep(configGet("remove_application_time")*60)
|
||||
|
@ -7,8 +7,8 @@ from classes.holo_user import HoloUser
|
||||
from modules import custom_filters
|
||||
|
||||
# Filter users on join =========================================================================================================
|
||||
@app.on_chat_member_updated(custom_filters.enabled_invites_check, group=configGet("admin", "users"))
|
||||
#@app.on_message(filters.new_chat_members, group=configGet("admin", "users"))
|
||||
@app.on_chat_member_updated(custom_filters.enabled_invites_check, group=configGet("users", "groups"))
|
||||
#@app.on_message(filters.new_chat_members, group=configGet("users", "groups"))
|
||||
async def filter_join(app: Client, member: ChatMemberUpdated):
|
||||
|
||||
if member.invite_link != None:
|
||||
|
@ -7,7 +7,7 @@ from modules.logging import logWrite
|
||||
from modules.utils import configGet, locale
|
||||
from modules import custom_filters
|
||||
|
||||
@app.on_message(custom_filters.enabled_dinovoice & ~filters.scheduled & filters.voice & filters.chat(configGet("admin", "users")))
|
||||
@app.on_message(custom_filters.enabled_dinovoice & ~filters.scheduled & filters.voice & filters.chat(configGet("users", "groups")))
|
||||
async def voice_message(app: Client, msg: Message):
|
||||
logWrite(f"User {msg.from_user.id} sent voice message in destination group")
|
||||
await msg.reply_text(choice(locale("voice_message", "message")))
|
@ -84,7 +84,7 @@ async def inline_answer(client: Client, inline_query: InlineQuery):
|
||||
max_results = configGet("inline_preview_count") if inline_query.query != "" else 200
|
||||
|
||||
list_of_users = []
|
||||
async for m in app.get_chat_members(configGet("admin", "users"), limit=max_results, filter=ChatMembersFilter.SEARCH, query=inline_query.query):
|
||||
async for m in app.get_chat_members(configGet("users", "groups"), limit=max_results, filter=ChatMembersFilter.SEARCH, query=inline_query.query):
|
||||
list_of_users.append(m)
|
||||
|
||||
for match in list_of_users:
|
||||
|
@ -19,7 +19,7 @@ if configGet("enabled", "scheduler", "cache_members"):
|
||||
@scheduler.scheduled_job(trigger="interval", seconds=configGet("interval", "scheduler", "cache_members"))
|
||||
async def cache_group_members():
|
||||
list_of_users = []
|
||||
async for member in app.get_chat_members(configGet("admin", "users")):
|
||||
async for member in app.get_chat_members(configGet("users", "groups")):
|
||||
list_of_users.append(member.user.id)
|
||||
makedirs("cache", exist_ok=True)
|
||||
jsonSave(list_of_users, path.join(configGet("cache", "locations"), "group_members"))
|
||||
@ -39,7 +39,7 @@ if configGet("enabled", "scheduler", "cache_avatars"):
|
||||
@scheduler.scheduled_job(trigger="interval", hours=configGet("interval", "scheduler", "cache_avatars"))
|
||||
async def cache_avatars():
|
||||
list_of_users = []
|
||||
async for member in app.get_chat_members(configGet("admin", "users"), filter=ChatMembersFilter.SEARCH, query=""):
|
||||
async for member in app.get_chat_members(configGet("users", "groups"), filter=ChatMembersFilter.SEARCH, query=""):
|
||||
list_of_users.append(member.user)
|
||||
for user in list_of_users:
|
||||
if user.photo != None:
|
||||
@ -84,7 +84,7 @@ if configGet("enabled", "features", "sponsorships") is True:
|
||||
try:
|
||||
holo_user = HoloUser(entry["user"])
|
||||
await app.send_message( entry["user"], locale("sponsorships_expired", "message") ) # type: ignore
|
||||
await holo_user.label_reset(configGet("admin", "users"))
|
||||
await holo_user.label_reset(configGet("users", "groups"))
|
||||
col_sponsorships.find_one_and_delete({"user": holo_user.id})
|
||||
try:
|
||||
tg_user = await app.get_users(entry["user"])
|
||||
@ -172,7 +172,7 @@ async def commands_register():
|
||||
|
||||
# Registering destination group commands
|
||||
try:
|
||||
await app.set_bot_commands(commands["group_users"], scope=BotCommandScopeChat(chat_id=configGet("admin", "users")))
|
||||
await app.set_bot_commands(commands["group_users"], scope=BotCommandScopeChat(chat_id=configGet("users", "groups")))
|
||||
logWrite("Registered destination group commands")
|
||||
except bad_request_400.ChannelInvalid:
|
||||
logWrite(f"Could not register commands for destination group. Bot is likely not in the group.")
|
Reference in New Issue
Block a user