Changed code style to black

This commit is contained in:
2023-03-09 16:25:06 +01:00
parent 5b8951fe07
commit 3304339244
44 changed files with 3243 additions and 936 deletions

View File

@@ -12,51 +12,92 @@ from dateutil.relativedelta import relativedelta
from modules.database import col_applications
from modules import custom_filters
# Application command ==========================================================================================================
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.command(["application"], prefixes=["/"]) & custom_filters.admin)
@app.on_message(
custom_filters.enabled_applications
& ~filters.scheduled
& filters.command(["application"], prefixes=["/"])
& custom_filters.admin
)
async def cmd_application(app: Client, msg: Message):
try:
try:
holo_user = HoloUser(int(msg.command[1]))
except (ValueError, UserNotFoundError):
try:
holo_user = HoloUser((await app.get_users(msg.command[1])).id)
except (bad_request_400.UsernameInvalid, bad_request_400.PeerIdInvalid, bad_request_400.UsernameNotOccupied):
await msg.reply_text(locale("no_user_application", "message", locale=msg.from_user).format(msg.command[1]), quote=should_quote(msg))
except (
bad_request_400.UsernameInvalid,
bad_request_400.PeerIdInvalid,
bad_request_400.UsernameNotOccupied,
):
await msg.reply_text(
locale(
"no_user_application", "message", locale=msg.from_user
).format(msg.command[1]),
quote=should_quote(msg),
)
return
application = col_applications.find_one({"user": holo_user.id})
if application is None:
logWrite(f"User {msg.from_user.id} requested application of {holo_user.id} but user does not exists")
await msg.reply_text(locale("user_invalid", "message", locale=msg.from_user), quote=should_quote(msg))
logWrite(
f"User {msg.from_user.id} requested application of {holo_user.id} but user does not exists"
)
await msg.reply_text(
locale("user_invalid", "message", locale=msg.from_user),
quote=should_quote(msg),
)
return
application_content = []
i = 1
for question in application['application']:
for question in application["application"]:
if i == 2:
age = relativedelta(datetime.now(), application['application']['2'])
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles', locale=msg.from_user)} {application['application']['2'].strftime('%d.%m.%Y')} ({age.years} р.)")
age = relativedelta(datetime.now(), application["application"]["2"])
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles', locale=msg.from_user)} {application['application']['2'].strftime('%d.%m.%Y')} ({age.years} р.)"
)
elif i == 3:
if application['application']['3']['countryCode'] == "UA":
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles', locale=msg.from_user)} {application['application']['3']['name']}")
if application["application"]["3"]["countryCode"] == "UA":
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles', locale=msg.from_user)} {application['application']['3']['name']}"
)
else:
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles', locale=msg.from_user)} {application['application']['3']['name']} ({application['application']['3']['adminName1']}, {application['application']['3']['countryName']})")
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles', locale=msg.from_user)} {application['application']['3']['name']} ({application['application']['3']['adminName1']}, {application['application']['3']['countryName']})"
)
else:
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles', locale=msg.from_user)} {application['application'][question]}")
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles', locale=msg.from_user)} {application['application'][question]}"
)
i += 1
application_status = locale("application_status_accepted", "message", locale=msg.from_user).format((await app.get_users(application["admin"])).first_name, application["date"].strftime("%d.%m.%Y, %H:%M"))
application_status = locale(
"application_status_accepted", "message", locale=msg.from_user
).format(
(await app.get_users(application["admin"])).first_name,
application["date"].strftime("%d.%m.%Y, %H:%M"),
)
logWrite(f"User {msg.from_user.id} requested application of {holo_user.id}")
await msg.reply_text(locale("contact", "message", locale=msg.from_user).format(holo_user.id, "\n".join(application_content), application_status), parse_mode=ParseMode.MARKDOWN, quote=should_quote(msg))
await msg.reply_text(
locale("contact", "message", locale=msg.from_user).format(
holo_user.id, "\n".join(application_content), application_status
),
parse_mode=ParseMode.MARKDOWN,
quote=should_quote(msg),
)
except IndexError:
await msg.reply_text(locale("application_invalid_syntax", "message", locale=msg.from_user), quote=should_quote(msg))
# ==============================================================================================================================
await msg.reply_text(
locale("application_invalid_syntax", "message", locale=msg.from_user),
quote=should_quote(msg),
)
# ==============================================================================================================================

View File

@@ -10,10 +10,15 @@ from modules.utils import should_quote, jsonSave
from modules.database import col_applications
from modules import custom_filters
# Applications command =========================================================================================================
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.command(["applications"], prefixes=["/"]) & custom_filters.admin)
async def cmd_applications(app: Client, msg: Message):
# Applications command =========================================================================================================
@app.on_message(
custom_filters.enabled_applications
& ~filters.scheduled
& filters.command(["applications"], prefixes=["/"])
& custom_filters.admin
)
async def cmd_applications(app: Client, msg: Message):
logWrite(f"Admin {msg.from_user.id} requested export of a database")
await app.send_chat_action(msg.chat.id, ChatAction.UPLOAD_DOCUMENT)
filename = uuid1()
@@ -21,10 +26,18 @@ async def cmd_applications(app: Client, msg: Message):
for entry in col_applications.find():
del entry["_id"]
entry["date"] = entry["date"].strftime("%d.%m.%Y, %H:%M")
entry["application"]["2"] = entry["application"]["2"].strftime("%d.%m.%Y, %H:%M")
entry["application"]["2"] = entry["application"]["2"].strftime(
"%d.%m.%Y, %H:%M"
)
output.append(entry)
makedirs("tmp", exist_ok=True)
jsonSave(output, f"tmp{sep}{filename}.json")
await msg.reply_document(document=f"tmp{sep}{filename}.json", file_name="applications", quote=should_quote(msg))
await msg.reply_document(
document=f"tmp{sep}{filename}.json",
file_name="applications",
quote=should_quote(msg),
)
remove(f"tmp{sep}{filename}.json")
# ==============================================================================================================================
# ==============================================================================================================================

