async def astcmds(e): xx = (e.text.replace("/", "")).lower().split()[0] if cmd_reply(xx): msg, media, bt = cmd_reply(xx) if bt: bt = create_tl_btn(bt) await e.reply(msg, file=media, buttons=bt)
async def butt(event): media, wut, text = None, None, None if event.reply_to: wt = await event.get_reply_message() if wt.text: text = wt.text if wt.media: wut = mediainfo(wt.media) if wut and wut.startswith(("pic", "gif")): dl = await wt.download_media() variable = uf(dl) media = "https://telegra.ph" + variable[0] elif wut == "video": if wt.media.document.size > 8 * 1000 * 1000: return await event.eor(get_string("com_4"), time=5) dl = await wt.download_media() variable = uf(dl) os.remove(dl) media = "https://telegra.ph" + variable[0] else: media = pack_bot_file_id(wt.media) try: text = event.text.split(maxsplit=1)[1] except IndexError: if not text: return await event.eor( f"**Please give some text in correct format.**\n\n`{HNDLR}help button`", ) text, buttons = get_msg_button(text) if buttons: buttons = create_tl_btn(buttons) await something(event, text, media, buttons) await event.delete()
async def listwel(event): wel = get_welcome(event.chat_id) if not wel: return await event.eor(get_string("grt_4"), time=5) msgg, med = wel["welcome"], wel["media"] if wel.get("button"): btn = create_tl_btn(wel["button"]) return await something(event, msgg, med, btn) await event.reply(f"**Welcome Note in this chat**\n\n`{msgg}`", file=med) await event.delete()
async def listgd(event): wel = get_goodbye(event.chat_id) if not wel: return await eor(event, get_string("grt_6"), time=5) msgg = wel["goodbye"] med = wel["media"] if wel.get("button"): btn = create_tl_btn(wel["button"]) return await something(event, msgg, med, btn) await event.reply(f"**Goodbye Note in this chat**\n\n`{msgg}`", file=med) await event.delete()
async def notes(e): xx = [ z.replace("#", "") for z in e.text.lower().split() if z.startswith("#") ] for word in xx: k = get_notes(e.chat_id, word) if k: msg = k["msg"] media = k["media"] if k.get("button"): btn = create_tl_btn(k["button"]) return await something(e, msg, media, btn) await e.reply(msg, file=media)
async def gcast(event): text, btn, reply = "", None, None xx = event.pattern_match.group(2) if xx: msg, btn = get_msg_button(event.text.split(maxsplit=1)[1]) elif event.is_reply: reply = await event.get_reply_message() msg = reply.text if reply.buttons: btn = format_btn(reply.buttons) else: msg, btn = get_msg_button(msg) else: return await eor( event, "`Give some text to Globally Broadcast or reply a message..`") kk = await eor(event, "`Globally Broadcasting Msg...`") er = 0 done = 0 err = "" async for x in event.client.iter_dialogs(): if x.is_group: chat = x.entity.id if (not is_gblacklisted(chat) and int("-100" + str(chat)) not in NOSPAM_CHAT and (event.text[2:7] != "admin" or (x.entity.admin_rights or x.entity.creator))): try: if btn: bt = create_tl_btn(btn) await something( event, msg, reply.media if reply else None, bt, chat=chat, reply=False, ) else: await event.client.send_message( chat, msg, file=reply.media if reply else None) done += 1 except Exception as h: err += "• " + str(h) + "\n" er += 1 text += f"Done in {done} chats, error in {er} chat(s)" if err != "": open("gcast-error.log", "w+").write(err) text += f"\nYou can do `{HNDLR}ul gcast-error.log` to know error report." await kk.edit(text)
async def add_snips(e): if not e.out and e.sender_id not in sudoers(): return xx = [ z.replace("$", "") for z in e.text.lower().split() if z.startswith("$") ] for z in xx: k = get_snips(z) if k: msg = k["msg"] media = k["media"] rep = await e.get_reply_message() if rep: if k.get("button"): btn = create_tl_btn(k["button"]) return await something(rep, msg, media, btn) await rep.reply(msg, file=media) else: await e.delete() if k.get("button"): btn = create_tl_btn(k["button"]) return await something(e, msg, media, btn, reply=None) await ultroid_bot.send_message(e.chat_id, msg, file=media)
async def gucast(event): msg, btn, reply = "", None, None xx = event.pattern_match.group(1) if xx: msg, btn = get_msg_button(event.text.split(maxsplit=1)[1]) elif event.is_reply: reply = await event.get_reply_message() msg = reply.text if reply.buttons: btn = format_btn(reply.buttons) else: msg, btn = get_msg_button(msg) else: return await eor( event, "`Give some text to Globally Broadcast or reply a message..`") kk = await event.eor("`Globally Broadcasting Msg...`") er = 0 done = 0 if event.client._dialogs: dialog = event.client._dialogs else: dialog = await event.client.get_dialogs() event.client._dialogs.extend(dialog) for x in dialog: if x.is_user and not x.entity.bot: chat = x.id if not is_gblacklisted(chat): try: if btn: bt = create_tl_btn(btn) await something( event, msg, reply.media if reply else None, bt, chat=chat, reply=False, ) else: await event.client.send_message( chat, msg, file=reply.media if reply else None) done += 1 except BaseException: er += 1 await kk.edit(f"Done in {done} chats, error in {er} chat(s)")
async def filter_func(e): if isinstance(e.sender, User) and e.sender.bot: return xx = (e.text).lower() chat = e.chat_id x = get_filter(chat) if x: for c in x: pat = r"( |^|[^\w])" + re.escape(c) + r"( |$|[^\w])" if re.search(pat, xx): k = x.get(c) if k: msg = k["msg"] media = k["media"] if k.get("button"): btn = create_tl_btn(k["button"]) return await something(e, msg, media, btn) await e.reply(msg, file=media)
async def DummyHandler(ult): # clean chat actions key = udB.get_key("CLEANCHAT") or [] if ult.chat_id in key: try: await ult.delete() except BaseException: pass # thank members if must_thank(ult.chat_id): chat_count = (await ult.client.get_participants(ult.chat_id, limit=0)).total if chat_count % 100 == 0: stik_id = chat_count / 100 - 1 sticker = stickers[stik_id] await ult.respond(file=sticker) # force subscribe if (udB.get_key("FORCESUB") and ((ult.user_joined or ult.user_added)) and get_forcesetting(ult.chat_id)): user = await ult.get_user() if not user.bot: joinchat = get_forcesetting(ult.chat_id) try: await ultroid_bot(GetParticipantRequest( int(joinchat), user.id)) except UserNotParticipantError: await ultroid_bot.edit_permissions(ult.chat_id, user.id, send_messages=False) res = await ultroid_bot.inline_query( asst.me.username, f"fsub {user.id}_{joinchat}") await res[0].click(ult.chat_id, reply_to=ult.action_message.id) if ult.user_joined or ult.added_by: user = await ult.get_user() chat = await ult.get_chat() # gbans and @UltroidBans checks if udB.get_key("ULTROID_BANS"): try: is_banned = await async_searcher( "https://bans.ultroid.tech/api/status", json={"userId": user.id}, post=True, re_json=True, ) if is_banned["is_banned"]: await ult.client.edit_permissions( chat.id, user.id, view_messages=False, ) await ult.client.send_message( chat.id, "**@UltroidBans:** Banned user detected and banned!\n`{}`.\nBan reason: {}" .format( str(is_banned), is_banned["reason"], ), ) except BaseException: pass reason = is_gbanned(user.id) if reason and chat.admin_rights: try: await ult.client.edit_permissions( chat.id, user.id, view_messages=False, ) gban_watch = get_string("can_1").format( inline_mention(user), reason) await ult.reply(gban_watch) except Exception as er: LOGS.exception(er) # greetings elif get_welcome(ult.chat_id): user = await ult.get_user() chat = await ult.get_chat() title = chat.title or "this chat" count = (chat.participants_count or (await ult.client.get_participants(chat, limit=0)).total) mention = inline_mention(user) name = user.first_name fullname = get_display_name(user) uu = user.username username = f"@{uu}" if uu else mention wel = get_welcome(ult.chat_id) msgg = wel["welcome"] med = wel["media"] or None userid = user.id msg = None if msgg: msg = msgg.format( mention=mention, group=title, count=count, name=name, fullname=fullname, username=username, userid=userid, ) if wel.get("button"): btn = create_tl_btn(wel["button"]) await something(ult, msg, med, btn) elif msg: send = await ult.reply( msg, file=med, ) await asyncio.sleep(150) await send.delete() else: await ult.reply(file=med) elif (ult.user_left or ult.user_kicked) and get_goodbye(ult.chat_id): user = await ult.get_user() chat = await ult.get_chat() title = chat.title or "this chat" count = (chat.participants_count or (await ult.client.get_participants(chat, limit=0)).total) mention = inline_mention(user) name = user.first_name fullname = get_display_name(user) uu = user.username username = f"@{uu}" if uu else mention wel = get_goodbye(ult.chat_id) msgg = wel["goodbye"] med = wel["media"] userid = user.id msg = None if msgg: msg = msgg.format( mention=mention, group=title, count=count, name=name, fullname=fullname, username=username, userid=userid, ) if wel.get("button"): btn = create_tl_btn(wel["button"]) await something(ult, msg, med, btn) elif msg: send = await ult.reply( msg, file=med, ) await asyncio.sleep(150) await send.delete() else: await ult.reply(file=med)
async def ChatActionsHandler(ult): # sourcery no-metrics # clean chat actions if is_clean_added(ult.chat_id): try: await ult.delete() except BaseException: pass # thank members if must_thank(ult.chat_id): chat_count = (await ult.client.get_participants(ult.chat_id, limit=0)).total if chat_count % 100 == 0: stik_id = chat_count / 100 - 1 sticker = stickers[stik_id] await ult.respond(file=sticker) # force subscribe if ( udB.get("FORCESUB") and ((ult.user_joined or ult.user_added)) and get_forcesetting(ult.chat_id) ): user = await ult.get_user() if not user.bot: joinchat = get_forcesetting(ult.chat_id) try: await ultroid_bot(GetParticipantRequest(int(joinchat), user.id)) except UserNotParticipantError: await ultroid_bot.edit_permissions( ult.chat_id, user.id, send_messages=False ) res = await ultroid_bot.inline_query( asst.me.username, f"fsub {user.id}_{joinchat}" ) await res[0].click(ult.chat_id, reply_to=ult.action_message.id) # gban checks if ult.user_joined or ult.added_by: user = await ult.get_user() chat = await ult.get_chat() reason = is_gbanned(user.id) if reason and chat.admin_rights: try: await ult.client.edit_permissions( chat.id, user.id, view_messages=False, ) gban_watch = get_string("can_1").format(inline_mention(user), reason) await ult.reply(gban_watch) except Exception as er: LOGS.exception(er) # greetings elif get_welcome(ult.chat_id): user = await ult.get_user() chat = await ult.get_chat() title = chat.title or "this chat" count = (await ult.client.get_participants(chat, limit=0)).total mention = inline_mention(user) name = user.first_name fullname = get_display_name(user) uu = user.username username = f"@{uu}" if uu else mention wel = get_welcome(ult.chat_id) msgg = wel["welcome"] med = wel["media"] or None userid = user.id msg = None if msgg: msg = msgg.format( mention=mention, group=title, count=count, name=name, fullname=fullname, username=username, userid=userid, ) if wel.get("button"): btn = create_tl_btn(wel["button"]) await something(ult, msg, med, btn) elif msg: send = await ult.reply( msg, file=med, ) await asyncio.sleep(150) await send.delete() else: await ult.reply(file=med) elif (ult.user_left or ult.user_kicked) and get_goodbye(ult.chat_id): user = await ult.get_user() chat = await ult.get_chat() title = chat.title or "this chat" count = (await ult.client.get_participants(chat, limit=0)).total mention = inline_mention(user) name = user.first_name fullname = get_display_name(user) uu = user.username username = f"@{uu}" if uu else mention wel = get_goodbye(ult.chat_id) msgg = wel["goodbye"] med = wel["media"] userid = user.id msg = None if msgg: msg = msgg.format( mention=mention, group=title, count=count, name=name, fullname=fullname, username=username, userid=userid, ) if wel.get("button"): btn = create_tl_btn(wel["button"]) await something(ult, msg, med, btn) elif msg: send = await ult.reply( msg, file=med, ) await asyncio.sleep(150) await send.delete() else: await ult.reply(file=med)