async def compress_(message: Message): """document to compressed media and vice versa""" reply_ = message.reply_to_message if not reply_: return await message.edit("`Reply to media...`", del_in=5) down_ = await userge.download_media(reply_) if "-d" in message.flags: await message.reply("`Processing document...`") await userge.send_document( message.chat.id, down_, force_document=True, reply_to_message_id=reply_.message_id, ) await message.delete() os.remove(down_) return await message.reply("`Compressing...`") if msg_type(reply_) == "photo": await userge.send_photo(message.chat.id, down_, reply_to_message_id=reply_.message_id) elif msg_type(reply_) == "video": await userge.send_video(message.chat.id, down_, reply_to_message_id=reply_.message_id) else: await reply_.reply("The replied document is not compressible...", del_in=5) await message.delete() os.remove(down_)
async def last_logged(message: Message): """get last traceback from main account""" limit_ = message.input_str if not limit_: limit_ = 5 elif not limit_.isdigit(): return await message.edit("`Provide a number as limit.`", del_in=5) if limit_ > 10: return await message.edit("`Can't search more than 10 messages.`", del_in=5) await message.edit("`Looking for last traceback...`") num = 0 me_ = (await userge.get_me()).first_name async for msg_ in userge.search_messages(Config.LOG_CHANNEL_ID): if msg_type(msg_) == "text": num += 1 if "-e" in message.flags: search_ = "#EXECUTOR" found_ = "eval traceback" else: search_ = "#TRACEBACK" found_ = "traceback" if search_ in msg_.text: text_ = msg_.text.html text_ = text_.replace("\n", "<br>") link_ = pt(f"{found_.capitalize()} from log channel of {me_}.", text_) return await message.edit( f"Last <b>{found_}</b> is [<b>HERE</b>]({link_}).", disable_web_page_preview=True, ) if num == limit_: return await message.edit( f"`Couldn't find {found_} in last {limit_} messages.`", del_in=5)
async def copy_message(message: Message): """copy message to database""" reply_ = message.reply_to_message if not reply_: return await message.edit( "`Reply to a message to put it in copied list...`", del_in=5 ) await message.edit("`Copying...`") log_ = Config.LOG_CHANNEL_ID info_ = await CHANNEL.log("### <b>COPIED MESSAGE BELOW</b> ###") fwd_ = await reply_.forward(log_) link_ = fwd_.link type_ = msg_type(reply_) await COPIED.insert_one({"msg_id": fwd_.message_id, "type": type_, "link": link_}) await message.edit("`Copied the replied message...`", del_in=5)
async def bl_action(_, message: Message): try: found = await BLOCKED.find_one({"chat_id": message.chat.id}) if not found: return if not found["block_tog"]: return if found["blocked"][msg_type(message)]: user_ = message.from_user.id full_name(await userge.get_users(user_)) chat_id = message.chat.id await message.delete() msg = await take_action(chat_id, user_) if found["block_mode"] == "None": return await userge.bot.send_message(message.chat.id, msg) except FloodWait as e: await asyncio.sleep(e.x + 3)
async def set_alive_media(message: Message): """set alive media""" found = await SAVED_SETTINGS.find_one({"_id": "ALIVE_MEDIA"}) if "-c" in message.flags: if found: media_ = found["url"] else: media_ = "https://telegra.ph/file/1fb4c193b5ac0c593f528.jpg" return await message.edit( f"The alive media is set to [<b>THIS</b>]({media_}).") elif "-r" in message.flags: if not found: return await message.edit("`No alive media is set.`", del_in=5) await SAVED_SETTINGS.delete_one({"_id": "ALIVE_MEDIA"}) return await message.edit("`Alive media reset to default.`", del_in=5) reply_ = message.reply_to_message if not reply_: return await message.edit("`Reply to media to set it as alive media.`", del_in=5) type_ = msg_type(reply_) if type_ not in ["gif", "photo"]: return await message.edit("`Reply to media only.`", del_in=5) link_ = await upload_media_(message) whole_link = f"https://telegra.ph{link_}" await SAVED_SETTINGS.update_one({"_id": "ALIVE_MEDIA"}, {"$set": { "url": whole_link }}, upsert=True) await SAVED_SETTINGS.update_one({"_id": "ALIVE_MEDIA"}, {"$set": { "type": type_ }}, upsert=True) link_log = (await reply_.forward(Config.LOG_CHANNEL_ID)).link await message.edit( f"`Alive media set.` [<b>Preview</b>]({link_log})\n`Bot soft restarting, please wait...`", disable_web_page_preview=True, ) asyncio.get_event_loop().create_task(userge.restart())