async def afk_group(bot: UserBot, message: Message): if AFK: if GetChatID(message) not in GROUPS: text = (f"```Beep boop. This is an automated message.```\n" f"I am not available right now.\n" f"Here's why: ```{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=message.message_id) GROUPS[GetChatID(message)] = 1 return elif GetChatID(message) in GROUPS: if GROUPS[GetChatID(message)] == 50: text = ( f"```This is an automated message```\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=message.message_id) elif GROUPS[GetChatID(message)] > 50: return elif GROUPS[GetChatID(message)] % 5 == 0: text = (f"Hey I'm still not back yet.\n" f"Still busy with ```{AFK_REASON.upper()}```\n" f"Try pinging a bit later.") await bot.send_message(chat_id=GetChatID(message), text=text, reply_to_message_id=message.message_id) GROUPS[GetChatID(message)] += 1
async def collect_afk_messages(_, 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"Here's why: ```{AFK_REASON.upper()}```\n" f"See you after I'm done doing whatever I'm doing.`" ) await UserBot.send_message( chat_id=GetChatID(message), text=text, reply_to_message_id=message.message_id, ) 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 UserBot.send_message( chat_id=GetChatID(message), text=text, reply_to_message_id=message.message_id, ) 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 with ```{AFK_REASON.upper()}```\n" f"Try pinging a bit later.`" ) await UserBot.send_message( chat_id=GetChatID(message), text=text, reply_to_message_id=message.message_id, ) CHAT_TYPE[GetChatID(message)] += 1
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 list_dir(client, message): cmd = message.command if len(cmd) > 1: try: directory_param = cmd[1] directory = UserBot.main_directory + "/userbot" + "/" + directory_param # + f"/{directory}" files = os.listdir(directory) view = "**__List items in " + directory_param + "__** : \n" for f in files: if os.path.isdir(directory + "/" + f): view += "\n📂 " + f else: view += "\n📄 " + f await client.delete_messages(GetChatID(message), message.message_id) d = await client.send_message(chat_id=message.chat["id"], text=view) except Exception as error: await client.send_message(chat_id=message.chat["id"], reply_to_message_id=int( message.message_id), text=str(error)) else: try: # extention = message.reply_to_message # print(message.reply_to_message) d = await client.send_message(chat_id=message.chat["id"], reply_to_message_id=int( message.message_id), text="invalid directory") except Exception as error: await client.send_message(chat_id=message.chat["id"], reply_to_message_id=int( message.message_id), text=str(error))
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 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 download(client, message): cmd = message.command if len(cmd) > 1: try: file_param = cmd[1] file_to_del = UserBot.main_directory + "/userbot" + "/" + file_param # + f"/{directory}" try: status = os.system("rm -rf \"" + file_to_del + "\"") d = await client.send_message(chat_id=message.chat["id"], text="deleted\n") await client.delete_messages(GetChatID(message), message.message_id) time.sleep(3) await client.delete_messages(GetChatID(d), d.message_id) except Exception as error: d = await client.send_message(chat_id=message.chat["id"], reply_to_message_id=int( message.message_id), text=str(error)) except Exception as error: await client.send_message(chat_id=message.chat["id"], reply_to_message_id=int( message.message_id), text=str(error)) else: try: d = await client.send_message(chat_id=message.chat["id"], reply_to_message_id=int( message.message_id), text="invalid directory") except Exception as error: await client.send_message(chat_id=message.chat["id"], reply_to_message_id=int( message.message_id), text=str(error))
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 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 send_files(client, message): cmd = message.command async def progress(current, total): await message.edit(f"uploaded {current * 100 / total:.1f}%") if len(cmd) > 1: try: file_param = cmd[1] if cmd[2]: caption_text = cmd[2] else: caption_text = None file_to_upload = str( UserBot.WORKDIR ) + "/userbot" + "/" + file_param # + f"/{directory}" try: filetype = magic.from_file(file_to_upload) if "document" in filetype: await UserBot.send_document(GetChatID(message), file_to_upload, progress=progress, caption=caption_text) elif "script" in filetype: await UserBot.send_document(GetChatID(message), file_to_upload, progress=progress, caption=caption_text) elif "GIF" in filetype: await UserBot.send_animation(GetChatID(message), file_to_upload, progress=progress, caption=caption_text) elif "image" in filetype: await UserBot.send_photo(GetChatID(message), file_to_upload, progress=progress, caption=caption_text) elif "Media" in filetype: await UserBot.send_video(GetChatID(message), file_to_upload, progress=progress, caption=caption_text) elif "Audio" in filetype: await UserBot.send_audio(GetChatID(message), file_to_upload, progress=progress, caption=caption_text) await client.delete_messages(GetChatID(message), message.message_id) time.sleep(3) except Exception as error: d = await client.send_message(chat_id=message.chat["id"], reply_to_message_id=int( message.message_id), text=str(error)) except Exception as error: await client.send_message(chat_id=message.chat["id"], reply_to_message_id=int( message.message_id), text=str(error)) else: try: d = await client.send_message(chat_id=message.chat["id"], reply_to_message_id=int( message.message_id), text="invalid directory") except Exception as error: await client.send_message(chat_id=message.chat["id"], reply_to_message_id=int( message.message_id), text=str(error))