This commit is contained in:
Profitroll 2022-12-04 11:28:02 +01:00
commit 40cf3cff7c
4 changed files with 132 additions and 14 deletions

View File

@ -2,6 +2,7 @@
"locale": "uk",
"debug": false,
"owner": 0,
"bot_id": 0,
"age_allowed": 0,
"birthdays_notify": true,
"birthdays_time": "09:00",
@ -9,6 +10,7 @@
"inline_preview_count": 7,
"admin_group": 0,
"destination_group": 0,
"remove_application_time": -1,
"admins": [],
"bot": {
"api_id": 0,

File diff suppressed because one or more lines are too long

110
main.py
View File

@ -1,3 +1,4 @@
import asyncio
from datetime import datetime
from threading import Thread
from dateutil.relativedelta import relativedelta
@ -61,14 +62,39 @@ async def cmd_kill(app, msg):
# Rules command =============================================================================================================
default_rules_markup = InlineKeyboardMarkup(
[
[
InlineKeyboardButton(locale("rules_home", "button"), callback_data="rules_home"),
InlineKeyboardButton(locale("rules_additional", "button"), callback_data="rules_additional")
],
[
InlineKeyboardButton("1", callback_data="rule_1"),
InlineKeyboardButton("2", callback_data="rule_2"),
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("7", callback_data="rule_7"),
InlineKeyboardButton("8", callback_data="rule_8"),
InlineKeyboardButton("9", callback_data="rule_9")
]
]
)
@app.on_message(~ filters.scheduled & filters.private & filters.command(["rules"], prefixes=["/"]))
async def cmd_rules(app, msg):
for rule_msg in locale("rules"):
await msg.reply_text(rule_msg)
await msg.reply_text(locale("rules_msg"), disable_web_page_preview=True, reply_markup=default_rules_markup)
# for rule_msg in locale("rules"):
# await msg.reply_text(rule_msg)
# ==============================================================================================================================
# Warn command =============================================================================================================
# Warn command =================================================================================================================
@app.on_message(~ filters.scheduled & filters.command(["warn"], prefixes=["/"]))
async def cmd_warn(app, msg):
@ -533,6 +559,72 @@ async def callback_query_nothing(app, clb):
# ==============================================================================================================================
# 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
# ==============================================================================================================================
# Contact getting ==============================================================================================================
@app.on_message(~ filters.scheduled & filters.contact & filters.private)
async def get_contact(app, msg):
@ -579,7 +671,7 @@ async def get_contact(app, msg):
@app.on_message(~ filters.scheduled & filters.private)
async def any_stage(app, msg):
if msg.via_bot == None:
if msg.via_bot is None:
user_stage = configGet("stage", file=str(msg.from_user.id))
@ -638,6 +730,16 @@ async def any_stage(app, msg):
else:
if not configGet("approved", file=str(msg.from_user.id)) and not configGet("refused", file=str(msg.from_user.id)):
await msg.reply_text(locale("already_sent", "message"))
@app.on_message(~ filters.scheduled & filters.group)
async def message_in_group(app, msg):
if (msg.chat is not None) and (msg.via_bot is not None):
if (msg.via_bot.id == configGet("bot_id")) and (msg.chat.id == configGet("destination_group")):
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)
await msg.delete()
logWrite(f"Removed application requested by {msg.from_user.id} in destination group")
# ==============================================================================================================================

View File

@ -11,7 +11,7 @@ from modules.utils import configGet, jsonLoad, locale
@app.on_inline_query()
async def inline_answer(client, inline_query):
if inline_query.chat_type not in [ChatType.BOT, ChatType.PRIVATE]:
if inline_query.chat_type in [ChatType.CHANNEL]:
await inline_query.answer(
results=[
InlineQueryResultArticle(