async def send_saved_image(bot: UserBot, message: Message, name: str, image: str, caption=None): files = json.load(open("file_ids.txt", "r")) if name in files: old_message = await get_old_message(bot, int(files[name]), "photo") if old_message is not None: await bot.send_photo( GetChatID(message), old_message.file_id, file_ref=old_message.file_ref, reply_to_message_id=ReplyCheck(message), caption=caption if caption is not None else '') else: # Reset file id list because of the one error reset_file_ids() await send_saved_image(bot, message, name, image, caption) else: sent_photo = await bot.send_photo( "self", photo="userbot/images/{}".format(image), reply_to_message_id=ReplyCheck(message)) save_media_id(name, sent_photo) await send_saved_image(bot, message, name, image, caption)
async def send_saved_animation(message: Message, name: str, image: str, caption=None): files = json.load(open("file_ids.txt", "r")) if name in files: old_message = await get_old_message(int(files[name]), "animation") if old_message is not None: await UserBot.send_animation( message.chat.id, old_message.file_id, reply_to_message_id=ReplyCheck(message), caption=caption if caption is not None else "", ) else: # Reset file id list because of the one error reset_file_ids() await send_saved_animation(message, name, image, caption) else: sent_animation = await UserBot.send_animation( "self", "userbot/images/{}".format(image), reply_to_message_id=ReplyCheck(message), ) save_media_id(name, sent_animation) await send_saved_animation(message, name, image, caption)
async def anime_boy(bot: UserBot, message: Message): try: cmd = message.command anime_boy_text = "" if len(cmd) > 1: anime_boy_text = " ".join(cmd[1:]) elif message.reply_to_message and len(cmd) == 1: anime_boy_text = message.reply_to_message.text elif not message.reply_to_message and len(cmd) == 1: await message.edit("`Senpai I need something to say :(`") await asyncio.sleep(2) await message.delete() return stickers = [37, 38, 48, 55] sticker = f"#{int(choice(stickers))}" anime_girl_results = await bot.get_inline_bot_results( "stickerizerbot", sticker + anime_boy_text) try: await bot.send_inline_bot_result( chat_id=message.chat.id, query_id=anime_girl_results.query_id, result_id=anime_girl_results.results[0].id, reply_to_message_id=ReplyCheck(message), hide_via=True) except TimeoutError: await message.edit("@StickerizerBot didn't respond in time.") await asyncio.sleep(2) await message.delete() except: await message.edit("`Failed to reach Stickerizerbot`") await asyncio.sleep(2) await message.delete()
async def who_is(bot: UserBot, message: Message): cmd = message.command if not message.reply_to_message and len(cmd) == 1: get_user = message.from_user.id elif message.reply_to_message and len(cmd) == 1: get_user = message.reply_to_message.from_user.id elif len(cmd) > 1: get_user = cmd[1] try: get_user = int(cmd[1]) except ValueError: pass try: user = await bot.get_users(get_user) except PeerIdInvalid: await message.edit("I don't know that User.") await asyncio.sleep(2) await message.delete() return user_details = await bot.get_chat(get_user) bio = user_details.bio user_pic = await bot.get_profile_photos(user.id) pic_count = await bot.get_profile_photos_count(user.id) common = await GetCommon(bot, user.id) if not user.photo: await message.edit( WHOIS.format( full_name=FullName(user), user_id=user.id, first_name=user.first_name, last_name=user.last_name if user.last_name else "", username=user.username if user.username else "", last_online=LastOnline(user), common_groups=len(common.chats), bio=bio if bio else "`No bio set up.`", ), disable_web_page_preview=True, ) elif user.photo: await bot.send_photo( message.chat.id, user_pic[0].file_id, caption=WHOIS_PIC.format( full_name=FullName(user), user_id=user.id, first_name=user.first_name, last_name=user.last_name if user.last_name else "", username=user.username if user.username else "", last_online=LastOnline(user), profile_pics=pic_count, common_groups=len(common.chats), bio=bio if bio else "`No bio set up.`", profile_pic_update=ProfilePicUpdate(user_pic), ), reply_to_message_id=ReplyCheck(message), ) await message.delete()
async def animu_gifs(_, message: Message): cmd = message.command if not (len(cmd) >= 2): await message.edit("```Not enough params provided```") await asyncio.sleep(3) await message.delete() return if cmd[1].lower() in gif_categories: category = cmd[1].lower() animu_link = f"https://some-random-api.ml/animu/{category}" try: data = await AioHttp().get_json(animu_link) gif = data["link"] except Exception: await message.edit(f"```Couldn't get a {category}```") await asyncio.sleep(3) await message.delete() else: await message.delete() await UserBot.send_animation( chat_id=message.chat.id, animation=gif, reply_to_message_id=ReplyCheck(message)) else: await message.edit("`Unsupported category...`") await asyncio.sleep(2) await message.delete()
async def spacex(_, message: Message): await message.delete() data = await get_latest() dt = datetime.utcfromtimestamp(int( data['launch_date_unix'])).strftime('%d-%m-%Y %H:%M:%S') images = data['links']['flickr_images'] txt = f"<b>Mission Name:</b> {data['mission_name']}\n" \ f"<b>Flight No:</b> {data['flight_number']}\n" \ f"<b>Rocket Name:</b> {data['rocket']['rocket_name']}\n" \ f"<b>Launch Site:</b> {data['launch_site']['site_name']}\n" \ f"<b>Launch Date:</b> {dt}\n\n" \ f"<b>Links:</b>\n" \ f"<a href='{data['links']['reddit_campaign']}'>Reddit</a>, " \ f"<a href='{data['links']['video_link']}'>YouTube</a>" if images: for i, image in enumerate(images, start=1): txt += f", <a href='{image}'>Flicker {i}</a>" txt += f"\n\n{data['details']}" if images: await UserBot.send_photo(chat_id=message.chat.id, photo=images[0], caption=txt, reply_to_message_id=ReplyCheck(message)) else: await UserBot.send_message(chat_id=message.chat.id, text=txt, disable_web_page_preview=True)
async def cat(bot: UserBot, message: Message): if message.from_user.is_self: await message.delete() await bot.send_photo(chat_id=message.chat.id, photo=_prep_cat(), reply_to_message_id=ReplyCheck(message))
async def execution(_, message: Message): cmd = message.text.split(" ", maxsplit=1)[1] reply_to_id = message.message_id if message.reply_to_message: reply_to_id = message.reply_to_message.message_id process = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE) stdout, stderr = await process.communicate() e = stderr.decode() if not e: e = "No errors" o = stdout.decode() if not o: o = "No output" OUTPUT = "" OUTPUT += f"<b>Command:</b>\n<code>{cmd}</code>\n\n" OUTPUT += f"<b>Output</b>: \n<code>{o}</code>\n" OUTPUT += f"<b>Errors</b>: \n<code>{e}</code>" if len(OUTPUT) > 4096: with open("exec.text", "w+", encoding="utf8") as out_file: out_file.write(str(OUTPUT)) await message.reply_document( document="exec.text", caption=cmd, disable_notification=True, reply_to_message_id=ReplyCheck(message), ) os.remove("exec.text") else: await message.reply_text(OUTPUT)
async def reverse(bot: UserBot, message: Message): await message.delete() await bot.send_message( chat_id=message.chat.id, text=MEMES.REVERSE, reply_to_message_id=ReplyCheck(message) )
async def mock_people(bot: UserBot, message: Message): try: cmd = message.command mock_text = "" if len(cmd) > 1: mock_text = " ".join(cmd[1:]) elif message.reply_to_message and len(cmd) == 1: mock_text = message.reply_to_message.text elif not message.reply_to_message and len(cmd) == 1: await message.edit("gIvE sOMEtHInG tO MoCk") await asyncio.sleep(2) await message.delete() return mock_results = await bot.get_inline_bot_results( "stickerizerbot", "#7" + mock_text) try: await bot.send_inline_bot_result( chat_id=message.chat.id, query_id=mock_results.query_id, result_id=mock_results.results[0].id, reply_to_message_id=ReplyCheck(message), hide_via=True) except TimeoutError: await message.edit("@StickerizerBot didn't respond in time.") await asyncio.sleep(2) await message.delete() except: await message.edit("`Failed to reach Stickerizerbot`") await asyncio.sleep(2) await message.delete()
async def download_tiktok(bot: UserBot, message: Message): if len(message.command) == 2: txt = message.command[1] elif message.reply_to_message: txt = message.reply_to_message.text or message.reply_to_message.caption elif len(message.command) > 1: txt = " ".join(message.command[1:]) else: await message.edit("TikTok link not found") await asyncio.sleep(3) await message.delete() return try: await message.edit("Processing link...") tiktok_video = await TikTok.download_tiktok(txt) await bot.send_video(message.chat.id, tiktok_video, caption=txt, reply_to_message_id=ReplyCheck(message), supports_streaming=True) await message.delete() os.remove(tiktok_video) return except Exception as e: print(e) await message.edit("Error while processing tiktok link") await asyncio.sleep(3) await message.delete() return
async def nice(bot: UserBot, message: Message): await message.delete() await bot.send_message( chat_id=message.chat.id, text="NICENICENICENICE", reply_to_message_id=ReplyCheck(message) )
async def google_sticker(bot: UserBot, message: Message): try: cmd = message.command ggl_text = "" if len(cmd) > 1: ggl_text = " ".join(cmd[1:]) elif message.reply_to_message and len(cmd) == 1: ggl_text = message.reply_to_message.text elif not message.reply_to_message and len(cmd) == 1: await message.edit("I need something to google") await asyncio.sleep(2) await message.delete() return ggl_result = await bot.get_inline_bot_results("stickerizerbot", "#12" + ggl_text) try: await bot.send_inline_bot_result( chat_id=message.chat.id, query_id=ggl_result.query_id, result_id=ggl_result.results[0].id, reply_to_message_id=ReplyCheck(message), hide_via=True) except TimeoutError: await message.edit("@StickerizerBot didn't respond in time.") await asyncio.sleep(2) await message.delete() except: await message.edit("`Failed to reach Stickerizerbot`") await asyncio.sleep(2) await message.delete()
async def anime_girl(bot: UserBot, message: Message): cmd = message.command anime_girl_text = '' if len(cmd) > 1: anime_girl_text = " ".join(cmd[1:]) elif message.reply_to_message and len(cmd) is 1: anime_girl_text = message.reply_to_message.text elif not message.reply_to_message and len(cmd) is 1: await message.edit("`Senpai I need something to say :(`") sleep(2) await message.delete() return anime_girl_results = await bot.get_inline_bot_results( "stickerizerbot", "#32" + anime_girl_text) try: await bot.send_inline_bot_result( chat_id=message.chat.id, query_id=anime_girl_results.query_id, result_id=anime_girl_results.results[0].id, reply_to_message_id=ReplyCheck(message), hide_via=True) except TimeoutError: await message.edit("@StickerizerBot didn't respond in time.") sleep(2) await message.delete()
async def this_cat_does_no_exist(_, message: Message): cat = get_cat() file_name = f"{randint(1, 999)}cat.jpeg" cat.save_image(file_name) await UserBot.send_photo(message.chat.id, file_name, reply_to_message_id=ReplyCheck(message)) os.remove(file_name) await message.delete()
async def collect_afk_messages(bot: UserBot, message: Message): if AFK: last_seen = subtract_time(datetime.now(), AFK_TIME) is_group = True if message.chat.type in ["supergroup", "group" ] else False CHAT_TYPE = GROUPS if is_group else USERS if GetChatID(message) not in CHAT_TYPE: text = (f"`Beep boop. This is an automated message.\n" f"I am not available right now.\n" f"Last seen: {last_seen}\n" f"Reason: ```{AFK_REASON.upper()}```\n" f"See you after I'm done doing whatever I'm doing.`") await bot.send_message( chat_id=GetChatID(message), text=text, reply_to_message_id=ReplyCheck(message), ) CHAT_TYPE[GetChatID(message)] = 1 return elif GetChatID(message) in CHAT_TYPE: if CHAT_TYPE[GetChatID(message)] == 50: text = ( f"`This is an automated message\n" f"Last seen: {last_seen}\n" f"This is the 10th time I've told you I'm AFK right now..\n" f"I'll get to you when I get to you.\n" f"No more auto messages for you`") await bot.send_message( chat_id=GetChatID(message), text=text, reply_to_message_id=ReplyCheck(message), ) elif CHAT_TYPE[GetChatID(message)] > 50: return elif CHAT_TYPE[GetChatID(message)] % 5 == 0: text = (f"`Hey I'm still not back yet.\n" f"Last seen: {last_seen}\n" f"Still busy: ```{AFK_REASON.upper()}```\n" f"Try pinging a bit later.`") await bot.send_message( chat_id=GetChatID(message), text=text, reply_to_message_id=ReplyCheck(message), ) CHAT_TYPE[GetChatID(message)] += 1
async def send_saved_image(bot: UserBot, message: Message, name: str, image: str): thing = json.load(open("file_ids.txt", "r")) if name in thing: old_message = await get_old_message(bot, int(thing[name]), "photo") await bot.send_photo(GetChatID(message), old_message.file_id, file_ref=old_message.file_ref, reply_to_message_id=ReplyCheck(message)) else: sent_photo = await bot.send_photo( "self", "userbot/images/{}".format(image), reply_to_message_id=ReplyCheck(message)) save_media_id(name, sent_photo) await send_saved_image(bot, message, name, image)
async def animal_image(bot: UserBot, message: Message): animal_data = animals_data[message.command[0]] await message.delete() await bot.send_photo( chat_id=message.chat.id, photo=await prep_animal_image(animal_data), reply_to_message_id=ReplyCheck(message) )
async def sticker_super_func(bot: UserBot, message: Message): try: sticker = {} command = message.command[0] if command not in sticker_data: for sticker in sticker_data: if 'alts' in sticker_data[sticker] and command in sticker_data[sticker]['alts']: sticker = sticker_data[sticker] break else: sticker = sticker_data[message.command[0]] cmd = message.command sticker_text = "" if len(cmd) > 1: sticker_text = " ".join(cmd[1:]) elif message.reply_to_message and len(cmd) == 1: sticker_text = message.reply_to_message.text elif not message.reply_to_message and len(cmd) == 1: await message.edit(sticker['empty_message']) await asyncio.sleep(2) await message.delete() return await message.edit(f"`Generating {sticker['action']}`") values = sticker['value'] choice = None if isinstance(values, list): choice = int(random.choice(values)) elif isinstance(values, int): choice = values if choice: sticker_results = await bot.get_inline_bot_results( "stickerizerbot", f"#{choice}" + sticker_text ) else: sticker_results = await bot.get_inline_bot_results( "stickerizerbot", sticker_text ) try: await bot.send_inline_bot_result( chat_id=message.chat.id, query_id=sticker_results.query_id, result_id=sticker_results.results[0].id, reply_to_message_id=ReplyCheck(message), hide_via=True) except TimeoutError: await message.edit("`@StickerizerBot didn't respond in time...`") await asyncio.sleep(2) except Exception: await message.edit("`Failed to reach @Stickerizerbot...`") await asyncio.sleep(2) await message.delete()
async def this_person_does_no_exist(bot: UserBot, message: Message): person = get_person() file_name = f"{randint(1, 999)}person.jpeg" person.save_image(file_name) await bot.send_photo(message.chat.id, file_name, reply_to_message_id=ReplyCheck(message)) os.remove(file_name) await message.delete()
async def subreddit_link(bot: UserBot, message: Message): html = "<a href='{link}'>{string}</a>" await message.delete() await bot.send_message(GetChatID(message), html.format(link="https://reddit.com/" + message.text, string=message.text), disable_web_page_preview=True, reply_to_message_id=ReplyCheck(message))
async def send_saved_animation(bot: UserBot, message: Message, name: str, image: str): id_list = json.load(open("file_ids.txt", "r")) if name in id_list: old_message = await get_old_message(bot, int(id_list[name]), "animation") await bot.send_animation(GetChatID(message), old_message.file_id, file_ref=old_message.file_ref, reply_to_message_id=ReplyCheck(message)) else: sent_animation = await bot.send_animation( "self", "userbot/images/{}".format(image), reply_to_message_id=ReplyCheck(message)) save_media_id(name, sent_animation) await send_saved_animation(bot, message, name, image)
async def animal_image(_, message: Message): if len(message.command) > 1: return animal_data = animals_data[message.command[0]] await message.delete() await UserBot.send_photo(chat_id=message.chat.id, photo=await prep_animal_image(animal_data), reply_to_message_id=ReplyCheck(message))
async def give_pats(_, message: Message): URL = "https://some-random-api.ml/animu/pat" async with aiohttp.ClientSession() as session: async with session.get(URL) as request: if request.status == 404: return await message.edit("`no Pats for u :c") result = await request.json() url = result.get("link", None) await asyncio.gather( message.delete(), UserBot.send_video(GetChatID(message), url, reply_to_message_id=ReplyCheck(message)) )
async def send_music(_, message: Message): try: cmd = message.command song_name = "" if len(cmd) > 1: song_name = " ".join(cmd[1:]) elif message.reply_to_message and len(cmd) == 1: song_name = ( message.reply_to_message.text or message.reply_to_message.caption ) elif not message.reply_to_message and len(cmd) == 1: await message.edit("Give a song name") await asyncio.sleep(2) await message.delete() return song_results = await UserBot.get_inline_bot_results("deezermusicbot", song_name) try: # send to Saved Messages because hide_via doesn't work sometimes saved = await UserBot.send_inline_bot_result( chat_id="me", query_id=song_results.query_id, result_id=song_results.results[0].id, hide_via=True, ) # forward as a new message from Saved Messages saved = await UserBot.get_messages("me", int(saved.updates[1].message.id)) reply_to = ( message.reply_to_message.message_id if message.reply_to_message else None ) await UserBot.send_audio( chat_id=message.chat.id, audio=str(saved.audio.file_id), reply_to_message_id=ReplyCheck(message), ) # delete the message from Saved Messages await UserBot.delete_messages("me", saved.message_id) except TimeoutError: await message.edit("That didn't work out") await asyncio.sleep(2) await message.delete() except Exception as e: print(e) await message.edit("`Failed to find song`") await asyncio.sleep(2) await message.delete()
async def evaluation_func(bot: UserBot, message: Message): status_message = await message.reply_text("Processing ...") cmd = message.text.split(" ", maxsplit=1)[1] reply_to_id = message.message_id if message.reply_to_message: reply_to_id = message.reply_to_message.message_id old_stderr = sys.stderr old_stdout = sys.stdout redirected_output = sys.stdout = io.StringIO() redirected_error = sys.stderr = io.StringIO() stdout, stderr, exc = None, None, None try: reply = message.reply_to_message or None await aexec(cmd, bot, message, reply, database) except Exception: exc = traceback.format_exc() stdout = redirected_output.getvalue() stderr = redirected_error.getvalue() sys.stdout = old_stdout sys.stderr = old_stderr if exc: evaluation = exc elif stderr: evaluation = stderr elif stdout: evaluation = stdout else: evaluation = "Success" final_output = "<b>Expression</b>:\n<code>{}</code>\n\n<b>Result</b>:\n<code>{}</code> \n".format( cmd, evaluation.strip() ) if len(final_output) > 4096: with open("eval.txt", "w", encoding="utf8") as out_file: out_file.write(str(final_output)) await message.reply_document( "eval.txt", caption=cmd, disable_notification=True, reply_to_message_id=ReplyCheck(message), ) os.remove("eval.txt") await status_message.delete() else: await status_message.edit(final_output)
async def animal_image(bot: UserBot, message: Message): cmd = message.command if len(message.command) > 1: return if cmd[0].lower() in animals_without_facts: await message.delete() await bot.send_photo( chat_id=message.chat.id, photo=await prep_animal_image(cmd[0].lower()), reply_to_message_id=ReplyCheck(message), )
async def spam(bot: UserBot, message: Message): # Get current chat and spam to there. # if in group and replied to user, then spam replying to user. await message.delete() times = message.command[1] to_spam = ' '.join(message.command[2:]) if message.chat.type in ['supergroup', 'group']: for _ in range(int(times)): await bot.send_message(message.chat.id, to_spam, reply_to_message_id=ReplyCheck(message)) await asyncio.sleep(0.20) if message.chat.type == "private": for _ in range(int(times)): await bot.send_message(message.chat.id, to_spam) await asyncio.sleep(0.20)
async def skyrim(_, message: Message): if len(message.command) >= 2: text = message.command[1] else: await message.edit("```Not enough params```") await asyncio.sleep(3) await message.delete() return level = message.command[2] if len(message.command) >= 3 else 100 try: try: if os.name == "nt": os.system( f'venv\\Scripts\\activate && python userbot\\helpers\\skyrim.py "{text}" {level}' ) else: os.system( f'. venv/bin/activate && python userbot//helpers//skyrim.py "{text}" {level}' ) except Exception: await message.edit("```Failed to generate skill```") time.sleep(2) await message.delete() try: await UserBot.send_photo( message.chat.id, "userbot/downloads/skyrim.png", reply_to_message_id=ReplyCheck(message), ) await message.delete() except Exception: await message.edit("```Failed to send skill```") time.sleep(2) await message.delete() finally: os.remove("userbot/downloads/skyrim.png") except Exception as e: print(e)
async def commit_graph(_, message: Message): if len(message.command) < 2: await message.edit( "Please provide a github profile username to generate the graph!" ) await sleep(2) await message.delete() return else: git_user = message.command[1] url = f"https://ghchart.rshah.org/{git_user}" file_name = f"{randint(1, 999)}{git_user}" resp = await AioHttp.get_raw(url) f = await aiofiles.open(f"{file_name}.svg", mode="wb") await f.write(resp) await f.close() try: drawing = svg2rlg(f"{file_name}.svg") renderPM.drawToFile(drawing, f"{file_name}.png") except UnboundLocalError: await message.edit("Username does not exist!") await sleep(2) await message.delete() return await asyncio.gather( UserBot.send_photo( chat_id=message.chat.id, photo=f"{file_name}.png", caption=git_user, reply_to_message_id=ReplyCheck(message), ), message.delete(), ) for file in iglob(f"{file_name}.*"): os.remove(file)