async def ultroid(event): args = event.pattern_match.group(1).strip() if not is_added(event.sender_id) and event.sender_id not in owner_and_sudos(): add_user(event.sender_id) kak_uiw = udB.get_key("OFF_START_LOG") if not kak_uiw or kak_uiw != True: msg = f"{inline_mention(event.sender)} `[{event.sender_id}]` started your [Assistant bot](@{asst.me.username})." buttons = [[Button.inline("Info", "itkkstyo")]] if event.sender.username: buttons[0].append( Button.mention( "User", await event.client.get_input_entity(event.sender_id) ) ) await event.client.send_message( udB.get_key("LOG_CHANNEL"), msg, buttons=buttons ) if event.sender_id not in SUDO_M.fullsudos: ok = "" me = inline_mention(ultroid_bot.me) mention = inline_mention(event.sender) if args and args != "set": await get_stored_file(event, args) if not udB.get_key("STARTMSG"): if udB.get_key("PMBOT"): ok = "You can contact my master using this bot!!\n\nSend your Message, I will Deliver it To Master." await event.reply( f"Hey there {mention}, this is Ultroid Assistant of {me}!\n\n{ok}", file=udB.get_key("STARTMEDIA"), buttons=[Button.inline("Info.", data="ownerinfo")] if Owner_info_msg else None, ) else: await event.reply( udB.get_key("STARTMSG").format(me=me, mention=mention), file=udB.get_key("STARTMEDIA"), buttons=[Button.inline("Info.", data="ownerinfo")] if Owner_info_msg else None, ) else: name = get_display_name(event.sender) if args == "set": await event.reply( "Choose from the below options -", buttons=_settings, ) elif args: await get_stored_file(event, args) else: await event.reply( get_string("ast_3").format(name), buttons=_start, )
async def own(event): msg = Owner_info_msg.format(mention=event.sender.mention, me=inline_mention(ultroid_bot.me)) if custom_info: msg += "\n\n• Powered by **@TheUltroid**" await event.edit( msg, buttons=[Button.inline("Close", data="closeit")], link_preview=False, )
async def choose_cata(event): match = event.data_match.group(1).decode("utf-8") if not match: if TR_BTS.get("category"): buttons = TR_BTS["category"] else: req = (await async_searcher("https://opentdb.com/api_category.php", re_json=True))["trivia_categories"] btt = [] for i in req: name = i["name"] if ":" in name: name = name.split(":")[1] btt.append(Button.inline(name, f"trziad_{i['id']}")) buttons = list(zip(btt[::2], btt[1::2])) if len(btt) % 2 == 1: buttons.append((btt[-1], )) buttons.append([Button.inline("Cancel ❌", "delit")]) TR_BTS.update({"category": buttons}) text = get_string("games_2") elif match[0] == "d": cat = match[1:] buttons = [[Button.inline(i, f"trziac{cat}_{i}") for i in DIFI_KEYS]] buttons.append(get_back_button("trzia")) text = get_string("games_3") elif match[0] == "c": m = match[1:] buttons = [[ Button.inline(str(i), f"trziat{m}_{i}") for i in range(10, 70, 20) ]] text = get_string("games_4") elif match[0] == "t": m_ = match[1:] buttons = [[ Button.inline(str(i), f"trzias{m_}_{i}") for i in [10, 30, 60, 120] ]] text = get_string("games_5") elif match[0] == "s": chat = event.chat_id cat, le, nu, in_ = match[2:].split("_") msg = await event.edit(get_string("games_6").format(le, nu)) for i in reversed(range(5)): msg = await msg.edit(buttons=Button.inline(f"{i} ⏰", f"ctdown{i}")) await asyncio.sleep(1) await msg.edit(msg.text + "\n\n• Send /cancel to stop the Quiz...", buttons=None) qsss = await async_searcher( f"https://opentdb.com/api.php?amount={nu}&category={cat}&difficulty={le.lower()}", re_json=True, ) qs = qsss["results"] if not qs: await event.respond( "Sorry, No Question Found for the given Criteria..") await event.delete() return TRIVIA_CHATS.update({chat: {}}) for copper, q in enumerate(qs): if TRIVIA_CHATS[chat].get("cancel") is not None: break ansi = str(uuid.uuid1()).split("-")[0].encode() opts = [PollAnswer(unescape(q["correct_answer"]), ansi)] [ opts.append( PollAnswer(unescape(a), str(uuid.uuid1()).split("-")[0].encode())) for a in q["incorrect_answers"] ] shuffle(opts) poll = InputMediaPoll( Poll( 0, f"[{copper+1}]. " + unescape(q["question"]), answers=opts, public_voters=True, quiz=True, close_period=int(in_), ), correct_answers=[ansi], solution="Join @TheUltroid", solution_entities=[], ) m_ = await event.client.send_message(chat, file=poll) POLLS.update( {m_.poll.poll.id: { "chat": m_.chat_id, "answer": ansi }}) await asyncio.sleep(int(in_)) if not TRIVIA_CHATS[chat]: await event.respond( "No-One Got Any Score in the Quiz!\nBetter Luck Next Time!") else: try: await event.respond(file=choice(CONGO_STICKER)) except ChatSendStickersForbiddenError: pass LBD = "🎯 **Scoreboard of the Quiz.**\n\n" TRC = TRIVIA_CHATS[chat] if "cancel" in TRC.keys(): del TRC["cancel"] for userid, user_score in dict( sorted(TRC.items(), key=operator.itemgetter(1), reverse=True)).items(): user = inline_mention(await event.client.get_entity(userid)) LBD += f"••• {user} - {user_score}\n" await event.respond(LBD) del TRIVIA_CHATS[chat] list_ = list(POLLS.copy().keys()) for key in list_: if POLLS[key]["chat"] == chat: del POLLS[key] return await event.edit(text, buttons=buttons)
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)