File size: 5,887 Bytes
1f26706 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# Ultroid - UserBot
# Copyright (C) 2021-2025 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
•`{i}warn <reply to user> <reason>`
Gives Warn.
•`{i}resetwarn <reply to user>`
To reset All Warns.
•`{i}warns <reply to user>`
To Get List of Warnings of a user.
•`{i}setwarn <warn count> | <ban/mute/kick>`
Set Number in warn count for warnings
After putting " | " mark put action like ban/mute/kick
Its Default 3 kick
Example : `setwarn 5 | mute`
"""
from pyUltroid.dB.warn_db import add_warn, reset_warn, warns
from . import eor, get_string, inline_mention, udB, ultroid_cmd
@ultroid_cmd(
pattern="warn( (.*)|$)",
manager=True,
groups_only=True,
admins_only=True,
)
async def warn(e):
ultroid_bot = e.client
reply = await e.get_reply_message()
if len(e.text) > 5 and " " not in e.text[5]:
return
if reply:
user = reply.sender_id
reason = e.text[5:] if e.pattern_match.group(1).strip() else "unknown"
else:
try:
user = e.text.split()[1]
if user.startswith("@"):
ok = await ultroid_bot.get_entity(user)
user = ok.id
else:
user = int(user)
except BaseException:
return await e.eor("Reply To A User", time=5)
try:
reason = e.text.split(maxsplit=2)[-1]
except BaseException:
reason = "unknown"
count, r = warns(e.chat_id, user)
r = f"{r}|$|{reason}" if r else reason
try:
x = udB.get_key("SETWARN")
number, action = int(x.split()[0]), x.split()[1]
except BaseException:
number, action = 3, "kick"
if ("ban" or "kick" or "mute") not in action:
action = "kick"
if count + 1 >= number:
if "ban" in action:
try:
await ultroid_bot.edit_permissions(e.chat_id, user, view_messages=False)
except BaseException:
return await e.eor("`Something Went Wrong.`", time=5)
elif "kick" in action:
try:
await ultroid_bot.kick_participant(e.chat_id, user)
except BaseException:
return await e.eor("`Something Went Wrong.`", time=5)
elif "mute" in action:
try:
await ultroid_bot.edit_permissions(
e.chat_id, user, until_date=None, send_messages=False
)
except BaseException:
return await e.eor("`Something Went Wrong.`", time=5)
add_warn(e.chat_id, user, count + 1, r)
c, r = warns(e.chat_id, user)
ok = await ultroid_bot.get_entity(user)
user = inline_mention(ok)
r = r.split("|$|")
text = f"User {user} Got {action} Due to {count+1} Warns.\n\n"
for x in range(c):
text += f"•**{x+1}.** {r[x]}\n"
await e.eor(text)
return reset_warn(e.chat_id, ok.id)
add_warn(e.chat_id, user, count + 1, r)
ok = await ultroid_bot.get_entity(user)
user = inline_mention(ok)
await eor(
e,
f"**WARNING :** {count+1}/{number}\n**To :**{user}\n**Be Careful !!!**\n\n**Reason** : {reason}",
)
@ultroid_cmd(
pattern="resetwarn( (.*)|$)",
manager=True,
groups_only=True,
admins_only=True,
)
async def rwarn(e):
reply = await e.get_reply_message()
if reply:
user = reply.sender_id
else:
try:
user = e.text.split()[1]
if user.startswith("@"):
ok = await e.client.get_entity(user)
user = ok.id
else:
user = int(user)
except BaseException:
return await e.eor("Reply To user")
reset_warn(e.chat_id, user)
ok = await e.client.get_entity(user)
user = inline_mention(ok)
await e.eor(f"Cleared All Warns of {user}.")
@ultroid_cmd(
pattern="warns( (.*)|$)",
manager=True,
groups_only=True,
admins_only=True,
)
async def twarns(e):
reply = await e.get_reply_message()
if reply:
user = reply.from_id.user_id
else:
try:
user = e.text.split()[1]
if user.startswith("@"):
ok = await e.client.get_entity(user)
user = ok.id
else:
user = int(user)
except BaseException:
return await e.eor("Reply To A User", time=5)
c, r = warns(e.chat_id, user)
if c and r:
ok = await e.client.get_entity(user)
user = inline_mention(ok)
r = r.split("|$|")
text = f"User {user} Got {c} Warns.\n\n"
for x in range(c):
text += f"•**{x+1}.** {r[x]}\n"
await e.eor(text)
else:
await e.eor("`No Warnings`")
@ultroid_cmd(pattern="setwarn( (.*)|$)", manager=True)
async def warnset(e):
ok = e.pattern_match.group(1).strip()
if not ok:
return await e.eor("Invalid format. Correct usage: .setwarns <number>|<action>")
if "|" in ok:
try:
number, action = ok.split("|")
number = int(number.strip())
action = action.strip()
except ValueError:
return await e.eor(
"Invalid format. Correct usage: .setwarns <number>|<action>", time=5
)
if action not in ["ban", "mute", "kick"]:
return await e.eor("Only mute / ban / kick options are supported", time=5)
udB.set_key("SETWARN", f"{number} {action}")
await e.eor(f"Done. Your Warn Count is now {number} and Action is {action}")
else:
await e.eor(
"Invalid format. Correct usage: .setwarns <number>|<action>", time=5
)
|