async def pm_logger(_, message: Message): u_id = message.from_user.id u_name = message.from_user.first_name found = await NO_PM_LOG.find_one({"user_id": u_id}) if found: return pm_logger_msg = "<b><i>ID</i></b> : <code>{}</code>\nΓ°ΕΈβΒ€ {} sent" new_pm_logger = pm_logger_msg + " a new message." if len(PM_LOGGER_CACHE) == 0: # First Pm logger_msg_count = await userge.send_message( Config.PM_LOG_GROUP_ID, new_pm_logger.format(u_id, mention_html(u_id, u_name)), disable_notification=True, ) PM_LOGGER_CACHE[u_id] = { "name": u_name, "msg_count": 1, "logger_msg_id": logger_msg_count.message_id, } # either it can be the same user or a new user elif len(PM_LOGGER_CACHE) == 1: if u_id in PM_LOGGER_CACHE: # if same person just updating the count PM_LOGGER_CACHE[u_id]["msg_count"] += 1 else: u_info_id = list(PM_LOGGER_CACHE)[0] u_mention = mention_html(u_info_id, PM_LOGGER_CACHE[u_info_id]["name"]) edit_pm_logger = pm_logger_msg + " <code>{}</code> messages." try: await userge.edit_message_text( Config.PM_LOG_GROUP_ID, PM_LOGGER_CACHE[u_info_id]["logger_msg_id"], edit_pm_logger.format( u_info_id, u_mention, PM_LOGGER_CACHE[u_info_id]["msg_count"] ), ) except FloodWait as e: await asyncio.sleep(e.x) PM_LOGGER_CACHE.clear() try: logger_msg_count = await userge.send_message( Config.PM_LOG_GROUP_ID, new_pm_logger.format(u_id, mention_html(u_id, u_name)), disable_notification=True, ) except FloodWait as e: await asyncio.sleep(e.x) PM_LOGGER_CACHE[u_id] = { "name": u_name, "msg_count": 1, "logger_msg_id": logger_msg_count.message_id, } else: # Just in Case PM_LOGGER_CACHE.clear() try: await message.forward(Config.PM_LOG_GROUP_ID, disable_notification=True) except FloodWait as e: await asyncio.sleep(e.x) except MessageIdInvalid: pass
async def media_h(message: Message): reply = message.reply_to_message if not reply: return await message.err("reply to a User") start = time.time() await message.edit( 'This process takes soo much F*ing Time π so here\'s a quote πββοΈ\n\n`"All you gotta do is chill out... Let go of control and chill out... Let it be, Trust."`\n- **Esther Hicks**' ) x = PrettyTable() media_dict = {} # Generate json for m in TYPES: media_dict[m] = {} media_dict[m]["file_size"] = 0 media_dict[m]["count"] = 0 media_dict[m]["max_size"] = 0 media_dict[m]["max_file_link"] = "" # Count msg_count = 0 x.title = "File Summary:" x.field_names = ["Media", "Count", "File size"] largest = " <b>Largest Size</b>\n" u_mention = mention_html(reply.from_user.id, reply.from_user.first_name) async for msg in userge.search_messages( message.chat.id, "", from_user=reply.from_user.id ): msg_count += 1 for media in TYPES: if msg[media]: media_dict[media]["file_size"] += msg[media].file_size media_dict[media]["count"] += 1 if msg[media].file_size > media_dict[media]["max_size"]: media_dict[media]["max_size"] = msg[media].file_size media_dict[media]["max_file_link"] = msg.link for mediax in TYPES: x.add_row( [ mediax, media_dict[mediax]["count"], humanbytes(media_dict[mediax]["file_size"]), ] ) if media_dict[mediax]["count"] != 0: largest += f"β’ [{mediax}]({media_dict[mediax]['max_file_link']}) : <code>{humanbytes(media_dict[mediax]['max_size'])}</code>\n" result = f"<b>{message.chat.title}</b>\n" result += f"π€ <b>User</b> : {u_mention}\n" result += f"<code>Total Messages: {msg_count}</code>\n" result += f"```{str(x)}```\n" result += f"{largest}\n" end = time.time() result += f"β³ <code>Process took: {time_formatter(end - start)}</code>." await message.edit(result, disable_web_page_preview=True)
async def nobtnspoiler_(_, c_q: CallbackQuery): u_id = c_q.from_user.id u_name = c_q.from_user.first_name if u_id not in Config.OWNER_ID and u_id not in Config.SUDO_USERS: return await c_q.answer( "Given That It's A Stupid-Ass Decision, I've Elected To Ignore It.", show_alert=True, ) bot_name = (await userge.bot.get_me()).username await c_q.answer("Without Buttons", show_alert=False) url = f"https://t.me/{bot_name}?start={c_q.matches[0].group(1)}" try: await c_q.edit_message_text( "<b>{} Shared A Spoiler</b> !\n[<b>Click To View</b>]({})". format(mention_html(u_id, u_name), url), disable_web_page_preview=True, ) except MessageNotModified: pass
async def spoiler_alert_(message: Message): content = message.input_str reply = message.reply_to_message if reply and reply.text: content = reply.text.html content = "{}".format(content or "") if not (content or (reply and reply.media)): await message.err("No Content Found!") return rnd_hex = uuid1().hex rnd_id = f"spoiler_{rnd_hex}" SPOILER_DB.save_msg(rnd_hex, (await CHANNEL.store(reply, content))) bot_name = (await userge.bot.get_me()).username link = f"https://t.me/{bot_name}?start={rnd_id}" buttons = None text_ = "<b>{} Shared A Spoiler</b> !\n[<b>Click To View</b>]({})".format( mention_html(message.from_user.id, message.from_user.first_name), link ) if message.client.is_bot: buttons = InlineKeyboardMarkup( [ [ InlineKeyboardButton( "Button", callback_data="getl{}".format(rnd_id) ), InlineKeyboardButton( "Text Link", callback_data="nobtnspoiler{}".format(rnd_id) ), ], [ InlineKeyboardButton( "Via Inline", switch_inline_query=rnd_id.replace("_", " ") ) ], ] ) text_ = "<b><u>Choose How You Want to Share the Spoiler.</b></u>" await message.edit(text_, reply_markup=buttons, disable_web_page_preview=True)
async def get_stats_(message: Message): """get info about your TG account""" start = time.time() await message.edit("πββοΈ `Collecting your Telegram Stats ...`\n" "<b>Please wait it will take some time</b>") owner = await userge.get_me() u_mention = mention_html(owner.id, owner.first_name) unread_mentions = 0 unread_msg = 0 private_chats = 0 bots = 0 users_ = 0 groups = 0 groups_admin = 0 groups_creator = 0 channels = 0 channels_admin = 0 channels_creator = 0 try: async for dialog in userge.iter_dialogs(): unread_mentions += dialog.unread_mentions_count unread_msg += dialog.unread_messages_count chat_type = dialog.chat.type if chat_type in ["bot", "private"]: private_chats += 1 if chat_type == "bot": bots += 1 else: users_ += 1 else: try: is_admin = await admin_check(dialog.chat.id, owner.id) is_creator = dialog.chat.is_creator except UserNotParticipant: is_admin = False is_creator = False if chat_type in ["group", "supergroup"]: groups += 1 if is_admin: groups_admin += 1 if is_creator: groups_creator += 1 else: # Channel channels += 1 if is_admin: channels_admin += 1 if is_creator: channels_creator += 1 except FloodWait as e: await asyncio.sleep(e.x + 5) results = f""" π <b><u>Telegram Stats</u></b> π€ User: <b>{u_mention}</b> <b>Private Chats:</b> <code>{private_chats}</code><code> β’ Users: {users_} β’ Bots: {bots}</code> <b>Groups:</b> <code>{groups}</code> <b>Channels:</b> <code>{channels}</code> <b>Admin in Groups:</b> <code>{groups_admin}</code><code> β Creator: {groups_creator} β’ Admin Rights: {groups_admin - groups_creator}</code> <b>Admin in Channels:</b> <code>{channels_admin}</code><code> β Creator: {channels_creator} β’ Admin Rights: {channels_admin - channels_creator}</code> <b>Unread Messages:</b> <code>{unread_msg}</code> <b>Unread Mentions:</b> <code>{unread_mentions}</code> """ end = time.time() results += f"\nβ³ <i>Process took: {time_formatter(end - start)}.</i>" await message.edit(results)