Files
Ultroid-fork/plugins/dnd.py
Devesh Pal 8ad7073d80 Ultroid v0.4 updates
Co-authored-by: Amit Sharma <48654350+buddhhu@users.noreply.github.com>
Co-authored-by: Danish <danish@ultroid.tech>
Co-authored-by: Mahesh Chauhan <84653476+vasusen-code@users.noreply.github.com>
Co-authored-by: Aditya <xditya@ultroid.tech>
Co-authored-by: CyrusXD <79554993+Ashutosh1478@users.noreply.github.com>
2022-02-09 11:53:45 +05:30

60 lines
1.9 KiB
Python

# Ultroid - UserBot
# Copyright (C) 2021-2022 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
"""
✘ Commands Available
Do Not Disturb - As it says, activating this in your group will kick new users who joins the group.
• `{i}dnd`
To activate.
• `{i}deldnd`
To deactivate.
"""
from pyUltroid.dB.dnd_db import add_dnd, chat_in_dnd, del_dnd, get_dnd_chats
from telethon import events
from . import LOGS, asst, ultroid_bot, ultroid_cmd
async def dnd_func(event):
if event.chat_id in get_dnd_chats():
for user in event.users:
try:
await (
await event.client.kick_participant(event.chat_id, user)
).delete()
except Exception as ex:
LOGS.error("Error in DND:")
LOGS.exception(ex)
await event.delete()
@ultroid_cmd(pattern="dnd$", manager=True, admins_only=True, groups_only=True)
async def _(event):
if chat_in_dnd(event.chat_id):
return await event.eor("`Chat already in do not disturb mode.`", time=3)
add_dnd(event.chat_id)
event.client.add_handler(dnd_func, events.ChatAction(func=lambda x: x.user_joined))
await event.eor("`Do not disturb mode activated for this chat.`", time=3)
@ultroid_cmd(pattern="deldnd$", manager=True, admins_only=True, groups_only=True)
async def _(event):
if not chat_in_dnd(event.chat_id):
return await event.eor("`Chat is not in do not disturb mode.`", time=3)
del_dnd(event.chat_id)
await event.eor("`Do not disturb mode deactivated for this chat.`", time=3)
if get_dnd_chats():
ultroid_bot.add_handler(dnd_func, events.ChatAction(func=lambda x: x.user_joined))
asst.add_handler(dnd_func, events.ChatAction(func=lambda x: x.user_joined))