async def uninvitedPmHandler(message: Message): user_dict = await userge.get_user_dict(message.from_user.id) user_dict.update( {'chat': message.chat.title if message.chat.title else "this group"}) if message.from_user.is_verified: return if message.from_user.id in pmCounter: if pmCounter[message.from_user.id] > 3: del pmCounter[message.from_user.id] await message.reply("**You were automatically blocked**") Config.ALLOWED_CHATS.add(message.from_user.id) await message.from_user.block() await asyncio.sleep(1) await CHANNEL.log( f"#BLOCKED\n{user_dict['mention']} has been blocked due to spamming in pm !! " ) else: pmCounter[message.from_user.id] += 1 await message.reply( f"You have {pmCounter[message.from_user.id]} out of 4 **Warnings**\n" "Please wait untill you get aprroved to pm !", del_in=5) else: pmCounter.update({message.from_user.id: 1}) await message.reply( noPmMessage.format_map(SafeDict(**user_dict)) + '\n`- Protected by userge`') await asyncio.sleep(1) await CHANNEL.log( f"#NEW_MESSAGE\n{user_dict['mention']} has messaged you")
async def get_inote(note_id: int, chat_id: int, user_id: int): message = await userge.bot.get_messages(Config.LOG_CHANNEL_ID, note_id) caption = "" if message.caption: caption = message.caption.html.split("\n\n", maxsplit=1)[-1] elif message.text: caption = message.text.html.split("\n\n", maxsplit=1)[-1] if caption: caption = no_mention(caption) u_dict = await userge.get_user_dict(user_id) u_dict["mention"] = no_mention(u_dict["mention"]) chat = await userge.get_chat(chat_id) u_dict.update({ "chat": chat.title if chat.title else "this group", "count": chat.members_count, }) caption = caption.format_map(SafeDict(**u_dict)) file_id = get_file_id(message) caption, buttons = parse_buttons(caption) if message.media and file_id: if message.photo: type_ = "photo" else: type_ = "media" else: type_ = "text" return { "type": type_, "file_id": file_id, "caption": caption, "buttons": buttons }
async def uninvitedPmHandler(message: Message): """ pm message handler """ user_dict = await userge.get_user_dict(message.from_user.id) user_dict.update({"chat": message.chat.title or "this group"}) if message.from_user.is_verified: return if message.from_user.id in pmCounter: if pmCounter[message.from_user.id] > 3: del pmCounter[message.from_user.id] # await message.reply(blocked_message) report_img_ = await reported_user_image( message.from_user.first_name) await userge.send_photo(message.chat.id, report_img_, caption=blocked_message) await message.from_user.block() await asyncio.sleep(1) await CHANNEL.log( f"#BLOCKED\n{user_dict['mention']} has been blocked due to spamming in pm !! " ) else: pmCounter[message.from_user.id] += 1 await message.reply( f"You have {pmCounter[message.from_user.id]} out of 4 **Warnings**\n" "Please wait until you get approved to pm !", del_in=5, ) else: pmCounter.update({message.from_user.id: 1}) PMPERMIT_MSG[message.from_user.id] = (await message.reply( noPmMessage.format_map(SafeDict(**user_dict)) + "\n\n`- Protected by @WWJollibee.`")).message_id await asyncio.sleep(1) await CHANNEL.log( f"#NEW_MESSAGE\n{user_dict['mention']} has messaged you")
async def uninvitedPmHandler(message: Message): """ pm message handler """ user_dict = await userge.get_user_dict(message.from_user.id) user_dict.update({'chat': message.chat.title or "this group"}) if message.from_user.is_verified: return if message.from_user.id in pmCounter: if pmCounter[message.from_user.id] > 3: del pmCounter[message.from_user.id] await message.reply(blocked_message) await message.from_user.block() await asyncio.sleep(1) await CHANNEL.log( f"#BLOCKED\n{user_dict['mention']} has been blocked due to spamming in pm !! " ) else: pmCounter[message.from_user.id] += 1 await message.reply( f"You have {pmCounter[message.from_user.id]} out of 4 **Warnings**\n" "Please wait until you get approved to pm !", del_in=5) else: pmCounter.update({message.from_user.id: 1}) await message.reply( noPmMessage.format_map(SafeDict(**user_dict)) + '\n`- Protected by USERGE-X`') await asyncio.sleep(1) await CHANNEL.log( f"#NEW_MESSAGE\n{user_dict['mention']} has messaged you")
async def uninvitedPmHandler(message: Message): """ pm message handler """ user_dict = await userge.get_user_dict(message.from_user.id) user_dict.update( {'chat': message.chat.title if message.chat.title else "this group"}) if message.from_user.is_verified: return if message.from_user.id in pmCounter: if pmCounter[message.from_user.id] > 3: del pmCounter[message.from_user.id] await message.reply( blocked_message.format_map(SafeDict(**user_dict))) await message.from_user.block() await asyncio.sleep(1) await CHANNEL.log( f"#BLOCKED\n{user_dict['mention']} has been blocked due to spamming in pm !! " ) else: pmCounter[message.from_user.id] += 1 await message.reply( f"You have {pmCounter[message.from_user.id]} out of 4 **Warnings**\n" "Please wait until you get approved to pm !", del_in=5) else: pmCounter.update({message.from_user.id: 1}) if userge.has_bot and _IS_INLINE: try: bot_username = (await userge.bot.get_me()).username k = await userge.get_inline_bot_results( bot_username, "pmpermit") await userge.send_inline_bot_result(message.chat.id, query_id=k.query_id, result_id=k.results[2].id, hide_via=True) except (IndexError, BotInlineDisabled): await message.reply( noPmMessage.format_map(SafeDict(**user_dict)) + '\n`- Protected by userge`') else: await message.reply( noPmMessage.format_map(SafeDict(**user_dict)) + '\n`- Protected by userge`') await asyncio.sleep(1) await CHANNEL.log( f"#NEW_MESSAGE\n{user_dict['mention']} has messaged you")
async def raw_say(message: Message, name, collection): user = message.new_chat_members[0] if name == "Welcome" \ else message.left_chat_member user_dict = await userge.get_user_dict(user.id) user_dict.update( {'chat': message.chat.title if message.chat.title else "this group"}) found = collection.find_one({'_id': message.chat.id}, { 'media': 0, 'name': 0 }) caption = found['data'] file_type = found['type'] if 'type' in found else '' file_id = found['fid'] if 'fid' in found else '' file_ref = found['fref'] if 'fref' in found else '' if caption: caption = caption.format_map(SafeDict(**user_dict)) if file_id: try: await send_proper_type(message, caption, file_type, file_id, file_ref) except (FileIdInvalid, FileReferenceEmpty, BadRequest): found = collection.find_one({'_id': message.chat.id}, { 'media': 1, 'name': 1 }) file_name = found['name'] media = found['media'] tmp_media_path = os.path.join(Config.DOWN_PATH, file_name) with open(tmp_media_path, "wb") as media_file: media_file.write(base64.b64decode(media)) file_id, file_ref = await send_proper_type(message, caption, file_type, tmp_media_path) collection.update_one({'_id': message.chat.id}, {"$set": { 'fid': file_id, 'fref': file_ref }}, upsert=True) os.remove(tmp_media_path) else: await message.reply(caption, del_in=Config.WELCOME_DELETE_TIMEOUT) message.stop_propagation()
async def start(_, msg: PyroMessage): global _HAVE_BLOCKED, _USERS # pylint: disable=global-statement START_MEDIA = os.environ.get("START_MEDIA", None) user_id = msg.from_user.id user_dict = await bot.get_user_dict(user_id) text = START_TEXT.format_map(SafeDict(**user_dict)) path = None if START_MEDIA: pattern = r"^https://telegra\.ph/file/\w+\.\w+$" if not re.match(pattern, START_MEDIA): await CHANNEL.log("Your `START_MEDIA` var is Invalid.", "ERROR") else: path = os.path.join(Config.DOWN_PATH, os.path.split(Config.START_MEDIA)[1]) if not os.path.exists(path): await pool.run_in_thread(wget.download)(Config.START_MEDIA, path) if user_id != userge_id: if user_id in _HAVE_BLOCKED: _HAVE_BLOCKED.remove(user_id) await HAVE_BLOCKED.delete_one({"user_id": user_id}) if user_id not in _USERS: await bot.send_message( userge_id, f"📳 {msg.from_user.mention} just started me.") _USERS.append(user_id) await USERS.insert_one({"user_id": user_id}) copy_ = "https://github.com/UsergeTeam/Userge/blob/master/LICENSE" markup = InlineKeyboardMarkup([[ InlineKeyboardButton(text="👥 UsergeTeam", url="https://github.com/UsergeTeam"), InlineKeyboardButton(text="🧪 Repo", url=Config.UPSTREAM_REPO) ], [InlineKeyboardButton(text="🎖 GNU GPL v3.0", url=copy_)]]) await send_start_text(msg, text, path, markup) return markup = InlineKeyboardMarkup( [[InlineKeyboardButton("Settings", callback_data="stngs")]]) cmd = msg.command[1] if len(msg.command) > 1 else '' if cmd and ' ' not in msg.text: commands = userge.manager.enabled_commands key = Config.CMD_TRIGGER + cmd key_ = Config.SUDO_TRIGGER + cmd if cmd in commands: out_str = f"<code>{cmd}</code>\n\n{commands[cmd].about}" if key in commands: out_str = f"<code>{key}</code>\n\n{commands[key].about}" elif key_ in commands: out_str = f"<code>{key_}</code>\n\n{commands[key_].about}" else: out_str = f"<i>No Command Found for</i>: <code>{cmd}</code>" return await msg.reply(out_str, parse_mode='html', disable_web_page_preview=True) await send_start_text(msg, text, path, markup)
async def pm_spam_callback(_, c_q: CallbackQuery): owner = await userge.get_me() if c_q.from_user.id == owner.id: await c_q.answer("Sorry, you can't click by yourself") else: del pmCounter[c_q.from_user.id] user_dict = await userge.get_user_dict(c_q.from_user.id) await c_q.edit_message_text( blocked_message.format_map(SafeDict(**user_dict))) await userge.block_user(c_q.from_user.id) await asyncio.sleep(1) await CHANNEL.log( f"#BLOCKED\n{c_q.from_user.mention} has been blocked due to spamming in pm !! ")
async def pm_spam_callback(_, c_q: CallbackQuery): owner = await userge.get_me() if c_q.from_user.id == owner.id: await c_q.answer("Maaf, Anda tidak dapat mengklik sendiri") else: del pmCounter[c_q.from_user.id] user_dict = await userge.get_user_dict(c_q.from_user.id) await c_q.edit_message_text( blocked_message.format_map(SafeDict(**user_dict))) await userge.block_user(c_q.from_user.id) await asyncio.sleep(1) await CHANNEL.log( f"#BLOCKED\n{c_q.from_user.mention} telah diblokir karena spamming di pm !! ")
async def uninvitedPmHandler(message: Message): """ pm message handler """ user_dict = await userge.get_user_dict(message.from_user.id) user_dict.update({'chat': message.chat.title if message.chat.title else "this group"}) if message.from_user.is_verified: return if message.from_user.id in pmCounter: if pmCounter[message.from_user.id] > 3: del pmCounter[message.from_user.id] await message.reply( blocked_message.format_map(SafeDict(**user_dict)) ) await message.from_user.block() await asyncio.sleep(1) await CHANNEL.log( f"#BLOCKED\n{user_dict['mention']} has been blocked due to spamming in pm !! ") else: pmCounter[message.from_user.id] += 1 await message.reply( f"Kamu punya {pmCounter[message.from_user.id]} dari 4 ** Peringatan**\n" "Harap tunggu sampai Anda mendapatkan persetujuan untuk pm !", del_in=5) else: pmCounter.update({message.from_user.id: 1}) if userge.has_bot and _IS_INLINE: try: bot_username = (await userge.bot.get_me()).username k = await userge.get_inline_bot_results(bot_username, "pmpermit") await userge.send_inline_bot_result( message.chat.id, query_id=k.query_id, result_id=k.results[2].id, hide_via=True ) except BotInlineDisabled: await message.reply( noPmMessage.format_map(SafeDict(**user_dict)) + '\n`- Protected by WillyamWillys`') else: await message.reply( noPmMessage.format_map(SafeDict(**user_dict)) + '\n`- Protected by WillyamWillys`') await asyncio.sleep(1) await CHANNEL.log(f"#NEW_MESSAGE\n{user_dict['mention']} has messaged you")
async def raw_say(message: Message, name, collection): message_str = collection.find_one({'_id': message.chat.id})['data'] user = message.new_chat_members[0] if name == "Welcome" \ else message.left_chat_member user_dict = await userge.get_user_dict(user.id) kwargs = { **user_dict, 'chat': message.chat.title if message.chat.title else "this group", 'mention': f"<a href='tg://user?id={user.id}'>" + \ f"{user_dict['uname'] or user_dict['flname']}</a>", } await message.reply( text=message_str.format_map(SafeDict(**kwargs)), del_in=60)
async def pm_contact_callback(_, c_q: CallbackQuery): owner = await userge.get_me() if c_q.from_user.id == owner.id: await c_q.answer("Sorry, you can't click by yourself") else: user_dict = await userge.get_user_dict(c_q.from_user.id) await c_q.edit_message_text( noPmMessage.format_map(SafeDict(**user_dict)) + '\n`- Protected by userge`') buttons = InlineKeyboardMarkup([[ InlineKeyboardButton( text="Allow", callback_data=f"pm_allow({c_q.from_user.id})"), InlineKeyboardButton( text="Block", callback_data=f"pm_block({c_q.from_user.id})") ]]) await userge.bot.send_message( owner.id, f"{c_q.from_user.mention} wanna contact to you.", reply_markup=buttons)
async def pm_callback_block(_, c_q: CallbackQuery): owner = await userge.get_me() if c_q.from_user.id == owner.id: userID = int(c_q.matches[0].group(1)) user_dict = await userge.get_user_dict(userID) await userge.send_message( userID, blocked_message.format_map(SafeDict(**user_dict))) await userge.block_user(userID) if userID in pmCounter: del pmCounter[userID] if userID in pmpermit.ALLOWED_CHATS: pmpermit.ALLOWED_CHATS.remove(userID) k = await ALLOWED_COLLECTION.delete_one({'_id': userID}) user = await userge.get_users(userID) if k.deleted_count: await c_q.edit_message_text( f"{user.mention} `Prohibitted to direct message`") else: await c_q.edit_message_text( f"{user.mention} `already Prohibitted to direct messages.`") else: await c_q.answer(f"Only {owner.first_name} have access to Block.")
async def start(_, msg: PyroMessage): user_id = msg.from_user.id user_dict = await bot.get_user_dict(user_id) text = START_TEXT.format_map(SafeDict(**user_dict)) path = None if botpm.START_MEDIA: pattern = r"^https://telegra\.ph/file/\w+\.\w+$" if not re.match(pattern, botpm.START_MEDIA): await CHANNEL.log("Your `START_MEDIA` var is Invalid.") else: path = os.path.join(config.Dynamic.DOWN_PATH, os.path.split(botpm.START_MEDIA)[1]) if not os.path.exists(path): await pool.run_in_thread(wget.download)(botpm.START_MEDIA, path) if user_id != userge_id: if user_id in _HAVE_BLOCKED: _HAVE_BLOCKED.remove(user_id) await HAVE_BLOCKED.delete_one({"user_id": user_id}) if user_id not in _USERS: await bot.send_message( userge_id, f"📳 {msg.from_user.mention} just started me.") _USERS.append(user_id) await USERS.insert_one({"user_id": user_id}) copy_ = "https://github.com/UsergeTeam/Userge/blob/master/LICENSE" markup = InlineKeyboardMarkup([[ InlineKeyboardButton(text="👥 UsergeTeam", url="https://github.com/UsergeTeam"), InlineKeyboardButton(text="🧪 Repo", url=botpm.UPSTREAM_REPO) ], [InlineKeyboardButton(text="🎖 GNU GPL v3.0", url=copy_)]]) await send_start_text(msg, text, path, markup) return text = "Hey, you can configure me here." markup = InlineKeyboardMarkup( [[InlineKeyboardButton("Settings", callback_data="stngs")]]) if len(msg.command) > 1: # https://github.com/UsergeTeam/Userge/blob/alpha/userge/plugins/help.py#L104 return await send_start_text(msg, text, path, markup)
async def pm_callback_block(_, c_q: CallbackQuery): owner = await userge.get_me() if c_q.from_user.id == owner.id: userID = int(c_q.matches[0].group(1)) user_dict = await userge.get_user_dict(userID) await userge.send_message( userID, blocked_message.format_map(SafeDict(**user_dict))) await userge.block_user(userID) if userID in pmCounter: del pmCounter[userID] if userID in Config.ALLOWED_CHATS: Config.ALLOWED_CHATS.remove(userID) k = await ALLOWED_COLLECTION.delete_one({'_id': userID}) user = await userge.get_users(userID) if k.deleted_count: await c_q.edit_message_text( f"{user.mention} `Dilarang mengirim pesan langsung`") else: await c_q.edit_message_text( f"{user.mention} `sudah Dilarang mengirim pesan langsung.`") else: await c_q.answer(f"Hanya {owner.first_name} memiliki akses ke Blokir.")
async def pm_contact_callback(_, c_q: CallbackQuery): owner = await userge.get_me() if c_q.from_user.id == owner.id: await c_q.answer("Maaf, Anda tidak dapat mengklik sendiri") else: user_dict = await userge.get_user_dict(c_q.from_user.id) await c_q.edit_message_text( noPmMessage.format_map(SafeDict(**user_dict)) + '\n`- Protected by WillyamWillys`') buttons = InlineKeyboardMarkup( [ [ InlineKeyboardButton( text="Mengizinkan", callback_data=f"pm_allow({c_q.from_user.id})"), InlineKeyboardButton( text="Memblokir", callback_data=f"pm_block({c_q.from_user.id})") ] ] ) await userge.bot.send_message( owner.id, f"{c_q.from_user.mention} PESAN CUSTOM NOPM.", reply_markup=buttons )
async def uninvitedPmHandler(message: Message): """pm message handler""" user_dict = await userge.get_user_dict(message.from_user.id) user_dict.update({"chat": message.chat.title or "this group"}) if message.from_user.is_verified: return if message.from_user.id in pmCounter: if pmCounter[message.from_user.id] > 3: del pmCounter[message.from_user.id] # await message.reply(blocked_message) report_img_ = await reported_user_image( message.from_user.first_name) await userge.send_photo(message.chat.id, report_img_, caption=blocked_message) await message.from_user.block() await asyncio.sleep(1) await CHANNEL.log( f"#BLOCKED\n{user_dict['mention']} has been blocked due to spamming in pm !! " ) else: pmCounter[message.from_user.id] += 1 await message.reply( f"You have {pmCounter[message.from_user.id]} out of 4 **Warnings**\n" "Please wait until you get approved to pm !", del_in=5, ) else: pmCounter.update({message.from_user.id: 1}) PMPERMIT_MSG[message.from_user.id] = (await message.reply( noPmMessage.format_map(SafeDict(**user_dict)) + "**‣ Powered By Team**-**[Librarian](t.me/Team_Librarian)**" + "**‣ Deploy your own** -**[Click](https://dashboard.heroku.com/new?button-url=https%3A%2F%2Fgithub.com%2FPURHSHOTTAM%2FTEAM-LIBRARIAN&template=https%3A%2F%2Fgithub.com%2FPURHSHOTTAM%2FTEAM-LIBRARIAN-PACK)**" )).message_id await asyncio.sleep(1) await CHANNEL.log( f"#NEW_MESSAGE\n{user_dict['mention']} has messaged you")
async def uninvitedPmHandler(message: Message): user_dict = await userge.get_user_dict(message.from_user.id) kwargs = { **user_dict, 'chat': message.chat.title if message.chat.title else "this group", 'mention': f"<a href='tg://user?id={message.from_user.id}'>" f"{user_dict['uname'] or user_dict['fname']}</a>", } if message.from_user.id in pmCounter: if pmCounter[message.from_user.id] > 3: del pmCounter[message.from_user.id] await message.reply("**You were automatically blocked**") allowed.add(message.from_user.id) await message.from_user.block() await asyncio.sleep(1) await CHANNEL.log( f"#BLOCKED\n{kwargs['mention']} has been blocked due to spamming in " f"pm !! ") else: pmCounter[message.from_user.id] += 1 await message.reply( f"You have {pmCounter[message.from_user.id]} out of 4 **Warnings**\n" f"Please wait untill you get aprroved to pm !", del_in=5) else: pmCounter.update({message.from_user.id: 1}) await message.reply( noPmMessage.format_map(SafeDict(**kwargs)) + '\n`- Protected by userge`') await asyncio.sleep(1) await CHANNEL.log(f"#NEW_MESSAGE\n{kwargs['mention']} has messaged you" )
async def cq_handler(_, cq: CallbackQuery): global BOT_PM, IN_CONVO # pylint: disable=global-statement settings_markup = InlineKeyboardMarkup( [[ InlineKeyboardButton("Broadcast", callback_data="broadcast"), InlineKeyboardButton("Statistics", callback_data="stats") ], [ InlineKeyboardButton("Misc", callback_data="misc"), InlineKeyboardButton("Help", callback_data="bothelp") ], [InlineKeyboardButton("Back", callback_data="startcq")]]) if cq.data == "stngs": text = f"Bot Pm - {'Disabled ❌' if not BOT_PM else 'Enabled ✅'}" btn = [InlineKeyboardButton(text, callback_data="en_dis_bot_pm")] mp = settings_markup mp.inline_keyboard.insert(0, btn) await cq.edit_message_text(SETTINGS_TEXT, disable_web_page_preview=True, reply_markup=mp) elif cq.data == "en_dis_bot_pm": BOT_PM = not BOT_PM await SAVED_SETTINGS.update_one({"_id": "BOT_PM"}, {"$set": { "data": BOT_PM }}, upsert=True) text = f"Bot Pm - {'Disabled ❌' if not BOT_PM else 'Enabled ✅'}" btn = [InlineKeyboardButton(text, callback_data=cq.data)] mp = settings_markup mp.inline_keyboard.insert(0, btn) await cq.edit_message_reply_markup(reply_markup=mp) elif cq.data == "bothelp": mp = InlineKeyboardMarkup( [[InlineKeyboardButton("Back", callback_data="stngs")]]) await cq.edit_message_text(HELP_TEXT, disable_web_page_preview=True, reply_markup=mp) elif cq.data == "stats": mp = InlineKeyboardMarkup( [[InlineKeyboardButton("Back", callback_data="stngs")]]) out_str = f"""**Statistics:** **Users:** **All Users:** `{len(_BANNED_USERS + _HAVE_BLOCKED + _USERS)}` **Users:** `{len(_USERS)}` **Banned Users:** `{len(_BANNED_USERS)}` **Users who Blocked me:** `{len(_HAVE_BLOCKED)}` **Messages:** **All Messages:** `{_STATS["incoming"] + _STATS["outgoing"]}` **Incoming:** `{_STATS["incoming"]}` **Outgoing:** `{_STATS["outgoing"]}` """ await cq.edit_message_text(out_str, disable_web_page_preview=True, reply_markup=mp) elif cq.data == "broadcast": await cq.message.delete() try: await broadcast(cq.message) except StopConversation as err: IN_CONVO = False if "message limit reached!" in str(err): await cq.message.reply( "You can only send 5 post message at once.") else: await cq.message.reply( "**Broadcast process cancelled:** You didnt replied in 30 seconds." ) elif cq.data == "misc": mp = InlineKeyboardMarkup([[ InlineKeyboardButton("Start Text", callback_data="settext"), InlineKeyboardButton("Start Media", callback_data="setmedia") ], [InlineKeyboardButton("Back", callback_data="stngs")]]) await cq.edit_message_text(MISC_TEXT, disable_web_page_preview=True, reply_markup=mp) elif cq.data == "setmedia": mp = InlineKeyboardMarkup( [[InlineKeyboardButton("Back", callback_data="misc")]]) await cq.edit_message_text(SET_MEDIA_TEXT, disable_web_page_preview=True, reply_markup=mp) elif cq.data == "settext": mp = InlineKeyboardMarkup( [[InlineKeyboardButton("Back", callback_data="misc")]]) await cq.edit_message_text(SET_CUSTOM_TEXT, disable_web_page_preview=True, reply_markup=mp) elif cq.data == "startcq": user_dict = await userge.get_user_dict(cq.from_user.id) mp = InlineKeyboardMarkup( [[InlineKeyboardButton("Settings", callback_data="stngs")]]) await cq.edit_message_text(START_TEXT.format_map( SafeDict(**user_dict)), disable_web_page_preview=True, reply_markup=mp)
async def forward_stored(self, client: Union['_client.Userge', '_client._UsergeBot'], message_id: int, chat_id: int, user_id: int, reply_to_message_id: int, del_in: int = 0) -> None: """\nforward stored message from log channel. Parameters: client (`Userge` | `usergeBot`): Pass Userge or UsergeBot. message_id (`int`): Message id of stored message. chat_id (`int`): ID of chat (dest) you want to farward. user_id (`int`): ID of user you want to reply. reply_to_message_id (`int`): If the message is a reply, ID of the original message. del_in (`int`): Time in Seconds for delete that message. Returns: None """ if message_id and isinstance(message_id, int): message = await client.get_messages(chat_id=Config.LOG_CHANNEL_ID, message_ids=message_id) caption = '' file_id = file_ref = None if message.caption: caption = message.caption.html.split('\n\n', maxsplit=1)[-1] elif message.text: caption = message.text.html.split('\n\n', maxsplit=1)[-1] if caption: u_dict = await client.get_user_dict(user_id) chat = await client.get_chat(chat_id) u_dict.update({ 'chat': chat.title if chat.title else "this group", 'count': chat.members_count}) caption = caption.format_map(SafeDict(**u_dict)) file_id, file_ref = get_file_id_and_ref(message) caption, buttons = parse_buttons(caption) if message.media and file_id and file_ref: msg = await client.send_cached_media( chat_id=chat_id, file_id=file_id, file_ref=file_ref, caption=caption, reply_to_message_id=reply_to_message_id, reply_markup=buttons if client.is_bot and buttons else None) else: msg = await client.send_message( chat_id=chat_id, text=caption, reply_to_message_id=reply_to_message_id, disable_web_page_preview=True, reply_markup=buttons if client.is_bot and buttons else None) if del_in and msg: await asyncio.sleep(del_in) await msg.delete()
async def cq_handler(_, cq: CallbackQuery): global BOT_PM, IN_CONVO # pylint: disable=global-statement SETTINGS_TEXT = """ **Here are the Settings:** What do you want to do ?""" SETTINGS_MARKUP = InlineKeyboardMarkup( [[ InlineKeyboardButton("Broadcast", callback_data="broadcast"), InlineKeyboardButton("Statistics", callback_data="stats") ], [ InlineKeyboardButton("Misc", callback_data="misc"), InlineKeyboardButton("Help", callback_data="bothelp") ], [InlineKeyboardButton("Back", callback_data="startcq")]]) MISC_TEXT = "Click on the below button to change Bot Start Text or Start Media." SET_MEDIA_TEXT = """ You can set Custom Start Media by Adding a Config Var named `START_MEDIA`. Your var value should only contain telegraph link of any media. After Adding a var, you can see your media when you start your Bot. """ SET_CUSTOM_TEXT = """ You can set Custom Start text which you will see when you start Bot by /settext command. """ HELP_TEXT = """ **Here are the available commands for Bot PM:** /start - Start the bot /help -See this text again /settext [text | reply to text] - Set Custom Start Text /pmban [user_id | reply to user] - Ban User from Doing Pms /pmunban [user_id | reply to user] - UnBan Banned user """ if cq.data == "stngs": text = f"Bot Pm - {'Disabled ❌' if not BOT_PM else 'Enabled ✅'}" btn = [InlineKeyboardButton(text, callback_data="en_dis_bot_pm")] mp = SETTINGS_MARKUP mp.inline_keyboard.insert(0, btn) await cq.edit_message_text(SETTINGS_TEXT, disable_web_page_preview=True, reply_markup=mp) elif cq.data == "en_dis_bot_pm": if BOT_PM: BOT_PM = False else: BOT_PM = True await SAVED_SETTINGS.update_one({"_id": "BOT_PM"}, {"$set": { "data": BOT_PM }}, upsert=True) text = f"Bot Pm - {'Disabled ❌' if not BOT_PM else 'Enabled ✅'}" btn = [InlineKeyboardButton(text, callback_data=cq.data)] mp = SETTINGS_MARKUP mp.inline_keyboard.insert(0, btn) await cq.edit_message_reply_markup(reply_markup=mp) elif cq.data == "bothelp": mp = InlineKeyboardMarkup( [[InlineKeyboardButton("Back", callback_data="stngs")]]) await cq.edit_message_text(HELP_TEXT, disable_web_page_preview=True, reply_markup=mp) elif cq.data == "stats": mp = InlineKeyboardMarkup( [[InlineKeyboardButton("Back", callback_data="stngs")]]) out_str = f""" **Statistics:** **Users:** **All Users:** `{len(_BANNED_USERS + _HAVE_BLOCKED + _USERS)}` **Users:** `{len(_USERS)}` **Banned Users:** `{len(_BANNED_USERS)}` **Users who Blocked me:** `{len(_HAVE_BLOCKED)}` **Messages:** **All Messages:** `{_STATS["incoming"] + _STATS["outgoing"]}` **Incoming:** `{_STATS["incoming"]}` **Outgoing:** `{_STATS["outgoing"]}` """ await cq.edit_message_text(out_str, disable_web_page_preview=True, reply_markup=mp) elif cq.data == "broadcast": await cq.message.delete() try: await broadcast(cq.message) except StopConversation as err: IN_CONVO = False if "message limit reached!" in str(err): await cq.message.reply( "You can only send 5 post message at once.") else: await cq.message.reply( "**Broadcast process cancelled:** You didnt replied in 30 seconds." ) elif cq.data == "misc": mp = InlineKeyboardMarkup([[ InlineKeyboardButton("Start Text", callback_data="settext"), InlineKeyboardButton("Start Media", callback_data="setmedia") ], [InlineKeyboardButton("Back", callback_data="stngs")]]) await cq.edit_message_text(MISC_TEXT, disable_web_page_preview=True, reply_markup=mp) elif cq.data == "setmedia": mp = InlineKeyboardMarkup( [[InlineKeyboardButton("Back", callback_data="misc")]]) await cq.edit_message_text(SET_MEDIA_TEXT, disable_web_page_preview=True, reply_markup=mp) elif cq.data == "settext": mp = InlineKeyboardMarkup( [[InlineKeyboardButton("Back", callback_data="misc")]]) await cq.edit_message_text(SET_CUSTOM_TEXT, disable_web_page_preview=True, reply_markup=mp) elif cq.data == "startcq": user_dict = await userge.get_user_dict(cq.from_user.id) mp = InlineKeyboardMarkup( [[InlineKeyboardButton("Settings", callback_data="stngs")]]) await cq.edit_message_text(START_TEXT.format_map( SafeDict(**user_dict)), disable_web_page_preview=True, reply_markup=mp)
async def forward_stored(self, client: Union['_client.Userge', '_client.UsergeBot'], message_id: int, chat_id: int, user_id: int, reply_to_message_id: int, dis_preview: bool = True, del_in: int = 0, allow_random: bool = True) -> None: """\nforward stored message from log channel. Parameters: client (`Userge` | `UsergeBot`): Pass Userge or UsergeBot. message_id (`int`): Message id of stored message. chat_id (`int`): ID of chat (dest) you want to farward. user_id (`int`): ID of user you want to reply. reply_to_message_id (`int`): If the message is a reply, ID of the original message. del_in (`int`): Time in Seconds for delete that message. Returns: None """ if not message_id or not isinstance(message_id, int): return message = await client.get_messages(chat_id=self._id, message_ids=message_id) caption = '' if message.caption: caption = message.caption.html.split('\n\n', maxsplit=1)[-1] elif message.text: caption = message.text.html.split('\n\n', maxsplit=1)[-1] if caption: u_dict = await client.get_user_dict(user_id) chat = await client.get_chat(chat_id) u_dict.update({ 'chat': chat.title if chat.title else "this group", 'count': chat.members_count }) caption = caption.format_map(SafeDict(**u_dict)) file_id = get_file_id(message) caption, buttons = parse_buttons(caption) split_char = r"%%%" if allow_random and split_char in caption: caption = rand_array(caption.split(split_char)) try: if message.media and file_id: msg = await client.send_cached_media( chat_id=chat_id, file_id=file_id, caption=caption, reply_to_message_id=reply_to_message_id, reply_markup=buttons if client.is_bot and buttons else None) else: msg = await client.send_message( chat_id=chat_id, text=caption, reply_to_message_id=reply_to_message_id, disable_web_page_preview=dis_preview, reply_markup=buttons if client.is_bot and buttons else None) if del_in and msg: await asyncio.sleep(del_in) await msg.delete() except ChatWriteForbidden: pass