async def frybot(event): "Fries the given sticker or image" reply_to = await reply_id(event) reply_message = await event.get_reply_message() if not event.reply_to_msg_id or not reply_message.media: return await edit_delete(event, "```Reply to a media to fry it...```", 10) output = await media_to_pic(event, reply_message) if output[1] is None: return await edit_delete( output[0], "__Unable to extract image from the replied message.__", 10) chat = "@image_deepfrybot" catevent = await edit_or_reply(event, "```Processing...```") async with event.client.conversation(chat) as conv: try: msg_flag = await conv.send_message("/start") except YouBlockedUserError: await edit_or_reply( catevent, "**Error:** Trying to unblock & retry, wait a sec...") await catub(unblock("image_deepfrybot")) msg_flag = await conv.send_message("/start") await conv.get_response() await event.client.send_read_acknowledge(conv.chat_id) await event.client.send_file(conv.chat_id, output[1]) response = await conv.get_response() await event.client.send_read_acknowledge(conv.chat_id) await catevent.delete() await event.client.send_file(event.chat_id, response, reply_to=reply_to) await delete_conv(event, chat, msg_flag) os.remove(output[1])
async def myfeds_fedinfo(event): "list all feds in which you are admin." catevent = await edit_or_reply(event, "`Fetching list of feds...`") replyid = await reply_id(event) async with event.client.conversation(rose) as conv: try: try: await conv.send_message("/myfeds") except YouBlockedUserError: await catub(unblock("MissRose_bot")) await conv.send_message("/myfeds") response = await conv.get_response() if "can only" in response.text: return await edit_delete(catevent, f"__{response.text}__") if "Looks like" in response.text: await response.click(0) response = await conv.get_response() await event.client.send_read_acknowledge(conv.chat_id) user = await event.client.get_me() await event.client.send_file( event.chat_id, response, caption= f"List of feds in which {_format.mentionuser('I am' ,user.id)} admin are.", reply_to=replyid, ) await catevent.delete() return await edit_or_reply(catevent, response.text) except Exception as e: await edit_delete(catevent, f"**Error while fecthing myfeds:**\n__{e}__", 10) await event.client.send_read_acknowledge(conv.chat_id) conv.cancel()
async def newpacksticker( catevent, conv, cmd, args, pack, packnick, is_video, emoji, packname, is_anim, stfile, otherpack=False, pkang=False, ): try: await conv.send_message(cmd) except YouBlockedUserError: await catub(unblock("stickers")) await conv.send_message(cmd) await conv.get_response() await args.client.send_read_acknowledge(conv.chat_id) await conv.send_message(packnick) await conv.get_response() await args.client.send_read_acknowledge(conv.chat_id) if is_video: await conv.send_file("animate.webm") elif is_anim: await conv.send_file("AnimatedSticker.tgs") os.remove("AnimatedSticker.tgs") else: stfile.seek(0) await conv.send_file(stfile, force_document=True) rsp = await conv.get_response() if not verify_cond(EMOJI_SEN, rsp.text): await catevent.edit( f"Failed to add sticker, use @Stickers bot to add the sticker manually.\n**error :**{rsp.text}" ) if not pkang: return None, None, None return None, None await conv.send_message(emoji) await args.client.send_read_acknowledge(conv.chat_id) await conv.get_response() await conv.send_message("/publish") if is_anim: await conv.get_response() await conv.send_message(f"<{packnick}>") await conv.get_response() await args.client.send_read_acknowledge(conv.chat_id) await conv.send_message("/skip") await args.client.send_read_acknowledge(conv.chat_id) await conv.get_response() await conv.send_message(packname) await args.client.send_read_acknowledge(conv.chat_id) await conv.get_response() await args.client.send_read_acknowledge(conv.chat_id) if not pkang: return otherpack, packname, emoji return pack, packname
async def fetch_fedinfo(event): "To fetch fed admins." input_str = (event.pattern_match.group(2).strip() if event.pattern_match.group(2) is not None else "") catevent = await edit_or_reply(event, "`Fetching admins list of given fed...`") async with event.client.conversation(rose) as conv: try: try: await conv.send_message(f"/fedadmins {input_str}") except YouBlockedUserError: await catub(unblock("MissRose_bot")) await conv.send_message(f"/fedadmins {input_str}") response = await conv.get_response() await edit_or_reply( catevent, f"**Fedid:** ```{input_str}```\n\n{response.text}" if input_str else response.text, ) except Exception as e: await edit_delete(catevent, f"**Error while fecthing fedinfo:**\n__{e}__", 10) await event.client.send_read_acknowledge(conv.chat_id) conv.cancel()
async def fstat_rose(event): "To get fedstat data from rose." catevent = await edit_or_reply(event, "`Fetching fedstat from given deatils...`") user, fedid = await get_user_from_event(event, catevent, secondgroup=True, noedits=True) if user is None: user = await event.client.get_me() if fedid is None: fedid = "" replyid = await reply_id(event) async with event.client.conversation(rose) as conv: try: try: await conv.send_message( f"/fedstat {str(user.id)} {fedid.strip()}") except YouBlockedUserError: await catub(unblock("MissRose_bot")) await conv.send_message( f"/fedstat {str(user.id)} {fedid.strip()}") response = await conv.get_response() await event.client.send_read_acknowledge(conv.chat_id) if "can only" in response.text: return await edit_delete(catevent, f"__{response.text}__") if fedid == "": response = await conv.get_edit() result = f"**List of feds** {_format.mentionuser(user.first_name ,user.id)} **has been banned in are.**\n\n" else: result = f"**Fban info about** {_format.mentionuser(user.first_name ,user.id)} **is**\n\n" if "Looks like" in response.message: await response.click(0) response = await conv.get_response() await event.client.send_read_acknowledge(conv.chat_id) await event.client.send_file( event.chat_id, response, caption= f"List of feds {_format.mentionuser(user.first_name ,user.id)} has been banned in are.", reply_to=replyid, ) await catevent.delete() return await edit_or_reply(catevent, result + response.text) except Exception as e: await edit_delete(catevent, f"**Error while fecthing fedstat:**\n__{e}__", 10) await event.client.send_read_acknowledge(conv.chat_id) conv.cancel()
async def delpack(catevent, conv, args, packname): try: await conv.send_message("/delpack") except YouBlockedUserError: await catub(unblock("stickers")) await conv.send_message("/delpack") await conv.get_response() await args.client.send_read_acknowledge(conv.chat_id) await conv.send_message(packname) await conv.get_response() await args.client.send_read_acknowledge(conv.chat_id) await conv.send_message("Yes, I am totally sure.") await conv.get_response() await args.client.send_read_acknowledge(conv.chat_id)
async def clippy(borg, msg, chat_id, reply_to_id): chat = "@clippy" async with borg.conversation(chat) as conv: try: msg = await conv.send_file(msg) except YouBlockedUserError: await catub(unblock("clippy")) msg = await conv.send_file(msg) pic = await conv.get_response() await borg.send_read_acknowledge(conv.chat_id) await borg.send_file( chat_id, pic, reply_to=reply_to_id, ) await borg.delete_messages(conv.chat_id, [msg.id, pic.id])
async def _(event): "To search songs" song = event.pattern_match.group(1) chat = "@songdl_bot" reply_id_ = await reply_id(event) catevent = await edit_or_reply(event, SONG_SEARCH_STRING, parse_mode="html") async with event.client.conversation(chat) as conv: try: purgeflag = await conv.send_message("/start") except YouBlockedUserError: await edit_or_reply( catevent, "**Error:** Trying to unblock & retry, wait a sec...") await catub(unblock("songdl_bot")) purgeflag = await conv.send_message("/start") await conv.get_response() await conv.send_message(song) hmm = await conv.get_response() while hmm.edit_hide is not True: await asyncio.sleep(0.1) hmm = await event.client.get_messages(chat, ids=hmm.id) baka = await event.client.get_messages(chat) if baka[0].message.startswith( ("I don't like to say this but I failed to find any such song.")): await delete_conv(event, chat, purgeflag) return await edit_delete(catevent, SONG_NOT_FOUND, parse_mode="html", time=5) await catevent.edit(SONG_SENDING_STRING, parse_mode="html") await baka[0].click(0) await conv.get_response() await conv.get_response() music = await conv.get_response() await event.client.send_read_acknowledge(conv.chat_id) await event.client.send_file( event.chat_id, music, caption=f"<b>Title :- <code>{song}</code></b>", parse_mode="html", reply_to=reply_id_, ) await catevent.delete() await delete_conv(event, chat, purgeflag)
async def scan(event): input_str = event.pattern_match.group(1) if not event.reply_to_msg_id: return await edit_or_reply(event, "```Reply to any user message.```") reply_message = await event.get_reply_message() if not reply_message.media: return await edit_or_reply(event, "```reply to a media message```") chat = "@VS_Robot" catevent = await edit_or_reply(event, " `Sliding my tip, of fingers over it`") async with event.client.conversation(chat) as conv: try: flag = await conv.send_message("/start") except YouBlockedUserError: await edit_or_reply( catevent, "**Error:** Trying to unblock & retry, wait a sec...") await catub(unblock("VS_Robot")) flag = await conv.send_message("/start") await conv.get_response() await conv.send_message(reply_message) response1 = await conv.get_response() if response1.text: await event.client.send_read_acknowledge(conv.chat_id) sec = "".join([num for num in response1.text if num.isdigit()]) await edit_delete(catevent, f"**Please wait for {sec}s before retry**", 15) else: await conv.get_response() await event.client.send_read_acknowledge(conv.chat_id) response2 = await conv.get_response() response3 = await conv.get_response() await event.client.send_read_acknowledge(conv.chat_id) if not input_str: await edit_or_reply(catevent, response3.text[30:]) else: await catevent.delete() await event.client.send_file(event.chat_id, response2.media, reply_to=(await reply_id(event))) await delete_conv(event, chat, flag)
async def ctg(event): "To get link preview" input_str = event.pattern_match.group(1) reply = await event.get_reply_message() reply_to_id = await reply_id(event) if not input_str and reply: input_str = reply.text if not input_str: return await edit_delete(event, "**ಠ∀ಠ Give me link to search..**", 20) urls = extractor.find_urls(input_str) if not urls: return await edit_delete(event, "**There no link to search in the text..**", 20) chat = "@chotamreaderbot" catevent = await edit_or_reply(event, "```Processing...```") async with event.client.conversation(chat) as conv: try: msg_flag = await conv.send_message(urls[0]) except YouBlockedUserError: await edit_or_reply( catevent, "**Error:** Trying to unblock & retry, wait a sec...") await catub(unblock("chotamreaderbot")) msg_flag = await conv.send_message(urls[0]) response = await conv.get_response() await event.client.send_read_acknowledge(conv.chat_id) if response.text.startswith(""): await edit_or_reply(catevent, "Am I Dumb Or Am I Dumb?") else: await catevent.delete() await event.client.send_message(event.chat_id, response, reply_to=reply_to_id, link_preview=True) await delete_conv(event, chat, msg_flag)
async def quote_search(event): # sourcery no-metrics "Add the federation to database." fedgroup = event.pattern_match.group(1) fedid = event.pattern_match.group(2) if get_collection("fedids") is not None: feds = get_collection("fedids").json else: feds = {} if fedgroup == "-all": catevent = await edit_or_reply( event, "`Adding all your feds to database...`") fedidstoadd = [] async with event.client.conversation("@MissRose_bot") as conv: try: try: await conv.send_message("/myfeds") except YouBlockedUserError: await catub(unblock("MissRose_bot")) await conv.send_message("/myfeds") await asyncio.sleep(2) try: response = await conv.get_response() except asyncio.exceptions.TimeoutError: return await edit_or_reply( catevent, "__Rose bot is not responding try again later.__", ) if "can only" in response.text: return await edit_delete(catevent, f"__{response.text}__") if "make a file" in response.text or "Looks like" in response.text: await response.click(0) await asyncio.sleep(2) response_result = await conv.get_response() await asyncio.sleep(2) if response_result.media: fed_file = await event.client.download_media( response_result, "fedlist", ) await asyncio.sleep(5) fedfile = open(fed_file, errors="ignore") lines = fedfile.readlines() for line in lines: try: fedidstoadd.append(line[:36]) except Exception: pass else: text_lines = response.text.split("`") fedidstoadd.extend( fed_id for fed_id in text_lines if len(fed_id) == 36 and fed_id.count("-") == 4) except Exception as e: await edit_delete( catevent, f"**Error while fecthing myfeds:**\n__{e}__", 10) await event.client.send_read_acknowledge(conv.chat_id) conv.cancel() if not fedidstoadd: return await edit_or_reply( catevent, "__I have failed to fetch your feds or you are not admin of any fed.__", ) feds[fedid] = fedidstoadd add_collection("fedids", feds) await edit_or_reply( catevent, f"__Successfully added all your feds to database group__ **{fedid}**.", ) if BOTLOG: await event.client.send_message( BOTLOG_CHATID, f"#ADDFEDID\ \n**Fed Group:** `{fedid}`\ \nSuccessfully added all your feds to above database category.", ) return if fedgroup in feds: fed_ids = feds[fedgroup] if fedid in fed_ids: return await edit_delete( event, "__This fed is already part of this fed category.__") fed_ids.append(fedid) feds[fedgroup] = fed_ids else: feds[fedgroup] = [fedid] add_collection("fedids", feds) await edit_or_reply( event, "__The given fed is succesfully added to fed category.__") if BOTLOG: await event.client.send_message( BOTLOG_CHATID, f"#ADDFEDID\ \n**Fedid:** `{fedid}`\ \n**Fed Group:** `{fedgroup}`\ \nThe above fedid is sucessfully added to that fed category.", )
async def pic2packcmd(event): "To split the replied image and make sticker pack." reply = await event.get_reply_message() mediatype = media_type(reply) if not reply or not mediatype or mediatype not in ["Photo", "Sticker"]: return await edit_delete( event, "__Reply to photo or sticker to make pack.__") if mediatype == "Sticker" and reply.document.mime_type == "application/x-tgsticker": return await edit_delete( event, "__Reply to photo or sticker to make pack. Animated sticker is not supported__", ) args = event.pattern_match.group(1) if not args: return await edit_delete( event, "__What's your packname ?. pass along with cmd.__") catevent = await edit_or_reply(event, "__🔪Cropping and adjusting the image...__") try: emoji = (re.findall(r"-e[\U00010000-\U0010ffff]+", args))[0] args = args.replace(emoji, "") emoji = emoji.replace("-e", "") except Exception: emoji = "▫️" chat = "@Stickers" name = "CatUserbot_" + "".join( random.choice(list(string.ascii_lowercase + string.ascii_uppercase)) for _ in range(16)) image = await _cattools.media_to_pic(catevent, reply, noedits=True) if image[1] is None: return await edit_delete( image[0], "__Unable to extract image from the replied message.__") image = Image.open(image[1]) w, h = image.size www = max(w, h) img = Image.new("RGBA", (www, www), (0, 0, 0, 0)) img.paste(image, ((www - w) // 2, 0)) newimg = img.resize((100, 100)) new_img = io.BytesIO() new_img.name = name + ".png" images = await crop_and_divide(img) newimg.save(new_img) new_img.seek(0) catevent = await event.edit("__Making the pack.__") async with event.client.conversation(chat) as conv: i = 0 try: await event.client.send_message(chat, "/cancel") except YouBlockedUserError: await catub(unblock("stickers")) await event.client.send_message(chat, "/cancel") await conv.wait_event(events.NewMessage(incoming=True, from_users=chat)) await event.client.send_message(chat, "/newpack") await conv.wait_event(events.NewMessage(incoming=True, from_users=chat)) await event.client.send_message(chat, args) await conv.wait_event(events.NewMessage(incoming=True, from_users=chat)) for im in images: img = io.BytesIO(im) img.name = name + ".png" img.seek(0) await event.client.send_file(chat, img, force_document=True) await conv.wait_event( events.NewMessage(incoming=True, from_users=chat)) await event.client.send_message(chat, emoji) await conv.wait_event( events.NewMessage(incoming=True, from_users=chat)) await event.client.send_read_acknowledge(conv.chat_id) await asyncio.sleep(1) i += 1 await catevent.edit( f"__Making the pack.\nProgress: {i}/{len(images)}__") await event.client.send_message(chat, "/publish") await conv.wait_event(events.NewMessage(incoming=True, from_users=chat)) await event.client.send_file(chat, new_img, force_document=True) await conv.wait_event(events.NewMessage(incoming=True, from_users=chat)) await event.client.send_message(chat, name) ending = await conv.wait_event( events.NewMessage(incoming=True, from_users=chat)) await event.client.send_read_acknowledge(conv.chat_id) for packname in ending.raw_text.split(): stick_pack_name = packname if stick_pack_name.startswith("https://t.me/"): break await catevent.edit( f"__successfully created the pack for the replied media : __[{args}]({stick_pack_name})" )
async def add_to_pack( catevent, conv, args, packname, pack, userid, username, is_video, is_anim, stfile, emoji, cmd, pkang=False, ): try: await conv.send_message("/addsticker") except YouBlockedUserError: await catub(unblock("stickers")) await conv.send_message("/addsticker") vtry = True if is_video else None await conv.get_response() await args.client.send_read_acknowledge(conv.chat_id) await conv.send_message(packname) x = await conv.get_response() while ("50" in x.message) or ("120" in x.message) or vtry: if vtry: await conv.send_file("animate.webm") x = await conv.get_response() if "50 video stickers" in x.message: await conv.send_message("/addsticker") else: vtry = None break try: val = int(pack) pack = val + 1 except ValueError: pack = 1 packname = pack_name(userid, pack, is_anim, is_video) packnick = pack_nick(username, pack, is_anim, is_video) await catevent.edit( f"`Switching to Pack {pack} due to insufficient space`") await conv.send_message(packname) x = await conv.get_response() if x.message == "Invalid set selected.": return await newpacksticker( catevent, conv, cmd, args, pack, packnick, is_video, emoji, packname, is_anim, stfile, otherpack=True, pkang=pkang, ) if is_video: os.remove("animate.webm") rsp = x elif is_anim: await conv.send_file("AnimatedSticker.tgs") os.remove("AnimatedSticker.tgs") rsp = await conv.get_response() else: stfile.seek(0) await conv.send_file(stfile, force_document=True) rsp = await conv.get_response() if not verify_cond(EMOJI_SEN, rsp.message): await catevent.edit( f"Failed to add sticker, use @Stickers bot to add the sticker manually.\n**error :**{rsp.message}" ) if not pkang: return None, None return None, None await conv.send_message(emoji) await args.client.send_read_acknowledge(conv.chat_id) await conv.get_response() await conv.send_message("/done") await conv.get_response() await args.client.send_read_acknowledge(conv.chat_id) if not pkang: return packname, emoji return pack, packname