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"""8✘ Commands Available -9 10• `{i}gban <reply user/ username>`11• `{i}ungban`12 Ban/Unban Globally.13 14• `{i}gstat <reply to user/userid/username>`15 Check if user is GBanned.16 17• `{i}listgban` : List all GBanned users.18 19• `{i}gmute` | `{i}ungmute` <reply user/ username>20 Mute/UnMute Globally.21 22• `{i}gkick <reply/username>` `Globally Kick User`23• `{i}gcast <text/reply>` `Globally Send msg in all grps`24 25• `{i}gadmincast <text/reply>` `Globally broadcast in your admin chats`26• `{i}gucast <text/reply>` `Globally send msg in all pm users`27 28• `{i}gblacklist <chat id/username/nothing (for current chat)`29 Add chat to blacklist and ignores global broadcast.30• `{i}ungblacklist` `Remove the chat from blacklist.`31 32• `{i}gpromote <reply to user> <channel/group/all> <rank>`33 globally promote user where you are admin34 - Set whether To promote only in groups/channels/all.35 Eg- `gpromote group boss` ~ promotes user in all grps.36 `gpromote @username all sar` ~ promote the user in all group & channel37• `{i}gdemote` - `demote user globally`38"""39import asyncio40import os41 42from telethon.errors.rpcerrorlist import ChatAdminRequiredError, FloodWaitError43from telethon.tl.functions.channels import EditAdminRequest44from telethon.tl.functions.contacts import BlockRequest, UnblockRequest45from telethon.tl.types import ChatAdminRights, User46 47from pyUltroid.dB import DEVLIST48from pyUltroid.dB.base import KeyManager49from pyUltroid.dB.gban_mute_db import (50 gban,51 gmute,52 is_gbanned,53 is_gmuted,54 list_gbanned,55 ungban,56 ungmute,57)58from pyUltroid.fns.tools import create_tl_btn, format_btn, get_msg_button59 60from . import (61 HNDLR,62 LOGS,63 NOSPAM_CHAT,64 OWNER_NAME,65 eod,66 eor,67 get_string,68 inline_mention,69 ultroid_bot,70 ultroid_cmd,71)72from ._inline import something73 74_gpromote_rights = ChatAdminRights(75 add_admins=False,76 invite_users=True,77 change_info=False,78 ban_users=True,79 delete_messages=True,80 pin_messages=True,81)82 83_gdemote_rights = ChatAdminRights(84 add_admins=False,85 invite_users=False,86 change_info=False,87 ban_users=False,88 delete_messages=False,89 pin_messages=False,90)91 92keym = KeyManager("GBLACKLISTS", cast=list)93 94 95@ultroid_cmd(pattern="gpromote( (.*)|$)", fullsudo=True)96async def _(e):97 x = e.pattern_match.group(1).strip()98 ultroid_bot = e.client99 if not x:100 return await e.eor(get_string("schdl_2"), time=5)101 user = await e.get_reply_message()102 if user:103 ev = await e.eor("`Promoting Replied User Globally`")104 ok = e.text.split()105 key = "all"106 if len(ok) > 1 and (("group" in ok[1]) or ("channel" in ok[1])):107 key = ok[1]108 rank = ok[2] if len(ok) > 2 else "AdMin"109 c = 0110 user.id = user.peer_id.user_id if e.is_private else user.from_id.user_id111 async for x in e.client.iter_dialogs():112 if (113 "group" in key.lower()114 and x.is_group115 or "group" not in key.lower()116 and "channel" in key.lower()117 and x.is_channel118 ):119 try:120 await e.client(121 EditAdminRequest(122 x.id,123 user.id,124 _gpromote_rights,125 rank,126 ),127 )128 c += 1129 except BaseException:130 pass131 elif (132 ("group" not in key.lower() or x.is_group)133 and (134 "group" in key.lower()135 or "channel" not in key.lower()136 or x.is_channel137 )138 and (139 "group" in key.lower()140 or "channel" in key.lower()141 or x.is_group142 or x.is_channel143 )144 ):145 try:146 await e.client(147 EditAdminRequest(148 x.id,149 user.id,150 _gpromote_rights,151 rank,152 ),153 )154 c += 1155 except Exception as er:156 LOGS.info(er)157 await eor(ev, f"Promoted The Replied Users in Total : {c} {key} chats")158 else:159 k = e.text.split()160 if not k[1]:161 return await eor(162 e, "`Give someone's username/id or replied to user.", time=5163 )164 user = k[1]165 if user.isdigit():166 user = int(user)167 try:168 name = await e.client.get_entity(user)169 except BaseException:170 return await e.eor(f"`No User Found Regarding {user}`", time=5)171 ev = await e.eor(f"`Promoting {name.first_name} globally.`")172 key = "all"173 if len(k) > 2 and (("group" in k[2]) or ("channel" in k[2])):174 key = k[2]175 rank = k[3] if len(k) > 3 else "AdMin"176 c = 0177 async for x in e.client.iter_dialogs():178 if (179 "group" in key.lower()180 and x.is_group181 or "group" not in key.lower()182 and "channel" in key.lower()183 and x.is_channel184 or "group" not in key.lower()185 and "channel" not in key.lower()186 and (x.is_group or x.is_channel)187 ):188 try:189 await ultroid_bot(190 EditAdminRequest(191 x.id,192 user,193 _gpromote_rights,194 rank,195 ),196 )197 c += 1198 except BaseException:199 pass200 await eor(ev, f"Promoted {name.first_name} in Total : {c} {key} chats.")201 202 203@ultroid_cmd(pattern="gdemote( (.*)|$)", fullsudo=True)204async def _(e):205 x = e.pattern_match.group(1).strip()206 ultroid_bot = e.client207 if not x:208 return await e.eor(get_string("schdl_2"), time=5)209 user = await e.get_reply_message()210 if user:211 user.id = user.peer_id.user_id if e.is_private else user.from_id.user_id212 ev = await e.eor("`Demoting Replied User Globally`")213 ok = e.text.split()214 key = "all"215 if len(ok) > 1 and (("group" in ok[1]) or ("channel" in ok[1])):216 key = ok[1]217 rank = "Not AdMin"218 c = 0219 async for x in e.client.iter_dialogs():220 if (221 "group" in key.lower()222 and x.is_group223 or "group" not in key.lower()224 and "channel" in key.lower()225 and x.is_channel226 or "group" not in key.lower()227 and "channel" not in key.lower()228 and (x.is_group or x.is_channel)229 ):230 try:231 await ultroid_bot(232 EditAdminRequest(233 x.id,234 user.id,235 _gdemote_rights,236 rank,237 ),238 )239 c += 1240 except BaseException:241 pass242 await eor(ev, f"Demoted The Replied Users in Total : {c} {key} chats")243 else:244 k = e.text.split()245 if not k[1]:246 return await eor(247 e, "`Give someone's username/id or replied to user.", time=5248 )249 user = k[1]250 if user.isdigit():251 user = int(user)252 try:253 name = await ultroid_bot.get_entity(user)254 except BaseException:255 return await e.eor(f"`No User Found Regarding {user}`", time=5)256 ev = await e.eor(f"`Demoting {name.first_name} globally.`")257 key = "all"258 if len(k) > 2 and (("group" in k[2]) or ("channel" in k[2])):259 key = k[2]260 rank = "Not AdMin"261 c = 0262 async for x in ultroid_bot.iter_dialogs():263 if (264 "group" in key.lower()265 and x.is_group266 or "group" not in key.lower()267 and "channel" in key.lower()268 and x.is_channel269 or "group" not in key.lower()270 and "channel" not in key.lower()271 and (x.is_group or x.is_channel)272 ):273 try:274 await ultroid_bot(275 EditAdminRequest(276 x.id,277 user,278 _gdemote_rights,279 rank,280 ),281 )282 c += 1283 except BaseException:284 pass285 await eor(ev, f"Demoted {name.first_name} in Total : {c} {key} chats.")286 287 288@ultroid_cmd(pattern="ungban( (.*)|$)", fullsudo=True)289async def _(e):290 xx = await e.eor("`UnGbanning...`")291 match = e.pattern_match.group(1).strip()292 peer = None293 if e.reply_to_msg_id:294 userid = (await e.get_reply_message()).sender_id295 elif match:296 try:297 userid = int(match)298 except ValueError:299 userid = match300 try:301 userid = (await e.client.get_entity(userid)).id302 except Exception as er:303 return await xx.edit(f"Failed to get User...\nError: {er}")304 elif e.is_private:305 userid = e.chat_id306 else:307 return await xx.eor("`Reply to some msg or add their id.`", time=5)308 if not is_gbanned(userid):309 return await xx.edit("`User/Channel is not Gbanned...`")310 try:311 if not peer:312 peer = await e.client.get_entity(userid)313 name = inline_mention(peer)314 except BaseException:315 userid = int(userid)316 name = str(userid)317 chats = 0318 if e.client._dialogs:319 dialog = e.client._dialogs320 else:321 dialog = await e.client.get_dialogs()322 e.client._dialogs.extend(dialog)323 for ggban in dialog:324 if ggban.is_group or ggban.is_channel:325 try:326 await e.client.edit_permissions(ggban.id, userid, view_messages=True)327 chats += 1328 except FloodWaitError as fw:329 LOGS.info(330 f"[FLOOD_WAIT_ERROR] : on Ungban\nSleeping for {fw.seconds+10}"331 )332 await asyncio.sleep(fw.seconds + 10)333 try:334 await e.client.edit_permissions(335 ggban.id, userid, view_messages=True336 )337 chats += 1338 except BaseException as er:339 LOGS.exception(er)340 except (ChatAdminRequiredError, ValueError):341 pass342 except BaseException as er:343 LOGS.exception(er)344 ungban(userid)345 if isinstance(peer, User):346 await e.client(UnblockRequest(userid))347 await xx.edit(348 f"`Ungbaned` {name} in {chats} `chats.\nRemoved from gbanwatch.`",349 )350 351 352@ultroid_cmd(pattern="gban( (.*)|$)", fullsudo=True)353async def _(e):354 xx = await e.eor("`Gbanning...`")355 reason = ""356 if e.reply_to_msg_id:357 userid = (await e.get_reply_message()).sender_id358 try:359 reason = e.text.split(" ", maxsplit=1)[1]360 except IndexError:361 pass362 elif e.pattern_match.group(1).strip():363 usr = e.text.split(maxsplit=2)[1]364 try:365 userid = await e.client.parse_id(usr)366 except ValueError:367 userid = usr368 try:369 reason = e.text.split(maxsplit=2)[2]370 except IndexError:371 pass372 elif e.is_private:373 userid = e.chat_id374 try:375 reason = e.text.split(" ", maxsplit=1)[1]376 except IndexError:377 pass378 else:379 return await xx.eor("`Reply to some msg or add their id.`", time=5)380 user = None381 try:382 user = await e.client.get_entity(userid)383 name = inline_mention(user)384 except BaseException:385 userid = int(userid)386 name = str(userid)387 chats = 0388 if userid == ultroid_bot.uid:389 return await xx.eor("`I can't gban myself.`", time=3)390 elif userid in DEVLIST:391 return await xx.eor("`I can't gban my Developers.`", time=3)392 elif is_gbanned(userid):393 return await eod(394 xx,395 "`User is already gbanned and added to gbanwatch.`",396 time=4,397 )398 if e.client._dialogs:399 dialog = e.client._dialogs400 else:401 dialog = await e.client.get_dialogs()402 e.client._dialogs.extend(dialog)403 for ggban in dialog:404 if ggban.is_group or ggban.is_channel:405 try:406 await e.client.edit_permissions(ggban.id, userid, view_messages=False)407 chats += 1408 except FloodWaitError as fw:409 LOGS.info(410 f"[FLOOD_WAIT_ERROR] : on GBAN Command\nSleeping for {fw.seconds+10}"411 )412 await asyncio.sleep(fw.seconds + 10)413 try:414 await e.client.edit_permissions(415 ggban.id, userid, view_messages=False416 )417 chats += 1418 except BaseException as er:419 LOGS.exception(er)420 except (ChatAdminRequiredError, ValueError):421 pass422 except BaseException as er:423 LOGS.exception(er)424 gban(userid, reason)425 if isinstance(user, User):426 await e.client(BlockRequest(userid))427 gb_msg = f"**#Gbanned** {name} `in {chats} chats and added to gbanwatch!`"428 if reason:429 gb_msg += f"\n**Reason** : {reason}"430 await xx.edit(gb_msg)431 432 433@ultroid_cmd(pattern="g(admin|)cast( (.*)|$)", fullsudo=True)434async def gcast(event):435 text, btn, reply = "", None, None436 if xx := event.pattern_match.group(2):437 msg, btn = get_msg_button(event.text.split(maxsplit=1)[1])438 elif event.is_reply:439 reply = await event.get_reply_message()440 msg = reply.text441 if reply.buttons:442 btn = format_btn(reply.buttons)443 else:444 msg, btn = get_msg_button(msg)445 else:446 return await eor(447 event, "`Give some text to Globally Broadcast or reply a message..`"448 )449 450 kk = await event.eor("`Globally Broadcasting Msg...`")451 er = 0452 done = 0453 err = ""454 if event.client._dialogs:455 dialog = event.client._dialogs456 else:457 dialog = await event.client.get_dialogs()458 event.client._dialogs.extend(dialog)459 for x in dialog:460 if x.is_group:461 chat = x.entity.id462 if (463 not keym.contains(chat)464 and int(f"-100{str(chat)}") not in NOSPAM_CHAT465 and (466 (467 event.text[2:7] != "admin"468 or (x.entity.admin_rights or x.entity.creator)469 )470 )471 ):472 try:473 if btn:474 bt = create_tl_btn(btn)475 await something(476 event,477 msg,478 reply.media if reply else None,479 bt,480 chat=chat,481 reply=False,482 )483 else:484 await event.client.send_message(485 chat, msg, file=reply.media if reply else None486 )487 done += 1488 except FloodWaitError as fw:489 await asyncio.sleep(fw.seconds + 10)490 try:491 if btn:492 bt = create_tl_btn(btn)493 await something(494 event,495 msg,496 reply.media if reply else None,497 bt,498 chat=chat,499 reply=False,500 )501 else:502 await event.client.send_message(503 chat, msg, file=reply.media if reply else None504 )505 done += 1506 except Exception as rr:507 err += f"• {rr}\n"508 er += 1509 except BaseException as h:510 err += f"• {str(h)}" + "\n"511 er += 1512 text += f"Done in {done} chats, error in {er} chat(s)"513 if err != "":514 open("gcast-error.log", "w+").write(err)515 text += f"\nYou can do `{HNDLR}ul gcast-error.log` to know error report."516 await kk.edit(text)517 518 519@ultroid_cmd(pattern="gucast( (.*)|$)", fullsudo=True)520async def gucast(event):521 msg, btn, reply = "", None, None522 if xx := event.pattern_match.group(1).strip():523 msg, btn = get_msg_button(event.text.split(maxsplit=1)[1])524 elif event.is_reply:525 reply = await event.get_reply_message()526 msg = reply.text527 if reply.buttons:528 btn = format_btn(reply.buttons)529 else:530 msg, btn = get_msg_button(msg)531 else:532 return await eor(533 event, "`Give some text to Globally Broadcast or reply a message..`"534 )535 kk = await event.eor("`Globally Broadcasting Msg...`")536 er = 0537 done = 0538 if event.client._dialogs:539 dialog = event.client._dialogs540 else:541 dialog = await event.client.get_dialogs()542 event.client._dialogs.extend(dialog)543 for x in dialog:544 if x.is_user and not x.entity.bot:545 chat = x.id546 if not keym.contains(chat):547 try:548 if btn:549 bt = create_tl_btn(btn)550 await something(551 event,552 msg,553 reply.media if reply else None,554 bt,555 chat=chat,556 reply=False,557 )558 else:559 await event.client.send_message(560 chat, msg, file=reply.media if reply else None561 )562 done += 1563 except BaseException:564 er += 1565 await kk.edit(f"Done in {done} chats, error in {er} chat(s)")566 567 568@ultroid_cmd(pattern="gkick( (.*)|$)", fullsudo=True)569async def gkick(e):570 xx = await e.eor("`Gkicking...`")571 if e.reply_to_msg_id:572 userid = (await e.get_reply_message()).sender_id573 elif e.pattern_match.group(1).strip():574 userid = await e.client.parse_id(e.pattern_match.group(1).strip())575 elif e.is_private:576 userid = e.chat_id577 else:578 return await xx.edit("`Reply to some msg or add their id.`", time=5)579 name = (await e.client.get_entity(userid)).first_name580 chats = 0581 if userid == ultroid_bot.uid:582 return await xx.eor("`I can't gkick myself.`", time=3)583 if userid in DEVLIST:584 return await xx.eor("`I can't gkick my Developers.`", time=3)585 if e.client._dialogs:586 dialog = e.client._dialogs587 else:588 dialog = await e.client.get_dialogs()589 e.client._dialogs.extend(dialog)590 for gkick in dialog:591 if gkick.is_group or gkick.is_channel:592 try:593 await e.client.kick_participant(gkick.id, userid)594 chats += 1595 except BaseException:596 pass597 await xx.edit(f"`Gkicked` [{name}](tg://user?id={userid}) `in {chats} chats.`")598 599 600@ultroid_cmd(pattern="gmute( (.*)|$)", fullsudo=True)601async def _(e):602 xx = await e.eor("`Gmuting...`")603 if e.reply_to_msg_id:604 userid = (await e.get_reply_message()).sender_id605 elif e.pattern_match.group(1).strip():606 userid = await e.client.parse_id(e.pattern_match.group(1).strip())607 elif e.is_private:608 userid = e.chat_id609 else:610 return await xx.eor("`Reply to some msg or add their id.`", tome=5, time=5)611 name = await e.client.get_entity(userid)612 chats = 0613 if userid == ultroid_bot.uid:614 return await xx.eor("`I can't gmute myself.`", time=3)615 if userid in DEVLIST:616 return await xx.eor("`I can't gmute my Developers.`", time=3)617 if is_gmuted(userid):618 return await xx.eor("`User is already gmuted.`", time=4)619 if e.client._dialogs:620 dialog = e.client._dialogs621 else:622 dialog = await e.client.get_dialogs()623 e.client._dialogs.extend(dialog)624 for onmute in dialog:625 if onmute.is_group:626 try:627 await e.client.edit_permissions(onmute.id, userid, send_messages=False)628 chats += 1629 except BaseException:630 pass631 gmute(userid)632 await xx.edit(f"`Gmuted` {inline_mention(name)} `in {chats} chats.`")633 634 635@ultroid_cmd(pattern="ungmute( (.*)|$)", fullsudo=True)636async def _(e):637 xx = await e.eor("`UnGmuting...`")638 if e.reply_to_msg_id:639 userid = (await e.get_reply_message()).sender_id640 elif e.pattern_match.group(1).strip():641 userid = await e.client.parse_id(e.pattern_match.group(1).strip())642 elif e.is_private:643 userid = e.chat_id644 else:645 return await xx.eor("`Reply to some msg or add their id.`", time=5)646 name = (await e.client.get_entity(userid)).first_name647 chats = 0648 if not is_gmuted(userid):649 return await xx.eor("`User is not gmuted.`", time=3)650 if e.client._dialogs:651 dialog = e.client._dialogs652 else:653 dialog = await e.client.get_dialogs()654 e.client._dialogs.extend(dialog)655 for hurr in dialog:656 if hurr.is_group:657 try:658 await e.client.edit_permissions(hurr.id, userid, send_messages=True)659 chats += 1660 except BaseException:661 pass662 ungmute(userid)663 await xx.edit(f"`Ungmuted` {inline_mention(name)} `in {chats} chats.`")664 665 666@ultroid_cmd(667 pattern="listgban$",668)669async def list_gengbanned(event):670 users = list_gbanned()671 x = await event.eor(get_string("com_1"))672 msg = ""673 if not users:674 return await x.edit("`You haven't GBanned anyone!`")675 for i in users:676 try:677 name = await event.client.get_entity(int(i))678 except BaseException:679 name = i680 msg += f"<strong>User</strong>: {inline_mention(name, html=True)}\n"681 reason = users[i]682 msg += f"<strong>Reason</strong>: {reason}\n\n" if reason is not None else "\n"683 gbanned_users = f"<strong>List of users GBanned by {OWNER_NAME}</strong>:\n\n{msg}"684 if len(gbanned_users) > 4096:685 with open("gbanned.txt", "w") as f:686 f.write(687 gbanned_users.replace("<strong>", "")688 .replace("</strong>", "")689 .replace("<a href=tg://user?id=", "")690 .replace("</a>", "")691 )692 await x.reply(693 file="gbanned.txt",694 message=f"List of users GBanned by {inline_mention(ultroid_bot.me)}",695 )696 os.remove("gbanned.txt")697 await x.delete()698 else:699 await x.edit(gbanned_users, parse_mode="html")700 701 702@ultroid_cmd(703 pattern="gstat( (.*)|$)",704)705async def gstat_(e):706 xx = await e.eor(get_string("com_1"))707 if e.is_private:708 userid = (await e.get_chat()).id709 elif e.reply_to_msg_id:710 userid = (await e.get_reply_message()).sender_id711 elif e.pattern_match.group(1).strip():712 try:713 userid = await e.client.parse_id(e.pattern_match.group(1).strip())714 except Exception as err:715 return await xx.eor(f"{err}", time=10)716 else:717 return await xx.eor("`Reply to some msg or add their id.`", time=5)718 name = (await e.client.get_entity(userid)).first_name719 msg = f"**{name} is "720 is_banned = is_gbanned(userid)721 reason = list_gbanned().get(userid)722 if is_banned:723 msg += "Globally Banned"724 msg += f" with reason** `{reason}`" if reason else ".**"725 else:726 msg += "not Globally Banned.**"727 await xx.edit(msg)728 729 730@ultroid_cmd(pattern="gblacklist$")731async def blacklist_(event):732 await gblacker(event, "add")733 734 735@ultroid_cmd(pattern="ungblacklist$")736async def ungblacker(event):737 await gblacker(event, "remove")738 739 740async def gblacker(event, type_):741 try:742 chat_id = int(event.text.split(maxsplit=1)[1])743 try:744 chat_id = (await event.client.get_entity(chat_id)).id745 except Exception as e:746 return await event.eor(f"**ERROR**\n`{str(e)}`")747 except IndexError:748 chat_id = event.chat_id749 if type_ == "add":750 keym.add(chat_id)751 elif type_ == "remove":752 keym.remove(chat_id)753 await event.eor(f"Global Broadcasts: \n{type_}ed {chat_id}")754 