Team Ai
Apppublic

azils3/bash

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
warn.py187 linesDownload Raw Back to plugins
1# Ultroid - UserBot2# Copyright (C) 2021-2025 TeamUltroid3#4# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >5# PLease read the GNU Affero General Public License in6# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.7"""8✘ Commands Available9 10•`{i}warn <reply to user> <reason>`11    Gives Warn.12 13•`{i}resetwarn <reply to user>`14    To reset All Warns.15 16•`{i}warns <reply to user>`17   To Get List of Warnings of a user.18 19•`{i}setwarn <warn count> | <ban/mute/kick>`20   Set Number in warn count for warnings21   After putting " | " mark put action like ban/mute/kick22   Its Default 3 kick23   Example : `setwarn 5 | mute`24 25"""26 27from pyUltroid.dB.warn_db import add_warn, reset_warn, warns28 29from . import eor, get_string, inline_mention, udB, ultroid_cmd30 31 32@ultroid_cmd(33    pattern="warn( (.*)|$)",34    manager=True,35    groups_only=True,36    admins_only=True,37)38async def warn(e):39    ultroid_bot = e.client40    reply = await e.get_reply_message()41    if len(e.text) > 5 and " " not in e.text[5]:42        return43    if reply:44        user = reply.sender_id45        reason = e.text[5:] if e.pattern_match.group(1).strip() else "unknown"46    else:47        try:48            user = e.text.split()[1]49            if user.startswith("@"):50                ok = await ultroid_bot.get_entity(user)51                user = ok.id52            else:53                user = int(user)54        except BaseException:55            return await e.eor("Reply To A User", time=5)56        try:57            reason = e.text.split(maxsplit=2)[-1]58        except BaseException:59            reason = "unknown"60    count, r = warns(e.chat_id, user)61    r = f"{r}|$|{reason}" if r else reason62    try:63        x = udB.get_key("SETWARN")64        number, action = int(x.split()[0]), x.split()[1]65    except BaseException:66        number, action = 3, "kick"67    if ("ban" or "kick" or "mute") not in action:68        action = "kick"69    if count + 1 >= number:70        if "ban" in action:71            try:72                await ultroid_bot.edit_permissions(e.chat_id, user, view_messages=False)73            except BaseException:74                return await e.eor("`Something Went Wrong.`", time=5)75        elif "kick" in action:76            try:77                await ultroid_bot.kick_participant(e.chat_id, user)78            except BaseException:79                return await e.eor("`Something Went Wrong.`", time=5)80        elif "mute" in action:81            try:82                await ultroid_bot.edit_permissions(83                    e.chat_id, user, until_date=None, send_messages=False84                )85            except BaseException:86                return await e.eor("`Something Went Wrong.`", time=5)87        add_warn(e.chat_id, user, count + 1, r)88        c, r = warns(e.chat_id, user)89        ok = await ultroid_bot.get_entity(user)90        user = inline_mention(ok)91        r = r.split("|$|")92        text = f"User {user} Got {action} Due to {count+1} Warns.\n\n"93        for x in range(c):94            text += f"•**{x+1}.** {r[x]}\n"95        await e.eor(text)96        return reset_warn(e.chat_id, ok.id)97    add_warn(e.chat_id, user, count + 1, r)98    ok = await ultroid_bot.get_entity(user)99    user = inline_mention(ok)100    await eor(101        e,102        f"**WARNING :** {count+1}/{number}\n**To :**{user}\n**Be Careful !!!**\n\n**Reason** : {reason}",103    )104 105 106@ultroid_cmd(107    pattern="resetwarn( (.*)|$)",108    manager=True,109    groups_only=True,110    admins_only=True,111)112async def rwarn(e):113    reply = await e.get_reply_message()114    if reply:115        user = reply.sender_id116    else:117        try:118            user = e.text.split()[1]119            if user.startswith("@"):120                ok = await e.client.get_entity(user)121                user = ok.id122            else:123                user = int(user)124        except BaseException:125            return await e.eor("Reply To user")126    reset_warn(e.chat_id, user)127    ok = await e.client.get_entity(user)128    user = inline_mention(ok)129    await e.eor(f"Cleared All Warns of {user}.")130 131 132@ultroid_cmd(133    pattern="warns( (.*)|$)",134    manager=True,135    groups_only=True,136    admins_only=True,137)138async def twarns(e):139    reply = await e.get_reply_message()140    if reply:141        user = reply.from_id.user_id142    else:143        try:144            user = e.text.split()[1]145            if user.startswith("@"):146                ok = await e.client.get_entity(user)147                user = ok.id148            else:149                user = int(user)150        except BaseException:151            return await e.eor("Reply To A User", time=5)152    c, r = warns(e.chat_id, user)153    if c and r:154        ok = await e.client.get_entity(user)155        user = inline_mention(ok)156        r = r.split("|$|")157        text = f"User {user} Got {c} Warns.\n\n"158        for x in range(c):159            text += f"•**{x+1}.** {r[x]}\n"160        await e.eor(text)161    else:162        await e.eor("`No Warnings`")163 164 165@ultroid_cmd(pattern="setwarn( (.*)|$)", manager=True)166async def warnset(e):167    ok = e.pattern_match.group(1).strip()168    if not ok:169        return await e.eor("Invalid format. Correct usage: .setwarns <number>|<action>")170    if "|" in ok:171        try:172            number, action = ok.split("|")173            number = int(number.strip())174            action = action.strip()175        except ValueError:176            return await e.eor(177                "Invalid format. Correct usage: .setwarns <number>|<action>", time=5178            )179        if action not in ["ban", "mute", "kick"]:180            return await e.eor("Only mute / ban / kick options are supported", time=5)181        udB.set_key("SETWARN", f"{number} {action}")182        await e.eor(f"Done. Your Warn Count is now {number} and Action is {action}")183    else:184        await e.eor(185            "Invalid format. Correct usage: .setwarns <number>|<action>", time=5186        )187