View File

@@ -6,14 +6,30 @@ from modules.utils import should_quote, logWrite, locale
from modules.database import col_tmp, col_spoilers, col_applications
from modules import custom_filters
# Cancel command ===============================================================================================================
@app.on_message((custom_filters.enabled_applications | custom_filters.enabled_sponsorships) & ~filters.scheduled & filters.command("cancel", prefixes=["/"]) & ~custom_filters.banned)
@app.on_message(
(custom_filters.enabled_applications | custom_filters.enabled_sponsorships)
& ~filters.scheduled
& filters.command("cancel", prefixes=["/"])
& ~custom_filters.banned
)
async def command_cancel(app: Client, msg: Message):
col_tmp.delete_many( {"user": msg.from_user.id, "sent": False} )
col_spoilers.delete_many( {"user": msg.from_user.id, "completed": False} )
if col_applications.find_one( {"user": msg.from_user.id} ) is None:
await msg.reply_text(locale("cancel_reapply", "message", locale=msg.from_user), quote=should_quote(msg), reply_markup=ReplyKeyboardRemove())
col_tmp.delete_many({"user": msg.from_user.id, "sent": False})
col_spoilers.delete_many({"user": msg.from_user.id, "completed": False})
if col_applications.find_one({"user": msg.from_user.id}) is None:
await msg.reply_text(
locale("cancel_reapply", "message", locale=msg.from_user),
quote=should_quote(msg),
reply_markup=ReplyKeyboardRemove(),
)
else:
await msg.reply_text(locale("cancel", "message", locale=msg.from_user), quote=should_quote(msg), reply_markup=ReplyKeyboardRemove())
await msg.reply_text(
locale("cancel", "message", locale=msg.from_user),
quote=should_quote(msg),
reply_markup=ReplyKeyboardRemove(),
)
logWrite(f"Cancelling all ongoing tmp operations for {msg.from_user.id}")
# ==============================================================================================================================
# ==============================================================================================================================

View File

@@ -7,15 +7,30 @@ from pyrogram.errors import bad_request_400
from pyrogram.enums.chat_action import ChatAction
from classes.errors.holo_user import UserNotFoundError, UserInvalidError
from classes.holo_user import HoloUser
from modules.utils import jsonLoad, should_quote, logWrite, locale, download_tmp, create_tmp, find_user
from modules.utils import (
jsonLoad,
should_quote,
logWrite,
locale,
download_tmp,
create_tmp,
find_user,
)
from modules import custom_filters
# Identify command =============================================================================================================
@app.on_message((custom_filters.enabled_applications | custom_filters.enabled_sponsorships) & ~filters.scheduled & filters.command("identify", prefixes=["/"]) & custom_filters.admin)
async def cmd_identify(app: Client, msg: Message):
# Identify command =============================================================================================================
@app.on_message(
(custom_filters.enabled_applications | custom_filters.enabled_sponsorships)
& ~filters.scheduled
& filters.command("identify", prefixes=["/"])
& custom_filters.admin
)
async def cmd_identify(app: Client, msg: Message):
if len(msg.command) != 2:
await msg.reply_text(locale("identify_invalid_syntax", "message", locale=msg.from_user))
await msg.reply_text(
locale("identify_invalid_syntax", "message", locale=msg.from_user)
)
return
try:
@@ -23,17 +38,44 @@ async def cmd_identify(app: Client, msg: Message):
holo_user = HoloUser(int(msg.command[1]))
except ValueError:
holo_user = HoloUser(await find_user(app, msg.command[1]))
except (UserInvalidError, UserNotFoundError, bad_request_400.UsernameInvalid, bad_request_400.PeerIdInvalid, bad_request_400.UsernameNotOccupied, TypeError):
await msg.reply_text(locale("identify_not_found", "message", locale=msg.from_user).format(msg.command[1]))
except (
UserInvalidError,
UserNotFoundError,
bad_request_400.UsernameInvalid,
bad_request_400.PeerIdInvalid,
bad_request_400.UsernameNotOccupied,
TypeError,
):
await msg.reply_text(
locale("identify_not_found", "message", locale=msg.from_user).format(
msg.command[1]
)
)
return
role = holo_user.label
has_application = locale("yes", "message", locale=msg.from_user) if holo_user.application_approved() is True else locale("no", "message", locale=msg.from_user)
has_sponsorship = locale("yes", "message", locale=msg.from_user) if holo_user.sponsorship_valid() is True else locale("no", "message", locale=msg.from_user)
has_application = (
locale("yes", "message", locale=msg.from_user)
if holo_user.application_approved() is True
else locale("no", "message", locale=msg.from_user)
)
has_sponsorship = (
locale("yes", "message", locale=msg.from_user)
if holo_user.sponsorship_valid() is True
else locale("no", "message", locale=msg.from_user)
)
username = holo_user.username if holo_user.username is not None else "N/A"
in_chat = locale("yes", "message", locale=msg.from_user) if (holo_user.id in jsonLoad(path.join("cache", "group_members"))) else locale("no", "message", locale=msg.from_user)
is_admin = locale("yes", "message", locale=msg.from_user) if (await isAnAdmin(holo_user.id)) else locale("no", "message", locale=msg.from_user)
in_chat = (
locale("yes", "message", locale=msg.from_user)
if (holo_user.id in jsonLoad(path.join("cache", "group_members")))
else locale("no", "message", locale=msg.from_user)
)
is_admin = (
locale("yes", "message", locale=msg.from_user)
if (await isAnAdmin(holo_user.id))
else locale("no", "message", locale=msg.from_user)
)
output = locale("identify_success", "message", locale=msg.from_user).format(
holo_user.id,
@@ -43,24 +85,25 @@ async def cmd_identify(app: Client, msg: Message):
is_admin,
role,
has_application,
has_sponsorship
has_sponsorship,
)
user = await app.get_users(holo_user.id)
if user.photo is not None:
await app.send_chat_action(msg.chat.id, action=ChatAction.UPLOAD_PHOTO)
await msg.reply_photo(
create_tmp((await download_tmp(app, user.photo.big_file_id))[1], kind="image"),
create_tmp(
(await download_tmp(app, user.photo.big_file_id))[1], kind="image"
),
quote=should_quote(msg),
caption=output
caption=output,
)
else:
await app.send_chat_action(msg.chat.id, action=ChatAction.TYPING)
await msg.reply_text(
output,
quote=should_quote(msg)
)
await msg.reply_text(output, quote=should_quote(msg))
logWrite(f"User {msg.from_user.id} identified user {holo_user.id}")
# ==============================================================================================================================
# ==============================================================================================================================

