Add silent commands

This commit is contained in:
hok7z 2022-11-28 21:27:41 +02:00
parent 303d8034f9
commit 149a21d6e3
3 changed files with 21 additions and 18 deletions

View File

@ -37,7 +37,7 @@ This bot is designed to simplify the moderation and management of Telegram group
- [ ] Docker
- [ ] Systemd unit
- [ ] Antiflood system
- [ ] Silent commands
- [x] Silent commands
- [ ] Site for group moderator
## Support

View File

@ -16,11 +16,11 @@ from utils import getCommandArgs, getArgument, checkArg, parse_duration, delete_
# replied=True - If message is answer, continue.
# accessed_roles - list roles.
@dp.message_handler(commands=["ban"],commands_prefix="!",available_roles=[MemberRoles.HELPER,MemberRoles.ADMIN])
@dp.message_handler(commands=["ban","sban"],commands_prefix="!",available_roles=[MemberRoles.HELPER,MemberRoles.ADMIN])
async def ban_user(message: types.Message):
command = await getCommandArgs(message)
reason = getArgument(command.arguments)
to_user = command.to_user
from_user = command.from_user
@ -35,7 +35,7 @@ async def ban_user(message: types.Message):
# Ban user and save (bool)
status = await bot.kick_chat_member(chat_id=message.chat.id, user_id=to_user.user_id, until_date=None)
if status:
if status and (not command.is_silent):
await message.answer(f"[{from_user.first_name}](tg://user?id={from_user.user_id}) has banned [{to_user.first_name}](tg://user?id={to_user.user_id})",parse_mode="Markdown")
@ -47,7 +47,7 @@ async def ban_user(message: types.Message):
reason=reason,
)
@dp.message_handler(commands=["unban"],commands_prefix="!",available_roles=[MemberRoles.HELPER,MemberRoles.ADMIN])
@dp.message_handler(commands=["unban","sunban"],commands_prefix="!",available_roles=[MemberRoles.HELPER,MemberRoles.ADMIN])
async def unban_user(message: types.Message):
command = await getCommandArgs(message)
@ -66,7 +66,7 @@ async def unban_user(message: types.Message):
status = await bot.unban_chat_member(chat_id=message.chat.id, user_id=to_user.user_id)
if status:
if status and (not command.is_silent):
await message.answer(f"[{from_user.first_name}](tg://user?id={from_user.user_id}) has unbanned [{to_user.first_name}](tg://user?id={to_user.user_id})",parse_mode="Markdown")
Member.create(
@ -94,7 +94,7 @@ async def info_user(message: types.Message):
parse_mode="Markdown"
)
@dp.message_handler(commands=["kick"],commands_prefix="!",available_roles=[MemberRoles.HELPER,MemberRoles.ADMIN])
@dp.message_handler(commands=["kick","skick"],commands_prefix="!",available_roles=[MemberRoles.HELPER,MemberRoles.ADMIN])
async def kick_user(message:types.Message):
command = await getCommandArgs(message)
arguments = command.arguments
@ -115,7 +115,7 @@ async def kick_user(message:types.Message):
status1 = await bot.kick_chat_member(chat_id=message.chat.id, user_id=to_user.user_id, until_date=None)
status2 = await bot.unban_chat_member(chat_id=message.chat.id, user_id=to_user.user_id)
if (not status1 and status2):
if (not status1 and status2) and (not command.is_silent):
await message.answer(f"[{from_user.first_name}](tg://user?id={from_user.user_id}) has kicked [{to_user.first_name}](tg://user?id={to_user.user_id})",parse_mode="Markdown")
@ -127,7 +127,7 @@ async def kick_user(message:types.Message):
)
@dp.message_handler(commands=["mute"],commands_prefix="!",available_roles=[MemberRoles.ADMIN])
@dp.message_handler(commands=["mute","smute"],commands_prefix="!",available_roles=[MemberRoles.ADMIN])
async def mute_user(message:types.Message):
command = await getCommandArgs(message)
arguments = command.arguments
@ -170,7 +170,7 @@ async def mute_user(message:types.Message):
permissions=permissions
)
if status:
if status and (not command.is_silent):
await message.answer(f"[{from_user.first_name}](tg://user?id={from_user.user_id}) has muted [{to_user.first_name}](tg://user?id={to_user.user_id}) for {duration_string}",parse_mode="Markdown")
@ -182,7 +182,7 @@ async def mute_user(message:types.Message):
)
@dp.message_handler(commands=["unmute"],commands_prefix="!",available_roles=[MemberRoles.ADMIN])
@dp.message_handler(commands=["unmute","sunmute"],commands_prefix="!",available_roles=[MemberRoles.ADMIN])
async def umute_user(message: types.Message):
# Get information
command = await getCommandArgs(message)
@ -220,7 +220,7 @@ async def umute_user(message: types.Message):
permissions=permissions
)
if status:
if status and (not command.is_silent):
await message.answer(f"[{from_user.first_name}](tg://user?id={from_user.user_id}) has unmuted [{to_user.first_name}](tg://user?id={to_user.user_id})",parse_mode="Markdown")
@dp.message_handler(commands=["pin"],commands_prefix="!",available_roles=[MemberRoles.HELPER,MemberRoles.ADMIN])
@ -231,7 +231,7 @@ async def pin_message(message:types.Message):
async def readonly_mode(message:types.Message):
group_permissions = config.group_permissions
status = config.group_permissions['can_send_messages']
if (status):
await message.answer("🔕 Readonly mode enabled!")
chat_permissions = ChatPermissions(
@ -249,11 +249,9 @@ async def readonly_mode(message:types.Message):
can_add_web_page_previews=group_permissions['can_add_web_page_previews'],
can_pin_messages=group_permissions['can_pin_messages']
)
config.group_permissions["can_send_messages"] = not status
await bot.set_chat_permissions(chat_id=message.chat.id, permissions=chat_permissions)
@dp.message_handler(commands=["warn","w"],commands_prefix="!",available_roles=[MemberRoles.HELPER,MemberRoles.ADMIN])
async def warn_user(message: types.Message):

View File

@ -19,18 +19,24 @@ class CommandArguments:
to_user:Member | None
from_user:Member | None
arguments:list
is_silent:bool
async def getCommandArgs(message: types.Message) -> CommandArguments:
"""
Describe user data and arguments from message
!command (username|id) ...
"""
silent = False
if (message.text.split()[0] == "s"):
silent = True
arguments = message.text.split()[1:]
to_user = None
from_user = Member.search(Member.user_id, message.from_user.id)
# If message replied
if (message.reply_to_message):
to_user = Member.search(Member.user_id, message.reply_to_message)
@ -49,8 +55,7 @@ async def getCommandArgs(message: types.Message) -> CommandArguments:
arguments = arguments[1:]
return CommandArguments(to_user, from_user, arguments)
return CommandArguments(to_user, from_user, arguments,silent)
def delete_substring_from_string(string:str,substring:str) -> str:
string_list = string.split(substring)