azils3/bash
0
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 8from . import get_help9 10__doc__ = get_help("help_admintools")11 12import asyncio13 14from telethon.errors import BadRequestError15from telethon.errors.rpcerrorlist import ChatNotModifiedError, UserIdInvalidError16from telethon.tl.functions.channels import EditAdminRequest, GetFullChannelRequest17from telethon.tl.functions.messages import GetFullChatRequest, SetHistoryTTLRequest18from telethon.tl.types import InputMessagesFilterPinned19from telethon.utils import get_display_name20 21from pyUltroid.dB import DEVLIST22from pyUltroid.fns.admins import ban_time23from pyUltroid.fns.info import get_uinfo24 25from . import HNDLR, LOGS, eod, eor, get_string, inline_mention, types, ultroid_cmd26 27 28@ultroid_cmd(29 pattern="promote( (.*)|$)",30 admins_only=True,31 manager=True,32 require="add_admins",33 fullsudo=True,34)35async def prmte(ult):36 xx = await ult.eor(get_string("com_1"))37 user, rank = await get_uinfo(ult)38 rank = rank or "Admin"39 FullRight = False40 if not user:41 return await xx.edit(get_string("pro_1"))42 if rank.split()[0] == "-f":43 try:44 rank = rank.split(maxsplit=1)[1]45 except IndexError:46 rank = "Admin"47 FullRight = True48 try:49 if FullRight:50 await ult.client(51 EditAdminRequest(ult.chat_id, user.id, ult.chat.admin_rights, rank)52 )53 else:54 await ult.client.edit_admin(55 ult.chat_id,56 user.id,57 invite_users=True,58 ban_users=True,59 delete_messages=True,60 pin_messages=True,61 manage_call=True,62 title=rank,63 )64 await eod(65 xx, get_string("pro_2").format(inline_mention(user), ult.chat.title, rank)66 )67 except Exception as ex:68 return await xx.edit(f"`{ex}`")69 70 71@ultroid_cmd(72 pattern="demote( (.*)|$)",73 admins_only=True,74 manager=True,75 require="add_admins",76 fullsudo=True,77)78async def dmote(ult):79 xx = await ult.eor(get_string("com_1"))80 user, rank = await get_uinfo(ult)81 if not rank:82 rank = "Not Admin"83 if not user:84 return await xx.edit(get_string("de_1"))85 try:86 await ult.client.edit_admin(87 ult.chat_id,88 user.id,89 invite_users=None,90 ban_users=None,91 delete_messages=None,92 pin_messages=None,93 manage_call=None,94 title=rank,95 )96 await eod(xx, get_string("de_2").format(inline_mention(user), ult.chat.title))97 except Exception as ex:98 return await xx.edit(f"`{ex}`")99 100 101@ultroid_cmd(102 pattern="ban( (.*)|$)",103 admins_only=True,104 manager=True,105 require="ban_users",106 fullsudo=True,107)108async def bban(ult):109 something = await get_uinfo(ult)110 if not something:111 return112 user, reason = something113 if not user:114 return await eod(ult, get_string("ban_1"))115 if user.id in DEVLIST:116 return await eod(ult, get_string("ban_2"))117 try:118 await ult.client.edit_permissions(ult.chat_id, user.id, view_messages=False)119 except UserIdInvalidError:120 return await eod(ult, get_string("adm_1"))121 except BadRequestError:122 return await eod(ult, get_string("ban_3"))123 senderme = inline_mention(await ult.get_sender())124 userme = inline_mention(user)125 text = get_string("ban_4").format(userme, senderme, ult.chat.title)126 if reason:127 text += get_string("ban_5").format(reason)128 await eod(ult, text)129 130 131@ultroid_cmd(132 pattern="unban( (.*)|$)",133 admins_only=True,134 manager=True,135 require="ban_users",136 fullsudo=True,137)138async def uunban(ult):139 xx = await ult.eor(get_string("com_1"))140 if ult.text[1:].startswith("unbanall"):141 return142 something = await get_uinfo(ult)143 if not something:144 return145 user, reason = something146 if not user:147 return await xx.edit(get_string("unban_1"))148 try:149 await ult.client.edit_permissions(ult.chat_id, user.id, view_messages=True)150 except UserIdInvalidError:151 return await eod(ult, get_string("adm_1"))152 except BadRequestError:153 return await xx.edit(get_string("adm_2"))154 sender = inline_mention(await ult.get_sender())155 text = get_string("unban_3").format(inline_mention(user), sender, ult.chat.title)156 if reason:157 text += get_string("ban_5").format(reason)158 await xx.edit(text)159 160 161@ultroid_cmd(162 pattern="kick( (.*)|$)",163 manager=True,164 require="ban_users",165 fullsudo=True,166)167async def kck(ult):168 if "kickme" in ult.text:169 return170 if ult.is_private:171 return await ult.eor("`Use this in Group/Channel.`", time=5)172 ml = ult.text.split(" ", maxsplit=1)[0]173 xx = await ult.eor(get_string("com_1"))174 something = await get_uinfo(ult)175 if not something:176 return177 user, reason = something178 if not user:179 return await xx.edit(get_string("adm_1"))180 if user.id in DEVLIST:181 return await xx.edit(get_string("kick_2"))182 if getattr(user, "is_self", False):183 return await xx.edit(get_string("kick_3"))184 try:185 await ult.client.kick_participant(ult.chat_id, user.id)186 except BadRequestError as er:187 LOGS.info(er)188 return await xx.edit(get_string("kick_1"))189 except Exception as e:190 LOGS.exception(e)191 return192 text = get_string("kick_4").format(193 inline_mention(user), inline_mention(await ult.get_sender()), ult.chat.title194 )195 if reason:196 text += get_string("ban_5").format(reason)197 await xx.edit(text)198 199 200@ultroid_cmd(201 pattern="tban( (.*)|$)",202 admins_only=True,203 manager=True,204 require="ban_users",205 fullsudo=True,206)207async def tkicki(e):208 huh = e.text.split()209 inputt = None210 try:211 tme = huh[1]212 except IndexError:213 return await e.eor(get_string("adm_3"), time=15)214 try:215 inputt = huh[2]216 except IndexError:217 if e.reply_to_msg_id:218 inputt = (await e.get_reply_message()).sender_id219 if not inputt:220 return await e.eor(get_string("tban_1"))221 userid = await e.client.parse_id(inputt)222 try:223 user = await e.client.get_entity(userid)224 except Exception as ex:225 return await eor(e, f"`{ex}`")226 try:227 bun = ban_time(tme)228 await e.client.edit_permissions(229 e.chat_id, user.id, until_date=bun, view_messages=False230 )231 await eod(232 e,233 get_string("tban_2").format(inline_mention(user), e.chat.title, tme),234 time=15,235 )236 except Exception as m:237 return await e.eor(str(m))238 239 240@ultroid_cmd(pattern="pin$", manager=True, require="pin_messages", fullsudo=True)241async def pin(msg):242 if not msg.is_reply:243 return await eor(msg, get_string("pin_1"))244 me = await msg.get_reply_message()245 if me.is_private:246 text = "`Pinned.`"247 else:248 text = f"Pinned [This Message]({me.message_link}) !"249 try:250 await msg.client.pin_message(msg.chat_id, me.id, notify=False)251 except BadRequestError:252 return await eor(msg, get_string("adm_2"))253 except Exception as e:254 return await eor(msg, f"**ERROR:**`{e}`")255 await eor(msg, text)256 257 258@ultroid_cmd(259 pattern="unpin($| (.*))",260 manager=True,261 require="pin_messages",262 fullsudo=True,263)264async def unp(ult):265 xx = await ult.eor(get_string("com_1"))266 ch = (ult.pattern_match.group(1).strip()).strip()267 msg = None268 if ult.is_reply:269 msg = ult.reply_to_msg_id270 elif ch != "all":271 return await xx.edit(get_string("unpin_1").format(HNDLR))272 try:273 await ult.client.unpin_message(ult.chat_id, msg)274 except BadRequestError:275 return await xx.edit(get_string("adm_2"))276 except Exception as e:277 return await xx.edit(f"**ERROR:**`{e}`")278 await xx.edit("`Unpinned!`")279 280 281@ultroid_cmd(282 pattern="tpin( (.*)|$)",283 admins_only=True,284 manager=True,285 require="pin_messages",286 fullsudo=True,287)288async def pin_message(ult):289 match = ult.pattern_match.group(1).strip()290 if not ult.is_reply:291 return await ult.eor("`Reply to message..`", time=6)292 if not match:293 return await ult.eor("`Please provide time..`", time=8)294 msg = await ult.eor(get_string("com_1"))295 msg_id = ult.reply_to_msg_id296 try:297 time = ban_time(match)298 await ult.client.pin_message(ult.chat_id, msg_id)299 await msg.eor(f"`pinned for time` `{time}`", time=8)300 except Exception as er:301 return await msg.edit(str(er))302 await asyncio.sleep(time)303 try:304 await ult.client.unpin_message(ult.chat_id, msg_id)305 except Exception as er:306 LOGS.exception(er)307 308 309@ultroid_cmd(pattern="purge( (.*)|$)", manager=True, require="delete_messages")310async def fastpurger(purg):311 match = purg.pattern_match.group(1).strip()312 try:313 ABC = purg.text[6]314 except IndexError:315 ABC = None316 if ABC and purg.text[6] in ["m", "a"]:317 return318 if not purg._client._bot and (319 (match)320 or (purg.is_reply and (purg.is_private or isinstance(purg.chat, types.Chat)))321 ):322 p = 0323 async for msg in purg.client.iter_messages(324 purg.chat_id,325 limit=int(match) if match else None,326 min_id=purg.reply_to_msg_id if purg.is_reply else None,327 ):328 await msg.delete()329 p += 0330 return await eor(purg, f"Purged {p} Messages! ", time=5)331 if not purg.reply_to_msg_id:332 return await eor(purg, get_string("purge_1"), time=10)333 try:334 await purg.client.delete_messages(335 purg.chat_id, list(range(purg.reply_to_msg_id, purg.id))336 )337 338 except Exception as er:339 LOGS.info(er)340 await purg.eor("__Fast purge complete!__", time=5)341 342 343@ultroid_cmd(344 pattern="purgeme( (.*)|$)",345)346async def fastpurgerme(purg):347 if num := purg.pattern_match.group(1).strip():348 try:349 nnt = int(num)350 except BaseException:351 await eor(purg, get_string("com_3"), time=5)352 return353 mp = 0354 async for mm in purg.client.iter_messages(355 purg.chat_id, limit=nnt, from_user="me"356 ):357 await mm.delete()358 mp += 1359 await eor(purg, f"Purged {mp} Messages!", time=5)360 return361 elif not purg.reply_to_msg_id:362 return await eod(363 purg,364 "`Reply to a message to purge from or use it like ``purgeme <num>`",365 time=10,366 )367 chat = await purg.get_input_chat()368 msgs = []369 async for msg in purg.client.iter_messages(370 chat,371 from_user="me",372 min_id=purg.reply_to_msg_id,373 ):374 msgs.append(msg)375 if msgs:376 await purg.client.delete_messages(chat, msgs)377 await purg.eor(378 "__Fast purge complete!__\n**Purged** `" + str(len(msgs)) + "` **messages.**",379 time=5,380 )381 382 383@ultroid_cmd(384 pattern="purgeall$",385)386async def _(e):387 if not e.is_reply:388 return await eod(389 e,390 get_string("purgeall_1"),391 )392 393 msg = await e.get_reply_message()394 name = msg.sender395 try:396 await e.client.delete_messages(e.chat_id, from_user=msg.sender_id)397 await e.eor(get_string("purgeall_2").format(name.first_name), time=5)398 except Exception as er:399 return await e.eor(str(er), time=5)400 401@ultroid_cmd(pattern="pinned", manager=True, groups_only=True)402async def djshsh(event):403 chat = await event.get_chat()404 if isinstance(chat, types.Chat):405 FChat = await event.client(GetFullChatRequest(chat.id))406 elif isinstance(chat, types.Channel):407 FChat = await event.client(GetFullChannelRequest(chat.id))408 else:409 return410 msg_id = FChat.full_chat.pinned_msg_id411 if not msg_id:412 return await event.eor(get_string("pinned_1"))413 msg = await event.client.get_messages(chat.id, ids=msg_id)414 if msg:415 await event.eor(get_string("pinned_2").format(msg.message_link))416 417 418@ultroid_cmd(419 pattern="listpinned$",420)421async def get_all_pinned(event):422 x = await event.eor(get_string("com_1"))423 chat_id = (str(event.chat_id)).replace("-100", "")424 chat_name = get_display_name(event.chat)425 a = ""426 c = 1427 async for i in event.client.iter_messages(428 event.chat_id, filter=InputMessagesFilterPinned429 ):430 if i.message:431 t = " ".join(i.message.split()[:4])432 txt = f"{t}...."433 else:434 txt = "Go to message."435 a += f"{c}. <a href=https://t.me/c/{chat_id}/{i.id}>{txt}</a>\n"436 c += 1437 438 if c == 1:439 m = f"<b>The pinned message in {chat_name}:</b>\n\n"440 else:441 m = f"<b>List of pinned message(s) in {chat_name}:</b>\n\n"442 443 if not a:444 return await eor(x, get_string("listpin_1"), time=5)445 446 await x.edit(m + a, parse_mode="html")447 448 449@ultroid_cmd(450 pattern="autodelete( (.*)|$)",451 admins_only=True,452)453async def autodelte(ult):454 match = ult.pattern_match.group(1).strip()455 if not match or match not in ["24h", "7d", "1m", "off"]:456 return await ult.eor("`Please Use in Proper Format..`", time=5)457 if match == "24h":458 tt = 3600 * 24459 elif match == "7d":460 tt = 3600 * 24 * 7461 elif match == "1m":462 tt = 3600 * 24 * 31463 else:464 tt = 0465 try:466 await ult.client(SetHistoryTTLRequest(ult.chat_id, period=tt))467 except ChatNotModifiedError:468 return await ult.eor(469 f"Auto Delete Setting is Already same to `{match}`", time=5470 )471 await ult.eor(f"Auto Delete Status Changed to `{match}` !")472 