View File

@@ -9,13 +9,28 @@ from classes.holo_user import HoloUser
# Issue command ================================================================================================================
@app.on_message(custom_filters.enabled_general & ~filters.scheduled & filters.private & filters.command(["issue"], prefixes=["/"]) & ~custom_filters.banned)
@app.on_message(
custom_filters.enabled_general
& ~filters.scheduled
& filters.private
& filters.command(["issue"], prefixes=["/"])
& ~custom_filters.banned
)
async def cmd_issue(app: Client, msg: Message):
await msg.reply_text(locale("issue", "message", locale=msg.from_user), disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup(
await msg.reply_text(
locale("issue", "message", locale=msg.from_user),
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(locale("issue", "button", locale=msg.from_user), url=configGet("issues"))
InlineKeyboardButton(
locale("issue", "button", locale=msg.from_user),
url=configGet("issues"),
)
]
]
))
# ==============================================================================================================================
),
)
# ==============================================================================================================================

View File

@@ -7,10 +7,15 @@ from classes.errors.holo_user import LabelTooLongError, LabelSettingError
from classes.holo_user import HoloUser
from modules import custom_filters
# Label command ================================================================================================================
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.command(["label"], prefixes=["/"]) & custom_filters.admin)
async def cmd_label(app: Client, msg: Message):
# Label command ================================================================================================================
@app.on_message(
custom_filters.enabled_applications
& ~filters.scheduled
& filters.command(["label"], prefixes=["/"])
& custom_filters.admin
)
async def cmd_label(app: Client, msg: Message):
if len(msg.command) < 3:
await msg.reply_text("Invalid syntax:\n`/label USER LABEL`")
return
@@ -18,15 +23,16 @@ async def cmd_label(app: Client, msg: Message):
target = await find_user(app, msg.command[1])
if target is not None:
target = HoloUser(target)
label = " ".join(msg.command[2:])
if label.lower() == "reset":
await target.label_reset(msg.chat)
await msg.reply_text(f"Resetting **{target.id}**'s label...", quote=should_quote(msg))
await msg.reply_text(
f"Resetting **{target.id}**'s label...", quote=should_quote(msg)
)
else:
try:
await target.label_set(msg.chat, label)
@@ -34,10 +40,19 @@ async def cmd_label(app: Client, msg: Message):
await msg.reply_text(locale("label_too_long", "message"))
return
except LabelSettingError as exp:
await app.send_message(configGet("admin", "groups"), exp.__str__(), disable_notification=True)
await app.send_message(
configGet("admin", "groups"),
exp.__str__(),
disable_notification=True,
)
return
await msg.reply_text(f"Setting **{target.id}**'s label to **{label}**...", quote=should_quote(msg))
await msg.reply_text(
f"Setting **{target.id}**'s label to **{label}**...",
quote=should_quote(msg),
)
else:
await msg.reply_text(f"User not found")
# ==============================================================================================================================
# ==============================================================================================================================

View File

@@ -7,28 +7,70 @@ from classes.holo_user import HoloUser
from modules.utils import logWrite, locale, should_quote, find_user
from modules import custom_filters
# Message command ==============================================================================================================
@app.on_message(custom_filters.enabled_general & ~filters.scheduled & filters.command(["message"], prefixes=["/"]) & custom_filters.admin)
@app.on_message(
custom_filters.enabled_general
& ~filters.scheduled
& filters.command(["message"], prefixes=["/"])
& custom_filters.admin
)
async def cmd_message(app: Client, msg: Message):
try:
try:
destination = HoloUser(int(msg.command[1]))
except (ValueError, UserInvalidError):
destination = HoloUser(await find_user(app, query=msg.command[1]))
if ((msg.text is not None) and (len(str(msg.text).split()) > 2)):
await destination.message(context=msg, text=" ".join(str(msg.text).split()[2:]), caption=msg.caption, photo=msg.photo, video=msg.video, file=msg.document, voice=msg.voice, animation=msg.animation, adm_context=True)
elif ((msg.caption is not None) and (len(msg.caption.split()) > 2)):
await destination.message(context=msg, text=str(msg.text), caption=" ".join(msg.caption.split()[2:]), photo=msg.photo, video=msg.video, file=msg.document, voice=msg.voice, animation=msg.animation, adm_context=True)
if (msg.text is not None) and (len(str(msg.text).split()) > 2):
await destination.message(
context=msg,
text=" ".join(str(msg.text).split()[2:]),
caption=msg.caption,
photo=msg.photo,
video=msg.video,
file=msg.document,
voice=msg.voice,
animation=msg.animation,
adm_context=True,
)
elif (msg.caption is not None) and (len(msg.caption.split()) > 2):
await destination.message(
context=msg,
text=str(msg.text),
caption=" ".join(msg.caption.split()[2:]),
photo=msg.photo,
video=msg.video,
file=msg.document,
voice=msg.voice,
animation=msg.animation,
adm_context=True,
)
else:
await destination.message(context=msg, text=None, caption=None, photo=msg.photo, video=msg.video, file=msg.document, voice=msg.voice, animation=msg.animation, adm_context=True)
await destination.message(
context=msg,
text=None,
caption=None,
photo=msg.photo,
video=msg.video,
file=msg.document,
voice=msg.voice,
animation=msg.animation,
adm_context=True,
)
except IndexError:
await msg.reply_text(locale("message_invalid_syntax", "message", locale=msg.from_user), quote=should_quote(msg))
await msg.reply_text(
locale("message_invalid_syntax", "message", locale=msg.from_user),
quote=should_quote(msg),
)
logWrite(f"Admin {msg.from_user.id} tried to send message but 'IndexError'")
except ValueError:
await msg.reply_text(locale("message_invalid_syntax", "message", locale=msg.from_user), quote=should_quote(msg))
await msg.reply_text(
locale("message_invalid_syntax", "message", locale=msg.from_user),
quote=should_quote(msg),
)
logWrite(f"Admin {msg.from_user.id} tried to send message but 'ValueError'")
# ==============================================================================================================================
# ==============================================================================================================================

