Modularity overhaul
This commit is contained in:
9
modules/callbacks/nothing.py
Normal file
9
modules/callbacks/nothing.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from app import app
|
||||
from pyrogram import filters
|
||||
from modules.utils import locale
|
||||
|
||||
# Callback empty ===============================================================================================================
|
||||
@app.on_callback_query(filters.regex("nothing")) # type: ignore
|
||||
async def callback_query_nothing(app, clb):
|
||||
await clb.answer(text=locale("nothing", "callback"))
|
||||
# ==============================================================================================================================
|
126
modules/callbacks/reapply.py
Normal file
126
modules/callbacks/reapply.py
Normal file
@@ -0,0 +1,126 @@
|
||||
from os import sep
|
||||
from time import time
|
||||
from app import app
|
||||
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
||||
from modules.utils import configGet, configSet, jsonLoad, jsonSave, locale, logWrite
|
||||
from modules.handlers.confirmation import confirm_yes
|
||||
from modules.handlers.welcome import welcome_pass
|
||||
|
||||
# Callbacks reapply ============================================================================================================
|
||||
@app.on_callback_query(filters.regex("reapply_yes_[\s\S]*")) # type: ignore
|
||||
async def callback_reapply_query_accept(app, clb):
|
||||
|
||||
fullclb = clb.data.split("_")
|
||||
|
||||
await app.send_message(configGet("admin_group"), locale("approved_by", "message").format(clb.from_user.first_name, fullclb[2]), disable_notification=True) # type: ignore
|
||||
logWrite(f"User {fullclb[2]} got their reapplication approved by {clb.from_user.id}")
|
||||
|
||||
await app.send_message(int(fullclb[2]), locale("approved_joined", "message"))
|
||||
|
||||
configSet(["approved"], True, file=fullclb[2])
|
||||
configSet(["sent"], False, file=fullclb[2])
|
||||
|
||||
application = jsonLoad(f"{configGet('data', 'locations')}{sep}applications.json")
|
||||
application[fullclb[2]]["approved"] = True
|
||||
application[fullclb[2]]["approved_by"] = clb.from_user.id
|
||||
application[fullclb[2]]["approval_date"] = int(time())
|
||||
jsonSave(application, f"{configGet('data', 'locations')}{sep}applications.json")
|
||||
|
||||
edited_markup = [[InlineKeyboardButton(text=str(locale("accepted", "button")), callback_data="nothing")]]
|
||||
|
||||
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||
await clb.answer(text=locale("sub_accepted", "callback").format(fullclb[2]), show_alert=True) # type: ignore
|
||||
|
||||
need_link = True
|
||||
|
||||
async for member in app.get_chat_members(configGet("destination_group")):
|
||||
if member.user.id == int(fullclb[2]):
|
||||
need_link = False
|
||||
|
||||
if need_link:
|
||||
link = await app.create_chat_invite_link(configGet("destination_group"), name=f"Invite for {fullclb[2]}", member_limit=1) #, expire_date=datetime.now()+timedelta(days=1))
|
||||
|
||||
await app.send_message(int(fullclb[2]), locale("read_rules", "message"))
|
||||
|
||||
for rule_msg in locale("rules"):
|
||||
await app.send_message(int(fullclb[2]), rule_msg)
|
||||
|
||||
await app.send_message(int(fullclb[2]), locale("approved", "message"), reply_markup=InlineKeyboardMarkup(
|
||||
[[
|
||||
InlineKeyboardButton(str(locale("join", "button")), url=link.invite_link)
|
||||
]]
|
||||
))
|
||||
|
||||
configSet(["link"], link.invite_link, file=fullclb[2])
|
||||
logWrite(f"User {fullclb[2]} got an invite link {link.invite_link}")
|
||||
|
||||
else:
|
||||
await app.send_message(int(fullclb[2]), locale("approved_joined", "message"))
|
||||
|
||||
@app.on_callback_query(filters.regex("reapply_no_[\s\S]*")) # type: ignore
|
||||
async def callback_query_reapply_refuse(app, clb):
|
||||
|
||||
fullclb = clb.data.split("_")
|
||||
|
||||
await app.send_message(configGet("admin_group"), locale("refused_by", "message").format(clb.from_user.first_name, fullclb[2]), disable_notification=True) # type: ignore
|
||||
await app.send_message(int(fullclb[2]), locale("refused", "message"))
|
||||
logWrite(f"User {fullclb[2]} got their reapplication refused by {clb.from_user.id}")
|
||||
|
||||
configSet(["refused"], True, file=fullclb[2])
|
||||
configSet(["sent"], False, file=fullclb[2])
|
||||
|
||||
application = jsonLoad(f"{configGet('data', 'locations')}{sep}applications.json")
|
||||
application[fullclb[2]]["refused"] = True
|
||||
application[fullclb[2]]["refused_by"] = clb.from_user.id
|
||||
application[fullclb[2]]["refusal_date"] = int(time())
|
||||
jsonSave(application, f"{configGet('data', 'locations')}{sep}applications.json")
|
||||
|
||||
edited_markup = [[InlineKeyboardButton(text=str(locale("declined", "button")), callback_data="nothing")]]
|
||||
|
||||
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||
await clb.answer(text=locale("sub_refused", "callback").format(fullclb[2]), show_alert=True) # type: ignore
|
||||
|
||||
# Use old application when user reapplies after leaving the chat
|
||||
@app.on_callback_query(filters.regex("reapply_old_[\s\S]*")) # type: ignore
|
||||
async def callback_query_reapply_old(app, clb):
|
||||
fullclb = clb.data.split("_")
|
||||
message = await app.get_messages(clb.from_user.id, int(fullclb[2]))
|
||||
configSet(["approved"], False, file=str(clb.from_user.id))
|
||||
configSet(["refused"], False, file=str(clb.from_user.id))
|
||||
await confirm_yes(app, message)
|
||||
await clb.message.edit(clb.message.text, reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton(locale("done", "button"), "nothing")]]))
|
||||
|
||||
# Start a new application when user reapplies after leaving the chat
|
||||
@app.on_callback_query(filters.regex("reapply_new_[\s\S]*")) # type: ignore
|
||||
async def callback_query_reapply_new(app, clb):
|
||||
|
||||
fullclb = clb.data.split("_")
|
||||
|
||||
jsonSave(jsonLoad(f"{configGet('data', 'locations')}{sep}user_default.json"), f"{configGet('data', 'locations')}{sep}users{sep}{clb.from_user.id}.json")
|
||||
configSet(["telegram_id"], str(clb.from_user.username), file=str(clb.from_user.id))
|
||||
configSet(["telegram_name"], f"{clb.from_user.first_name} {clb.from_user.last_name}", file=str(clb.from_user.id))
|
||||
configSet(["telegram_phone"], str(clb.from_user.phone_number), file=str(clb.from_user.id))
|
||||
configSet(["telegram_locale"], str(clb.from_user.language_code), file=str(clb.from_user.id))
|
||||
await clb.answer(locale("reapply_stopped", "callback"))
|
||||
message = await app.get_messages(clb.from_user.id, int(fullclb[2]))
|
||||
await welcome_pass(app, message, once_again=True)
|
||||
logWrite(f"User {clb.from_user.id} restarted the application after leaving the chat earlier")
|
||||
await clb.message.edit(clb.message.text, reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton(locale("done", "button"), "nothing")]]))
|
||||
|
||||
# Abort application fill in progress and restart it
|
||||
@app.on_callback_query(filters.regex("reapply_stop_[\s\S]*")) # type: ignore
|
||||
async def callback_query_reapply_stop(app, clb):
|
||||
|
||||
fullclb = clb.data.split("_")
|
||||
|
||||
jsonSave(jsonLoad(f"{configGet('data', 'locations')}{sep}user_default.json"), f"{configGet('data', 'locations')}{sep}users{sep}{clb.from_user.id}.json")
|
||||
configSet(["telegram_id"], str(clb.from_user.username), file=str(clb.from_user.id))
|
||||
configSet(["telegram_name"], f"{clb.from_user.first_name} {clb.from_user.last_name}", file=str(clb.from_user.id))
|
||||
configSet(["telegram_phone"], str(clb.from_user.phone_number), file=str(clb.from_user.id))
|
||||
configSet(["telegram_locale"], str(clb.from_user.language_code), file=str(clb.from_user.id))
|
||||
await clb.answer(locale("reapply_stopped", "callback"))
|
||||
message = await app.get_messages(clb.from_user.id, int(fullclb[2]))
|
||||
await welcome_pass(app, message, once_again=True)
|
||||
logWrite(f"User {clb.from_user.id} restarted the application due to typo in it")
|
||||
await clb.message.edit(clb.message.text, reply_markup=None)
|
||||
# ==============================================================================================================================
|
70
modules/callbacks/rules.py
Normal file
70
modules/callbacks/rules.py
Normal file
@@ -0,0 +1,70 @@
|
||||
from app import app
|
||||
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
||||
from pyrogram.errors import bad_request_400
|
||||
from modules.utils import locale, logWrite
|
||||
from modules.commands.rules import default_rules_markup
|
||||
|
||||
# Callback rule ================================================================================================================
|
||||
@app.on_callback_query(filters.regex("rule_[\s\S]*")) # type: ignore
|
||||
async def callback_query_rule(app, clb):
|
||||
|
||||
fullclb = clb.data.split("_")
|
||||
|
||||
logWrite(f"User {clb.from_user.id} requested to check out rule {fullclb[1]}")
|
||||
|
||||
rule_num = int(fullclb[1])
|
||||
|
||||
if rule_num == len(locale("rules")):
|
||||
lower_buttons = [
|
||||
InlineKeyboardButton(locale("rules_prev", "button"), callback_data=f"rule_{rule_num-1}")
|
||||
]
|
||||
elif rule_num == 1:
|
||||
lower_buttons = [
|
||||
InlineKeyboardButton(locale("rules_next", "button"), callback_data=f"rule_{rule_num+1}")
|
||||
]
|
||||
else:
|
||||
lower_buttons = [
|
||||
InlineKeyboardButton(locale("rules_prev", "button"), callback_data=f"rule_{rule_num-1}"),
|
||||
InlineKeyboardButton(locale("rules_next", "button"), callback_data=f"rule_{rule_num+1}")
|
||||
]
|
||||
|
||||
try:
|
||||
await clb.message.edit(text=locale("rules")[rule_num-1], disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton(locale("rules_home", "button"), callback_data="rules_home"),
|
||||
InlineKeyboardButton(locale("rules_additional", "button"), callback_data="rules_additional")
|
||||
],
|
||||
lower_buttons
|
||||
]
|
||||
)
|
||||
)
|
||||
except bad_request_400.MessageNotModified:
|
||||
pass
|
||||
|
||||
await clb.answer(text=locale("rules_page", "callback").format(fullclb[1])) # type: ignore
|
||||
|
||||
@app.on_callback_query(filters.regex("rules_home")) # type: ignore
|
||||
async def callback_query_rules_home(app, clb):
|
||||
|
||||
logWrite(f"User {clb.from_user.id} requested to check out homepage rules")
|
||||
|
||||
try:
|
||||
await clb.message.edit(text=locale("rules_msg"), disable_web_page_preview=True, reply_markup=default_rules_markup)
|
||||
except bad_request_400.MessageNotModified:
|
||||
pass
|
||||
|
||||
await clb.answer(text=locale("rules_home", "callback")) # type: ignore
|
||||
|
||||
@app.on_callback_query(filters.regex("rules_additional")) # type: ignore
|
||||
async def callback_query_rules_additional(app, clb):
|
||||
|
||||
logWrite(f"User {clb.from_user.id} requested to check out additional rules")
|
||||
|
||||
try:
|
||||
await clb.message.edit(text=locale("rules_additional"), disable_web_page_preview=True, reply_markup=default_rules_markup)
|
||||
except bad_request_400.MessageNotModified:
|
||||
pass
|
||||
|
||||
await clb.answer(text=locale("rules_additional", "callback")) # type: ignore
|
||||
# ==============================================================================================================================
|
125
modules/callbacks/sub.py
Normal file
125
modules/callbacks/sub.py
Normal file
@@ -0,0 +1,125 @@
|
||||
from os import sep
|
||||
from time import time
|
||||
from app import app
|
||||
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
||||
from modules.utils import configGet, configSet, jsonLoad, jsonSave, locale, logWrite
|
||||
|
||||
# Callbacks application ========================================================================================================
|
||||
@app.on_callback_query(filters.regex("sub_yes_[\s\S]*")) # type: ignore
|
||||
async def callback_query_accept(app, clb):
|
||||
|
||||
fullclb = clb.data.split("_")
|
||||
|
||||
await app.send_message(configGet("admin_group"), locale("approved_by", "message").format(clb.from_user.first_name, fullclb[2]), disable_notification=True) # type: ignore
|
||||
logWrite(f"User {fullclb[2]} got approved by {clb.from_user.id}")
|
||||
|
||||
need_link = True
|
||||
|
||||
async for member in app.get_chat_members(configGet("destination_group")):
|
||||
if member.user.id == int(fullclb[2]):
|
||||
need_link = False
|
||||
|
||||
if need_link:
|
||||
link = await app.create_chat_invite_link(configGet("destination_group"), name=f"Invite for {fullclb[2]}", member_limit=1) #, expire_date=datetime.now()+timedelta(days=1))
|
||||
|
||||
await app.send_message(int(fullclb[2]), locale("read_rules", "message"))
|
||||
|
||||
for rule_msg in locale("rules"):
|
||||
await app.send_message(int(fullclb[2]), rule_msg)
|
||||
|
||||
await app.send_message(int(fullclb[2]), locale("approved", "message"), reply_markup=InlineKeyboardMarkup(
|
||||
[[
|
||||
InlineKeyboardButton(str(locale("join", "button")), url=link.invite_link)
|
||||
]]
|
||||
))
|
||||
|
||||
configSet(["link"], link.invite_link, file=fullclb[2])
|
||||
logWrite(f"User {fullclb[2]} got an invite link {link.invite_link}")
|
||||
|
||||
else:
|
||||
await app.send_message(int(fullclb[2]), locale("approved_joined", "message"))
|
||||
|
||||
configSet(["approved"], True, file=fullclb[2])
|
||||
configSet(["sent"], False, file=fullclb[2])
|
||||
|
||||
application = jsonLoad(f"{configGet('data', 'locations')}{sep}applications.json")
|
||||
application[fullclb[2]]["approved"] = True
|
||||
application[fullclb[2]]["approved_by"] = clb.from_user.id
|
||||
application[fullclb[2]]["approval_date"] = int(time())
|
||||
jsonSave(application, f"{configGet('data', 'locations')}{sep}applications.json")
|
||||
|
||||
edited_markup = [[InlineKeyboardButton(text=str(locale("accepted", "button")), callback_data="nothing")]]
|
||||
|
||||
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||
await clb.answer(text=locale("sub_accepted", "callback").format(fullclb[2]), show_alert=True) # type: ignore
|
||||
|
||||
@app.on_callback_query(filters.regex("sub_no_aggressive_[\s\S]*")) # type: ignore
|
||||
async def callback_query_refuse_aggressive(app, clb):
|
||||
|
||||
fullclb = clb.data.split("_")
|
||||
|
||||
await app.send_message(configGet("admin_group"), locale("refused_by_agr", "message").format(clb.from_user.first_name, fullclb[3]), disable_notification=True) # type: ignore
|
||||
await app.send_message(int(fullclb[3]), locale("refused", "message"))
|
||||
logWrite(f"User {fullclb[3]} got refused by {clb.from_user.id} due to being aggressive")
|
||||
|
||||
configSet(["refused"], True, file=fullclb[3])
|
||||
configSet(["sent"], False, file=fullclb[3])
|
||||
|
||||
application = jsonLoad(f"{configGet('data', 'locations')}{sep}applications.json")
|
||||
application[fullclb[3]]["refused"] = True
|
||||
application[fullclb[3]]["refused_by"] = clb.from_user.id
|
||||
application[fullclb[3]]["refusal_date"] = int(time())
|
||||
jsonSave(application, f"{configGet('data', 'locations')}{sep}applications.json")
|
||||
|
||||
edited_markup = [[InlineKeyboardButton(text=str(locale("declined", "button")), callback_data="nothing")]]
|
||||
|
||||
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||
await clb.answer(text=locale("sub_no_aggressive", "callback").format(fullclb[3]), show_alert=True) # type: ignore
|
||||
|
||||
@app.on_callback_query(filters.regex("sub_no_russian_[\s\S]*")) # type: ignore
|
||||
async def callback_query_refuse_russian(app, clb):
|
||||
|
||||
fullclb = clb.data.split("_")
|
||||
|
||||
await app.send_message(configGet("admin_group"), locale("refused_by_rus", "message").format(clb.from_user.first_name, fullclb[3]), disable_notification=True) # type: ignore
|
||||
await app.send_message(int(fullclb[3]), locale("refused", "message"))
|
||||
await app.send_message(int(fullclb[3]), locale("refused_russian", "message"))
|
||||
logWrite(f"User {fullclb[3]} got refused by {clb.from_user.id} due to being russian")
|
||||
|
||||
configSet(["refused"], True, file=fullclb[3])
|
||||
configSet(["sent"], False, file=fullclb[3])
|
||||
|
||||
application = jsonLoad(f"{configGet('data', 'locations')}{sep}applications.json")
|
||||
application[fullclb[3]]["refused"] = True
|
||||
application[fullclb[3]]["refused_by"] = clb.from_user.id
|
||||
application[fullclb[3]]["refusal_date"] = int(time())
|
||||
jsonSave(application, f"{configGet('data', 'locations')}{sep}applications.json")
|
||||
|
||||
edited_markup = [[InlineKeyboardButton(text=str(locale("declined", "button")), callback_data="nothing")]]
|
||||
|
||||
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||
await clb.answer(text=locale("sub_no_russian", "callback").format(fullclb[3]), show_alert=True) # type: ignore
|
||||
|
||||
@app.on_callback_query(filters.regex("sub_no_[\s\S]*")) # type: ignore
|
||||
async def callback_query_refuse(app, clb):
|
||||
|
||||
fullclb = clb.data.split("_")
|
||||
|
||||
await app.send_message(configGet("admin_group"), locale("refused_by", "message").format(clb.from_user.first_name, fullclb[2]), disable_notification=True) # type: ignore
|
||||
await app.send_message(int(fullclb[2]), locale("refused", "message"))
|
||||
logWrite(f"User {fullclb[2]} got refused by {clb.from_user.id}")
|
||||
|
||||
configSet(["refused"], True, file=fullclb[2])
|
||||
configSet(["sent"], False, file=fullclb[2])
|
||||
|
||||
application = jsonLoad(f"{configGet('data', 'locations')}{sep}applications.json")
|
||||
application[fullclb[2]]["refused"] = True
|
||||
application[fullclb[2]]["refused_by"] = clb.from_user.id
|
||||
application[fullclb[2]]["refusal_date"] = int(time())
|
||||
jsonSave(application, f"{configGet('data', 'locations')}{sep}applications.json")
|
||||
|
||||
edited_markup = [[InlineKeyboardButton(text=str(locale("declined", "button")), callback_data="nothing")]]
|
||||
|
||||
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||
await clb.answer(text=locale("sub_refused", "callback").format(fullclb[2]), show_alert=True) # type: ignore
|
||||
# ==============================================================================================================================
|
47
modules/callbacks/sus.py
Normal file
47
modules/callbacks/sus.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from os import sep
|
||||
from app import app
|
||||
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ChatPermissions
|
||||
from modules.utils import configGet, configSet, jsonLoad, jsonSave, locale, logWrite
|
||||
|
||||
# Callbacks sus users ==========================================================================================================
|
||||
@app.on_callback_query(filters.regex("sus_allow_[\s\S]*")) # type: ignore
|
||||
async def callback_query_sus_allow(app, clb):
|
||||
|
||||
fullclb = clb.data.split("_")
|
||||
|
||||
await app.send_message(configGet("admin_group"), locale("sus_allowed_by", "message").format(clb.from_user.first_name, fullclb[2]), disable_notification=True) # type: ignore
|
||||
logWrite(f"User {fullclb[2]} was allowed to join with another link by {clb.from_user.id}")
|
||||
|
||||
edited_markup = [[InlineKeyboardButton(text=str(locale("sus_allowed", "button")), callback_data="nothing")]]
|
||||
|
||||
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||
await clb.answer(text=locale("sus_allowed", "callback").format(fullclb[2]), show_alert=True) # type: ignore
|
||||
|
||||
await app.restrict_chat_member(configGet("destination_group"), int(fullclb[2]), permissions=ChatPermissions(
|
||||
can_send_messages=True,
|
||||
can_send_media_messages=True,
|
||||
can_send_other_messages=True,
|
||||
can_send_polls=True
|
||||
)
|
||||
)
|
||||
|
||||
@app.on_callback_query(filters.regex("sus_refuse_[\s\S]*")) # type: ignore
|
||||
async def callback_query_sus_refuse(app, clb):
|
||||
|
||||
fullclb = clb.data.split("_")
|
||||
|
||||
await app.send_message(configGet("admin_group"), locale("sus_refused_by", "message").format(clb.from_user.first_name, fullclb[2]), disable_notification=True) # type: ignore
|
||||
logWrite(f"User {fullclb[2]} was refused to join with another link by {clb.from_user.id}")
|
||||
|
||||
edited_markup = [[InlineKeyboardButton(text=str(locale("sus_refused", "button")), callback_data="nothing")]]
|
||||
|
||||
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||
await clb.answer(text=locale("sus_refused", "callback").format(fullclb[2]), show_alert=True) # type: ignore
|
||||
|
||||
await app.ban_chat_member(configGet("destination_group"), int(fullclb[2]))
|
||||
|
||||
jsonSave(jsonLoad(f"{configGet('data', 'locations')}{sep}user_default.json"), f"{configGet('data', 'locations')}{sep}users{sep}{fullclb[2]}.json")
|
||||
configSet(["stage"], 10, file=fullclb[2])
|
||||
configSet(["refused"], True, file=fullclb[2])
|
||||
configSet(["refused_by"], clb.from_user.id, file=fullclb[2])
|
||||
# ==============================================================================================================================
|
Reference in New Issue
Block a user