Command /message implemented
This commit is contained in:
parent
484990564f
commit
7de55e950e
@ -53,6 +53,9 @@
|
|||||||
"no_warnings": "Користувач **{0}** (`{1}`) не має попереджень",
|
"no_warnings": "Користувач **{0}** (`{1}`) не має попереджень",
|
||||||
"no_user_warnings": "Не знайдено користувачів за запитом **{0}**",
|
"no_user_warnings": "Не знайдено користувачів за запитом **{0}**",
|
||||||
"syntax_warnings": "Неправильний синтаксис!\nТреба: `/warnings ID/NAME/USERNAME`",
|
"syntax_warnings": "Неправильний синтаксис!\nТреба: `/warnings ID/NAME/USERNAME`",
|
||||||
|
"message_sent": "Повідомлення надіслано",
|
||||||
|
"message_no_user": "⚠️ **Помилка надсилання**\nВказано невірний ID користувача, тому не вдалось надіслати йому повідомлення. Перевірте чи в якості ID надано те число, яке було показане в анкеті.",
|
||||||
|
"message_invalid_syntax": "Неправильний синтаксис!\nТреба: `/message ID ПОВІДОМЛЕННЯ`",
|
||||||
"question_titles": {
|
"question_titles": {
|
||||||
"question1": "Ім'я/звертання:",
|
"question1": "Ім'я/звертання:",
|
||||||
"question2": "День народження:",
|
"question2": "День народження:",
|
||||||
|
42
main.py
42
main.py
@ -29,6 +29,9 @@ for entry in [f"{configGet('data', 'locations')}{sep}applications.json", f"{conf
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def should_quote(msg):
|
||||||
|
return True if msg.chat.type is not ChatType.PRIVATE else False
|
||||||
|
|
||||||
# Start command ================================================================================================================
|
# Start command ================================================================================================================
|
||||||
@app.on_message(~ filters.scheduled & filters.private & filters.command(["start"], prefixes=["/"]))
|
@app.on_message(~ filters.scheduled & filters.private & filters.command(["start"], prefixes=["/"]))
|
||||||
async def cmd_start(app, msg):
|
async def cmd_start(app, msg):
|
||||||
@ -56,7 +59,7 @@ async def cmd_kill(app, msg):
|
|||||||
|
|
||||||
if msg.chat.id == configGet("admin_group") or await isAnAdmin(msg.from_user.id):
|
if msg.chat.id == configGet("admin_group") or await isAnAdmin(msg.from_user.id):
|
||||||
logWrite(f"Shutting down bot with pid {pid}")
|
logWrite(f"Shutting down bot with pid {pid}")
|
||||||
await msg.reply_text(f"Вимкнення бота з підом `{pid}`")
|
await msg.reply_text(f"Вимкнення бота з підом `{pid}`", quote=should_quote(msg))
|
||||||
killProc(pid)
|
killProc(pid)
|
||||||
# ==============================================================================================================================
|
# ==============================================================================================================================
|
||||||
|
|
||||||
@ -114,7 +117,26 @@ async def cmd_warn(app, msg):
|
|||||||
# Message command ==============================================================================================================
|
# Message command ==============================================================================================================
|
||||||
@app.on_message(~ filters.scheduled & filters.command(["message"], prefixes=["/"]))
|
@app.on_message(~ filters.scheduled & filters.command(["message"], prefixes=["/"]))
|
||||||
async def cmd_message(app, msg):
|
async def cmd_message(app, msg):
|
||||||
pass
|
|
||||||
|
if msg.chat.id == configGet("admin_group") or await isAnAdmin(msg.from_user.id):
|
||||||
|
|
||||||
|
try:
|
||||||
|
destination = int(msg.command[1])
|
||||||
|
void = msg.command[2]
|
||||||
|
message = " ".join(msg.command[2:])
|
||||||
|
try:
|
||||||
|
await app.send_message(destination, message)
|
||||||
|
await msg.reply_text(locale("message_sent", "message"), quote=should_quote(msg))
|
||||||
|
logWrite(f"Admin {msg.from_user.id} sent message '{' '.join(msg.command[2:])}' to {destination}")
|
||||||
|
except bad_request_400.PeerIdInvalid:
|
||||||
|
await msg.reply_text(locale("message_no_user", "message"), quote=should_quote(msg))
|
||||||
|
logWrite(f"Admin {msg.from_user.id} tried to send message '{' '.join(msg.command[2:])}' to {destination} but 'PeerIdInvalid'")
|
||||||
|
except IndexError:
|
||||||
|
await msg.reply_text(locale("message_invalid_syntax", "message"), 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"), quote=should_quote(msg))
|
||||||
|
logWrite(f"Admin {msg.from_user.id} tried to send message but 'ValueError'")
|
||||||
# ==============================================================================================================================
|
# ==============================================================================================================================
|
||||||
|
|
||||||
|
|
||||||
@ -127,7 +149,7 @@ async def cmd_warnings(app, msg):
|
|||||||
warnings = jsonLoad(f"{configGet('data', 'locations')}{sep}warnings.json")
|
warnings = jsonLoad(f"{configGet('data', 'locations')}{sep}warnings.json")
|
||||||
|
|
||||||
if len(msg.command) <= 1:
|
if len(msg.command) <= 1:
|
||||||
await msg.reply_text(locale("syntax_warnings", "message"))
|
await msg.reply_text(locale("syntax_warnings", "message"), quote=should_quote(msg))
|
||||||
|
|
||||||
if path.exists(f"{configGet('data', 'locations')}{sep}users{sep}{msg.command[1]}.json"):
|
if path.exists(f"{configGet('data', 'locations')}{sep}users{sep}{msg.command[1]}.json"):
|
||||||
target_id = str(int(msg.command[1]))
|
target_id = str(int(msg.command[1]))
|
||||||
@ -146,12 +168,12 @@ async def cmd_warnings(app, msg):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if target_id not in warnings:
|
if target_id not in warnings:
|
||||||
await msg.reply_text(locale("no_warnings", "message").format(target_name, target_id)) # type: ignore
|
await msg.reply_text(locale("no_warnings", "message").format(target_name, target_id), quote=should_quote(msg)) # type: ignore
|
||||||
else:
|
else:
|
||||||
if warnings[target_id] <= 5:
|
if warnings[target_id] <= 5:
|
||||||
await msg.reply_text(locale("warnings_1", "message").format(target_name, target_id, warnings[target_id])) # type: ignore
|
await msg.reply_text(locale("warnings_1", "message").format(target_name, target_id, warnings[target_id]), quote=should_quote(msg)) # type: ignore
|
||||||
else:
|
else:
|
||||||
await msg.reply_text(locale("warnings_2", "message").format(target_name, target_id, warnings[target_id])) # type: ignore
|
await msg.reply_text(locale("warnings_2", "message").format(target_name, target_id, warnings[target_id]), quote=should_quote(msg)) # type: ignore
|
||||||
# ==============================================================================================================================
|
# ==============================================================================================================================
|
||||||
|
|
||||||
|
|
||||||
@ -161,7 +183,7 @@ async def cmd_applications(app, msg):
|
|||||||
|
|
||||||
if (await isAnAdmin(msg.from_user.id)) or (msg.chat.id == configGet("admin_group")):
|
if (await isAnAdmin(msg.from_user.id)) or (msg.chat.id == configGet("admin_group")):
|
||||||
await app.send_chat_action(msg.chat.id, ChatAction.UPLOAD_DOCUMENT)
|
await app.send_chat_action(msg.chat.id, ChatAction.UPLOAD_DOCUMENT)
|
||||||
await msg.reply_document(document=f"{configGet('data', 'locations')}{sep}applications.json")
|
await msg.reply_document(document=f"{configGet('data', 'locations')}{sep}applications.json", quote=should_quote(msg))
|
||||||
# ==============================================================================================================================
|
# ==============================================================================================================================
|
||||||
|
|
||||||
|
|
||||||
@ -205,13 +227,13 @@ async def cmd_application(app, msg):
|
|||||||
else:
|
else:
|
||||||
application_status = locale("application_status_not_send", "message")
|
application_status = locale("application_status_not_send", "message")
|
||||||
logWrite(f"User {msg.from_user.id} requested application of {user_id}")
|
logWrite(f"User {msg.from_user.id} requested application of {user_id}")
|
||||||
await msg.reply_text(locale("contact", "message").format(str(user_id), "\n".join(application_content), application_status)) # type: ignore
|
await msg.reply_text(locale("contact", "message").format(str(user_id), "\n".join(application_content), application_status), quote=should_quote(msg)) # type: ignore
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
logWrite(f"User {msg.from_user.id} requested application of {user_id} but user does not exists")
|
logWrite(f"User {msg.from_user.id} requested application of {user_id} but user does not exists")
|
||||||
await msg.reply_text(locale("contact_invalid", "message"))
|
await msg.reply_text(locale("contact_invalid", "message"), quote=should_quote(msg))
|
||||||
|
|
||||||
except IndexError:
|
except IndexError:
|
||||||
await msg.reply_text(locale("application_invalid_syntax", "message"))
|
await msg.reply_text(locale("application_invalid_syntax", "message"), quote=should_quote(msg))
|
||||||
# ==============================================================================================================================
|
# ==============================================================================================================================
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user