View File

@@ -11,50 +11,111 @@ from modules.utils import configGet, jsonLoad, locale, should_quote, find_locati
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("users", "groups")))) & filters.command(["nearby"], prefixes=["/"]) & (custom_filters.allowed | custom_filters.admin) & ~custom_filters.banned)
async def cmd_nearby(app: Client, msg: Message):
# Nearby command ===============================================================================================================
@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)
& ~custom_filters.banned
)
async def cmd_nearby(app: Client, msg: Message):
holo_user = HoloUser(msg.from_user)
# Check if any place provided
if len(msg.command) == 1: # Action if no place provided
if len(msg.command) == 1: # Action if no place provided
application = col_applications.find_one({"user": msg.from_user.id})
if application is None:
await msg.reply_text(locale("nearby_user_empty", "message", locale=holo_user))
await msg.reply_text(
locale("nearby_user_empty", "message", locale=holo_user)
)
return
location = application["application"]["3"]["location"][0], application["application"]["3"]["location"][1]
else: # Find a place from input query
location = (
application["application"]["3"]["location"][0],
application["application"]["3"]["location"][1],
)
else: # Find a place from input query
logWrite(f"Looking for the location by query '{' '.join(msg.command[1:])}'")
try:
location_coordinates = find_location(" ".join(msg.command[1:]))
location = float(location_coordinates["lng"]), float(location_coordinates["lat"])
except PlaceNotFoundError: # Place is not found
await msg.reply_text(locale("nearby_invalid", "message", locale=holo_user), quote=should_quote(msg))
location = float(location_coordinates["lng"]), float(
location_coordinates["lat"]
)
except PlaceNotFoundError: # Place is not found
await msg.reply_text(
locale("nearby_invalid", "message", locale=holo_user),
quote=should_quote(msg),
)
return
except Exception as exp: # Error occurred while finding the place
await msg.reply_text(locale("nearby_error", "message", locale=holo_user).format(exp, print_exc()), quote=should_quote(msg))
except Exception as exp: # Error occurred while finding the place
await msg.reply_text(
locale("nearby_error", "message", locale=holo_user).format(
exp, print_exc()
),
quote=should_quote(msg),
)
return
# Find all users registered in the area provided
output = []
applications_nearby = col_applications.find( {"application.3.location": { "$nearSphere": {"$geometry": {"type": "Point", "coordinates": [location[0], location[1]]}, "$maxDistance": configGet("search_radius")*1000} } } )
applications_nearby = col_applications.find(
{
"application.3.location": {
"$nearSphere": {
"$geometry": {
"type": "Point",
"coordinates": [location[0], location[1]],
},
"$maxDistance": configGet("search_radius") * 1000,
}
}
}
)
for entry in applications_nearby:
if not entry["user"] == msg.from_user.id:
user = col_users.find_one( {"user": entry["user"]} )
user = col_users.find_one({"user": entry["user"]})
if user is not None:
if entry["user"] in jsonLoad(path.join(configGet("cache", "locations"), "group_members")):
if user["tg_username"] not in [None, "None", ""]: # Check if user has any name
output.append(f'• **{user["tg_name"]}** (@{user["tg_username"]}):\n - {entry["application"]["3"]["name"]}, {entry["application"]["3"]["adminName1"]}')
if entry["user"] in jsonLoad(
path.join(configGet("cache", "locations"), "group_members")
):
if user["tg_username"] not in [
None,
"None",
"",
]: # Check if user has any name
output.append(
f'• **{user["tg_name"]}** (@{user["tg_username"]}):\n - {entry["application"]["3"]["name"]}, {entry["application"]["3"]["adminName1"]}'
)
else:
output.append(f'• **{user["tg_name"]}**:\n - {entry["application"]["3"]["name"]}, {entry["application"]["3"]["adminName1"]}')
output.append(
f'• **{user["tg_name"]}**:\n - {entry["application"]["3"]["name"]}, {entry["application"]["3"]["adminName1"]}'
)
logWrite(f"{holo_user.id} tried to find someone nearby {location[1]} {location[0]} in the radius of {configGet('search_radius')} kilometers")
logWrite(
f"{holo_user.id} tried to find someone nearby {location[1]} {location[0]} in the radius of {configGet('search_radius')} kilometers"
)
# Check if any users found
if len(output) > 0:
await msg.reply_text(locale("nearby_result", "message", locale=holo_user).format("\n".join(output)), quote=should_quote(msg))
await msg.reply_text(
locale("nearby_result", "message", locale=holo_user).format(
"\n".join(output)
),
quote=should_quote(msg),
)
else:
await msg.reply_text(locale("nearby_empty", "message", locale=holo_user), quote=should_quote(msg))
# ==============================================================================================================================
await msg.reply_text(
locale("nearby_empty", "message", locale=holo_user), quote=should_quote(msg)
)
# ==============================================================================================================================

