async def store(self, message: Optional['_message.Message'], caption: Optional[str] = '') -> int: """\nstore message to log channel. Parameters: message (`pyrogram.Message` | `None`): pass pyrogram.Message object which want to forward. caption (`str`, *optional*): Text or Caption of the message to be sent. Returns: message_id on success or None """ caption = caption or '' file_id = None if message and message.caption: caption = caption + message.caption.html if message: file_id = get_file_id_of_media(message) if message and message.media and file_id: if caption: caption = self._string.format(caption.strip()) msg = await message.client.send_cached_media(chat_id=self._id, file_id=file_id, caption=caption) message_id = msg.message_id else: message_id = await self.log(caption) return message_id
async def create_button(msg: Message): """ Create Buttons Using Bot """ if config.BOT_TOKEN is None: await msg.err("First Create a Bot via @Botfather to Create Buttons...") return string = msg.input_raw if not msg.client.is_bot: client = msg.client.bot replied = msg.reply_to_message if replied: try: replied = await client.get_messages( replied.chat.id, replied.id ) except ChannelInvalid: await msg.err("`Are you sure that your bot is here?`\n" "If not , then add it here") return else: client = msg.client replied = msg.reply_to_message file_id = None if replied: if replied.caption: string = replied.caption.html elif replied.text: string = replied.text.html file_id = get_file_id_of_media(replied) if not string: await msg.err("`need an input!`") return text, markup = pb(string) if not text: await msg.err("`need text too!`") return message_id = replied.id if replied else None try: if replied and replied.media and file_id: await client.send_cached_media( chat_id=msg.chat.id, file_id=file_id, caption=text, reply_to_message_id=message_id, reply_markup=markup) else: await client.send_message( chat_id=msg.chat.id, text=text, reply_to_message_id=message_id, reply_markup=markup) except UserIsBot: await msg.err("oops, your Bot is not here to send Msg!") except BadRequest as err: await msg.err("Check Syntax of Your Message for making buttons!") log.debug(str(err)) except Exception as error: await msg.edit(f"`Something went Wrong! 😁`\n\n**ERROR:** `{error}`") else: await msg.delete()
async def _refresh_id(message: Message) -> None: global _LOGO_ID, _IS_STICKER # pylint: disable=global-statement try: media = await message.client.get_messages(_CHAT, _MSG_ID) except (ChannelInvalid, PeerIdInvalid, ValueError): _set_data(True) return await _refresh_id(message) else: if media.sticker: _IS_STICKER = True _LOGO_ID = get_file_id_of_media(media)
async def _custom_media_reply(message: Message): if CUSTOM_REPLIES_IDS: await asyncio.sleep(1) cus_msg = int(random.choice(CUSTOM_REPLIES_IDS)) cus_msg = await message.client.get_messages( chat_id=CUSTOM_REPLY_CHANNEL, message_ids=cus_msg) if cus_msg.service: await _custom_media_reply(message) return if cus_msg.media: file_id = get_file_id_of_media(cus_msg) try: if cus_msg.animation: await message.client.send_animation( chat_id=message.chat.id, animation=file_id, unsave=True, reply_to_message_id=message.message_id, ) else: action = None if cus_msg.audio: action = "upload_audio" elif cus_msg.document: action = "upload_document" elif cus_msg.photo: action = "upload_photo" elif cus_msg.video: action = "upload_audio" elif cus_msg.voice: action = "record_audio" elif cus_msg.video_note: action = "upload_video_note" if action: await message.reply_chat_action(action) await asyncio.sleep(5) await message.reply_cached_media(file_id=file_id) except Exception as idk: # pylint: disable=W0703 LOGGER.log(f"#ERROR: `{idk}`") await _custom_media_reply(message) return if cus_msg.text: await _send_text_like_a_human(message, cus_msg.text)
async def spam(message: Message): replied = message.reply_to_message delay = str(0.1) is_str = "|" in message.input_str if (replied and replied.media and not is_str): if not os.path.isdir(Config.DOWN_PATH): os.makedirs(Config.DOWN_PATH) if replied.sticker: to_spam = replied.sticker.file_id count = message.input_str if " " in count: count, delay = count.split(" ", maxsplit=1) try: count = int(count) delay = float(delay) if '.' in delay else int(delay) except ValueError as e: await message.edit(e) await message.reply_sticker( sticker="CAADAQADzAADiO9hRu2b2xyV4IbAFgQ") return await message.edit(f"Spamming {count} Time") for _ in range(count): if message.process_is_canceled: return await message.edit("`Process Cancelled`") await message.client.send_sticker(sticker=to_spam, chat_id=message.chat.id) await asyncio.sleep(delay) await S_LOG.log( f"Spammed Sticker in Chat» {message.chat.title}, {count} times" ) await message.delete() elif (replied.animation or replied.video or replied.photo or replied.document): to_spam = get_file_id_of_media(replied) count = message.input_str if " " in count: count, delay = count.split(" ", maxsplit=1) try: count = int(count) delay = float(delay) if '.' in delay else int(delay) except ValueError as e: await message.edit(e) await message.reply_sticker( sticker="CAADAQADzAADiO9hRu2b2xyV4IbAFgQ") return await message.edit(f"Spamming {count} times") for _ in range(count): if message.process_is_canceled: return await message.edit("`Process Cancelled`") await message.client.send_cached_media(message.chat.id, to_spam) await asyncio.sleep(delay) await S_LOG.log( f"Spammed Media in Chat» {message.chat.title}, {count} times") await message.delete() elif (replied and replied.text and not is_str): count = message.input_str if " " in count: count, delay = count.split(" ", maxsplit=1) try: count = int(count) delay = float(delay) if '.' in delay else int(delay) except ValueError as e: await message.edit(e) await message.reply_sticker( sticker="CAADAQADzAADiO9hRu2b2xyV4IbAFgQ") return await message.edit(f"Spamming {count} times") for _ in range(count): if message.process_is_canceled: return await message.edit("`Process Cancelled`") await message.client.send_message(text=replied.text, chat_id=message.chat.id) await asyncio.sleep(delay) await S_LOG.log( f"Spammed Text in Chat» {message.chat.title}, {count} times") await message.delete() elif is_str: spam_count, spam_text = message.input_str.split("|", maxsplit=1) if '|' in spam_text: spam_text, delay = spam_text.split("|", maxsplit=1) try: sc = int(spam_count) delay = float(delay) if '.' in delay else int(delay) except ValueError as e: await message.edit(e) await message.reply_sticker( sticker="CAADAQADzAADiO9hRu2b2xyV4IbAFgQ") return await message.edit(f"Spamming {sc} times") for _ in range(sc): if message.process_is_canceled: return await message.edit("`Process Cancelled`") await message.client.send_message(text=spam_text, chat_id=message.chat.id) await asyncio.sleep(delay) await S_LOG.log( f"Spammed Text in Chat» {message.chat.title}, {sc} times") await message.delete() else: await message.edit("Well it doesn't work that way") await message.reply_sticker(sticker="CAADAQAD6gADfAVQRnyVSb3GhGT4FgQ")
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 not message_id or not isinstance(message_id, int): return message = await client.get_messages(chat_id=self._id, message_ids=message_id) caption = '' file_id = 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 = get_file_id_of_media(message) caption, buttons = parse_buttons(caption) 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=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()