View File

@@ -9,18 +9,32 @@ from modules.handlers.welcome import welcome_pass
from modules.database import col_tmp, col_applications
from modules import custom_filters
# Reapply command ==============================================================================================================
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(["reapply"], prefixes=["/"]) & ~custom_filters.banned)
async def cmd_reapply(app: Client, msg: Message):
# Reapply command ==============================================================================================================
@app.on_message(
custom_filters.enabled_applications
& ~filters.scheduled
& filters.private
& filters.command(["reapply"], prefixes=["/"])
& ~custom_filters.banned
)
async def cmd_reapply(app: Client, msg: Message):
holo_user = HoloUser(msg.from_user)
# Check if user has approved/rejected tmp application
if ((holo_user.application_state()[0] in ["approved", "rejected"]) or (holo_user.application_state()[0] == "none")) and holo_user.spoiler_state() is False:
if (
(holo_user.application_state()[0] in ["approved", "rejected"])
or (holo_user.application_state()[0] == "none")
) and holo_user.spoiler_state() is False:
# Check if user's tmp application is already completed or even sent
if ((holo_user.application_state()[1] is True) and (not col_tmp.find_one({"user": holo_user.id, "type": "application"})["sent"])) or (holo_user.application_state()[0] == "none"):
if (
(holo_user.application_state()[1] is True)
and (
not col_tmp.find_one({"user": holo_user.id, "type": "application"})[
"sent"
]
)
) or (holo_user.application_state()[0] == "none"):
left_chat = True
async for member in app.get_chat_members(configGet("users", "groups")):
@@ -28,64 +42,132 @@ async def cmd_reapply(app: Client, msg: Message):
left_chat = False
if left_chat is True:
if (holo_user.application_state()[1] is True and holo_user.application_state()[0] not in ["fill", "rejected"]):
if holo_user.application_state()[
1
] is True and holo_user.application_state()[0] not in [
"fill",
"rejected",
]:
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}",
)
],
]
),
)
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}")
]
]))
elif col_tmp.find_one({"user": holo_user.id, "type": "application"}) is None and col_applications.find_one({"user": holo_user.id}) is not None:
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}")
]
]))
elif (
col_tmp.find_one({"user": holo_user.id, "type": "application"})
is None
and col_applications.find_one({"user": holo_user.id}) is not None
):
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)
else:
if holo_user.sponsorship_state()[0] == "fill":
await msg.reply_text(locale("finish_sponsorship", "message"), quote=should_quote(msg))
await msg.reply_text(
locale("finish_sponsorship", "message"), quote=should_quote(msg)
)
return
holo_user.application_restart(reapply=True)
await welcome_pass(app, msg, once_again=True)
else:
await msg.reply_text(locale("reapply_in_progress", "message", locale=holo_user).format(locale("confirm", "keyboard", locale=holo_user)[1][0]), reply_markup=InlineKeyboardMarkup([
[
InlineKeyboardButton(locale("applying_stop", "button", locale=holo_user), f"reapply_stop_{msg.id}")
]
]))
await msg.reply_text(
locale("reapply_in_progress", "message", locale=holo_user).format(
locale("confirm", "keyboard", locale=holo_user)[1][0]
),
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
locale("applying_stop", "button", locale=holo_user),
f"reapply_stop_{msg.id}",
)
]
]
),
)
elif holo_user.spoiler_state() is True:
await msg.reply_text(locale("spoiler_in_progress", "message", locale=holo_user))
else:
if (holo_user.application_state()[0] == "fill") and (
col_tmp.find_one({"user": holo_user.id, "type": "application"})["sent"]
is True
):
await msg.reply_text(
locale("reapply_forbidden", "message", locale=holo_user)
)
if (holo_user.application_state()[0] == "fill") and (col_tmp.find_one({"user": holo_user.id, "type": "application"})["sent"] is True):
await msg.reply_text(locale("reapply_forbidden", "message", locale=holo_user))
else:
await msg.reply_text(locale("reapply_in_progress", "message", locale=holo_user).format(locale("confirm", "keyboard", locale=holo_user)[1][0]), reply_markup=InlineKeyboardMarkup([
[
InlineKeyboardButton(locale("applying_stop", "button", locale=holo_user), f"reapply_stop_{msg.id}")
]
]))
# ==============================================================================================================================
await msg.reply_text(
locale("reapply_in_progress", "message", locale=holo_user).format(
locale("confirm", "keyboard", locale=holo_user)[1][0]
),
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
locale("applying_stop", "button", locale=holo_user),
f"reapply_stop_{msg.id}",
)
]
]
),
)
# ==============================================================================================================================

View File

@@ -11,14 +11,28 @@ from modules import custom_filters
pid = getpid()
# Reboot command ===============================================================================================================
@app.on_message(custom_filters.enabled_general & ~filters.scheduled & filters.private & filters.command(["kill", "die", "reboot"], prefixes=["/"]) & custom_filters.admin)
async def cmd_kill(app: Client, msg: Message):
# Reboot command ===============================================================================================================
@app.on_message(
custom_filters.enabled_general
& ~filters.scheduled
& filters.private
& filters.command(["kill", "die", "reboot"], prefixes=["/"])
& custom_filters.admin
)
async def cmd_kill(app: Client, msg: Message):
logWrite(f"Shutting down bot with pid {pid}")
await msg.reply_text(locale("shutdown", "message", locale=msg.from_user).format(pid), quote=should_quote(msg))
await msg.reply_text(
locale("shutdown", "message", locale=msg.from_user).format(pid),
quote=should_quote(msg),
)
scheduler.shutdown()
makedirs(configGet("cache", "locations"), exist_ok=True)
jsonSave({"timestamp": time()}, path.join(configGet("cache", "locations"), "shutdown_time"))
jsonSave(
{"timestamp": time()},
path.join(configGet("cache", "locations"), "shutdown_time"),
)
exit()
# ==============================================================================================================================
# ==============================================================================================================================

View File

@@ -9,40 +9,65 @@ from modules import custom_filters
pid = getpid()
# Reset commands command =======================================================================================================
@app.on_message(custom_filters.enabled_general & ~filters.scheduled & filters.private & filters.command(["resetcommands"], prefixes=["/"]) & custom_filters.admin)
@app.on_message(
custom_filters.enabled_general
& ~filters.scheduled
& filters.private
& filters.command(["resetcommands"], prefixes=["/"])
& custom_filters.admin
)
async def cmd_resetcommands(app: Client, msg: Message):
if msg.from_user.id == configGet("owner"):
logWrite(f"Resetting all commands on owner's request")
valid_locales = []
files_locales = listdir(f'{configGet("locale", "locations")}')
for entry in files_locales:
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)
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("admin", "groups")))
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("users", "groups")))
logWrite(
f'Resetting commands in groups {configGet("admin", "groups")} and {configGet("users", "groups")}',
debug=True,
)
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 lc in valid_locales:
try:
logWrite(f'Resetting commands in groups {configGet("admin", "groups")} and {configGet("users", "groups")} [{lc}]', debug=True)
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("admin", "groups")), language_code=lc)
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=configGet("users", "groups")), language_code=lc)
logWrite(
f'Resetting commands in groups {configGet("admin", "groups")} and {configGet("users", "groups")} [{lc}]',
debug=True,
)
await app.delete_bot_commands(
scope=BotCommandScopeChat(chat_id=configGet("admin", "groups")),
language_code=lc,
)
await app.delete_bot_commands(
scope=BotCommandScopeChat(chat_id=configGet("users", "groups")),
language_code=lc,
)
except:
pass
for admin in configGet("admins"):
try:
logWrite(f'Resetting commands for admin {admin}', debug=True)
logWrite(f"Resetting commands for admin {admin}", debug=True)
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=admin))
for lc in valid_locales:
try:
logWrite(f'Resetting commands for admin {admin} [{lc}]', debug=True)
await app.delete_bot_commands(scope=BotCommandScopeChat(chat_id=admin), language_code=lc)
logWrite(
f"Resetting commands for admin {admin} [{lc}]", debug=True
)
await app.delete_bot_commands(
scope=BotCommandScopeChat(chat_id=admin), language_code=lc
)
except:
pass
except bad_request_400.PeerIdInvalid:
@@ -51,21 +76,40 @@ async def cmd_resetcommands(app: Client, msg: Message):
try:
logWrite(f'Resetting commands for owner {configGet("owner")}', debug=True)
for lc in valid_locales:
logWrite(f'Resetting commands for owner {configGet("owner")} [{lc}]', debug=True)
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")))
logWrite(
f'Resetting commands for owner {configGet("owner")} [{lc}]',
debug=True,
)
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)
await app.delete_bot_commands(scope=BotCommandScopeDefault(), language_code=lc)
logWrite(f"Resetting commands for locale {lc}", debug=True)
await app.delete_bot_commands(
scope=BotCommandScopeDefault(), language_code=lc
)
logWrite(f'Resetting default commands', debug=True)
logWrite(f"Resetting default commands", debug=True)
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)
# ==============================================================================================================================
logWrite(
str(
await app.get_bot_commands(
scope=BotCommandScopeChat(chat_id=configGet("owner"))
)
),
debug=True,
)
# ==============================================================================================================================

View File

@@ -7,36 +7,55 @@ from modules.utils import locale
from modules import custom_filters
from classes.holo_user import HoloUser
class DefaultRulesMarkup(list):
def __init__(self, language_code: Union[str, HoloUser, User, None]):
super().__init__([])
self.keyboard = InlineKeyboardMarkup(
[
[
InlineKeyboardButton(locale("rules_home", "button", locale=language_code), callback_data="rules_home"),
InlineKeyboardButton(locale("rules_additional", "button", locale=language_code), callback_data="rules_additional")
InlineKeyboardButton(
locale("rules_home", "button", locale=language_code),
callback_data="rules_home",
),
InlineKeyboardButton(
locale("rules_additional", "button", locale=language_code),
callback_data="rules_additional",
),
],
[
InlineKeyboardButton("1", callback_data="rule_1"),
InlineKeyboardButton("2", callback_data="rule_2"),
InlineKeyboardButton("3", callback_data="rule_3")
InlineKeyboardButton("3", callback_data="rule_3"),
],
[
InlineKeyboardButton("4", callback_data="rule_4"),
InlineKeyboardButton("5", callback_data="rule_5"),
InlineKeyboardButton("6", callback_data="rule_6")
InlineKeyboardButton("6", callback_data="rule_6"),
],
[
InlineKeyboardButton("7", callback_data="rule_7"),
InlineKeyboardButton("8", callback_data="rule_8"),
InlineKeyboardButton("9", callback_data="rule_9")
]
InlineKeyboardButton("9", callback_data="rule_9"),
],
]
)
# Rules command =============================================================================================================
@app.on_message(custom_filters.enabled_general & ~filters.scheduled & filters.private & ~custom_filters.banned & filters.command(["rules"], prefixes=["/"]))
@app.on_message(
custom_filters.enabled_general
& ~filters.scheduled
& filters.private
& ~custom_filters.banned
& filters.command(["rules"], prefixes=["/"])
)
async def cmd_rules(app: Client, msg: Message):
await msg.reply_text(locale("rules_msg", locale=msg.from_user), disable_web_page_preview=True, reply_markup=DefaultRulesMarkup(msg.from_user).keyboard)
# ==============================================================================================================================
await msg.reply_text(
locale("rules_msg", locale=msg.from_user),
disable_web_page_preview=True,
reply_markup=DefaultRulesMarkup(msg.from_user).keyboard,
)
# ==============================================================================================================================

View File

@@ -9,24 +9,30 @@ from modules.utils import locale
from modules.database import col_spoilers, col_applications
from modules import custom_filters
# Spoiler command ==============================================================================================================
@app.on_message(custom_filters.enabled_spoilers & ~filters.scheduled & filters.private & ~custom_filters.banned & filters.command(["spoiler"], prefixes=["/"]))
async def cmd_spoiler(app: Client, msg: Message):
# Spoiler command ==============================================================================================================
@app.on_message(
custom_filters.enabled_spoilers
& ~filters.scheduled
& filters.private
& ~custom_filters.banned
& filters.command(["spoiler"], prefixes=["/"])
)
async def cmd_spoiler(app: Client, msg: Message):
try:
holo_user = HoloUser(msg.from_user)
except (UserInvalidError, UserNotFoundError):
return
if col_applications.find_one( {"user": holo_user.id} ) is None:
if col_applications.find_one({"user": holo_user.id}) is None:
await msg.reply_text(locale("not_member", "message", locale=msg.from_user))
return
if holo_user.application_state()[0] != "fill" and holo_user.sponsorship_state()[0] != "fill":
if col_spoilers.find_one( {"user": holo_user.id, "completed": False} ) is None:
if (
holo_user.application_state()[0] != "fill"
and holo_user.sponsorship_state()[0] != "fill"
):
if col_spoilers.find_one({"user": holo_user.id, "completed": False}) is None:
col_spoilers.insert_one(
{
"user": holo_user.id,
@@ -39,13 +45,24 @@ async def cmd_spoiler(app: Client, msg: Message):
"animation": None,
"document": None,
"caption": None,
"text": None
"text": None,
}
)
await msg.reply_text(locale("spoiler_started", "message", locale=msg.from_user), reply_markup=ReplyKeyboardMarkup(locale("spoiler_categories", "keyboard"), resize_keyboard=True, one_time_keyboard=True))
await msg.reply_text(
locale("spoiler_started", "message", locale=msg.from_user),
reply_markup=ReplyKeyboardMarkup(
locale("spoiler_categories", "keyboard"),
resize_keyboard=True,
one_time_keyboard=True,
),
)
logWrite(f"User {msg.from_user.id} started creating new spoiler")
else:
await msg.reply_text(locale("spoiler_unfinished", "message", locale=msg.from_user))
# ==============================================================================================================================
await msg.reply_text(
locale("spoiler_unfinished", "message", locale=msg.from_user)
)
# ==============================================================================================================================

View File

@@ -7,17 +7,44 @@ from modules import custom_filters
from modules.utils import locale, should_quote
from modules.database import col_applications
# Sponsorship command ==========================================================================================================
@app.on_message(custom_filters.enabled_sponsorships & ~filters.scheduled & filters.command(["sponsorship"], prefixes=["/"]) & ~custom_filters.banned & (custom_filters.allowed | custom_filters.admin))
@app.on_message(
custom_filters.enabled_sponsorships
& ~filters.scheduled
& filters.command(["sponsorship"], prefixes=["/"])
& ~custom_filters.banned
& (custom_filters.allowed | custom_filters.admin)
)
async def cmd_sponsorship(app: Client, msg: Message):
holo_user = HoloUser(msg.from_user)
if holo_user.application_state()[0] == "fill":
await msg.reply_text(locale("finish_application", "message", locale=msg.from_user), quote=should_quote(msg))
await msg.reply_text(
locale("finish_application", "message", locale=msg.from_user),
quote=should_quote(msg),
)
return
if holo_user.spoiler_state() is True:
await msg.reply_text(locale("spoiler_in_progress", "message", locale=holo_user))
return
await msg.reply_text(locale("sponsorship_apply", "message", locale=msg.from_user), reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton(text=str(locale("sponsor_apply", "button", locale=msg.from_user)), callback_data=f"sponsor_apply_{msg.from_user.id}")]]), quote=should_quote(msg))
await msg.reply_text(
locale("sponsorship_apply", "message", locale=msg.from_user),
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
text=str(
locale("sponsor_apply", "button", locale=msg.from_user)
),
callback_data=f"sponsor_apply_{msg.from_user.id}",
)
]
]
),
quote=should_quote(msg),
)
# else:
# await msg.reply_text(locale("sponsorship_application_empty", "message"))
# ==============================================================================================================================
# ==============================================================================================================================

View File

@@ -8,42 +8,67 @@ from modules import custom_filters
from bson.objectid import ObjectId
from bson.errors import InvalidId
# Start command ================================================================================================================
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(["start"], prefixes=["/"]) & ~custom_filters.banned)
async def cmd_start(app: Client, msg: Message):
# Start command ================================================================================================================
@app.on_message(
custom_filters.enabled_applications
& ~filters.scheduled
& filters.private
& filters.command(["start"], prefixes=["/"])
& ~custom_filters.banned
)
async def cmd_start(app: Client, msg: Message):
user = col_users.find_one({"user": msg.from_user.id})
if user is None:
col_users.insert_one({
"user": msg.from_user.id,
"link": None,
"label": "",
"tg_name": msg.from_user.first_name,
"tg_phone": msg.from_user.phone_number,
"tg_locale": msg.from_user.language_code,
"tg_username": msg.from_user.username
})
col_users.insert_one(
{
"user": msg.from_user.id,
"link": None,
"label": "",
"tg_name": msg.from_user.first_name,
"tg_phone": msg.from_user.phone_number,
"tg_locale": msg.from_user.language_code,
"tg_username": msg.from_user.username,
}
)
logWrite(f"User {msg.from_user.id} started bot interaction")
await msg.reply_text(locale("start", "message", locale=msg.from_user), reply_markup=ReplyKeyboardMarkup(locale("welcome", "keyboard", locale=msg.from_user), resize_keyboard=True))
await msg.reply_text(
locale("start", "message", locale=msg.from_user),
reply_markup=ReplyKeyboardMarkup(
locale("welcome", "keyboard", locale=msg.from_user),
resize_keyboard=True,
),
)
if len(msg.command) > 1:
try:
spoiler = col_spoilers.find_one( {"_id": ObjectId(msg.command[1])} )
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_cached_media(
spoiler["photo"], caption=spoiler["caption"]
)
if spoiler["video"] is not None:
await msg.reply_cached_media(spoiler["video"], caption=spoiler["caption"])
await msg.reply_cached_media(
spoiler["video"], caption=spoiler["caption"]
)
if spoiler["audio"] is not None:
await msg.reply_cached_media(spoiler["audio"], caption=spoiler["caption"])
await msg.reply_cached_media(
spoiler["audio"], caption=spoiler["caption"]
)
if spoiler["animation"] is not None:
await msg.reply_cached_media(spoiler["animation"], caption=spoiler["caption"])
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_cached_media(
spoiler["document"], caption=spoiler["caption"]
)
if spoiler["text"] is not None:
await msg.reply_text(spoiler["text"])
except InvalidId:
await msg.reply_text(f"Got an invalid ID {msg.command[1]}")
# ==============================================================================================================================
# ==============================================================================================================================

View File

@@ -7,16 +7,41 @@ from modules.utils import configGet, locale
from modules.database import col_warnings
from modules import custom_filters
# Warn command =================================================================================================================
@app.on_message(custom_filters.enabled_warnings & ~filters.scheduled & filters.command(["warn"], prefixes=["/"]) & custom_filters.admin)
async def cmd_warn(app: Client, msg: Message):
# Warn command =================================================================================================================
@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("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})
col_warnings.insert_one(
{
"user": msg.reply_to_message.from_user.id,
"admin": msg.from_user.id,
"date": datetime.now(),
"reason": message,
}
)
if message == "":
await msg.reply_text(locale("warned", "message").format(msg.reply_to_message.from_user.first_name, msg.reply_to_message.from_user.id))
await msg.reply_text(
locale("warned", "message").format(
msg.reply_to_message.from_user.first_name,
msg.reply_to_message.from_user.id,
)
)
else:
await msg.reply_text(locale("warned_reason", "message").format(msg.reply_to_message.from_user.first_name, msg.reply_to_message.from_user.id, message))
# ==============================================================================================================================
await msg.reply_text(
locale("warned_reason", "message").format(
msg.reply_to_message.from_user.first_name,
msg.reply_to_message.from_user.id,
message,
)
)
# ==============================================================================================================================

View File

@@ -7,12 +7,20 @@ from modules.utils import configGet, locale, should_quote
from modules.database import col_users, col_warnings
from modules import custom_filters
# Warnings command =============================================================================================================
@app.on_message(custom_filters.enabled_warnings & ~filters.scheduled & filters.command(["warnings"], prefixes=["/"]) & custom_filters.admin)
async def cmd_warnings(app: Client, msg: Message):
# Warnings command =============================================================================================================
@app.on_message(
custom_filters.enabled_warnings
& ~filters.scheduled
& filters.command(["warnings"], prefixes=["/"])
& custom_filters.admin
)
async def cmd_warnings(app: Client, msg: Message):
if len(msg.command) <= 1:
await msg.reply_text(locale("syntax_warnings", "message", locale=msg.from_user), quote=should_quote(msg))
await msg.reply_text(
locale("syntax_warnings", "message", locale=msg.from_user),
quote=should_quote(msg),
)
return
try:
@@ -21,7 +29,11 @@ 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("users", "groups"), 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:
@@ -29,16 +41,37 @@ async def cmd_warnings(app: Client, msg: Message):
target_name = target.first_name
target_id = str(target.id)
else:
await msg.reply_text(locale("no_user_warnings", "message", locale=msg.from_user).format(msg.command[1]))
await msg.reply_text(
locale("no_user_warnings", "message", locale=msg.from_user).format(
msg.command[1]
)
)
return
warns = len(list(col_warnings.find({"user": target_id})))
if warns == 0:
await msg.reply_text(locale("no_warnings", "message", locale=msg.from_user).format(target_name, target_id), quote=should_quote(msg))
await msg.reply_text(
locale("no_warnings", "message", locale=msg.from_user).format(
target_name, target_id
),
quote=should_quote(msg),
)
else:
if warns <= 5:
await msg.reply_text(locale("warnings_1", "message", locale=msg.from_user).format(target_name, target_id, warns), quote=should_quote(msg))
await msg.reply_text(
locale("warnings_1", "message", locale=msg.from_user).format(
target_name, target_id, warns
),
quote=should_quote(msg),
)
else:
await msg.reply_text(locale("warnings_2", "message", locale=msg.from_user).format(target_name, target_id, warns), quote=should_quote(msg))
# ==============================================================================================================================
await msg.reply_text(
locale("warnings_2", "message", locale=msg.from_user).format(
target_name, target_id, warns
),
quote=should_quote(msg),
)
# ==============================================================================================================================