def decorator(func: Callable) -> Callable: if isinstance(self, pyrogram.Client): self.add_handler(pyrogram.MessageHandler(func, filters), group) elif isinstance(self, Filter) or self is None: func.handler = (pyrogram.MessageHandler(func, self), group if filters is None else filters) return func
def decorator(func): handler = pyrogram.MessageHandler(func, filters) if isinstance(self, Filter): return pyrogram.MessageHandler(func, self), group if filters is None else filters if self is not None: self.add_handler(handler, group) return handler, group
def decorator(func: callable) -> Tuple[Handler, int]: if isinstance(func, tuple): func = func[0].callback handler = pyrogram.MessageHandler(func, filters) if isinstance(self, Filter): return pyrogram.MessageHandler(func, self), group if filters is None else filters if self is not None: self.add_handler(handler, group) return handler, group
def start(self) -> None: self.client.start() # Get info self.user: tg.User = self.client.get_me() self.uid: int = self.user.id # Register handlers with new info self.client.add_handler( tg.MessageHandler( self.on_command, tg.Filters.user(self.uid) & tg.Filters.command( list(self.commands.keys()), prefix=self.prefix))) self.client.add_handler(tg.MessageHandler(self.on_message)) # Save config in the background self.writer_thread: threading.Thread = threading.Thread( target=self.writer) self.writer_thread.daemon = True self.writer_thread.start()
def start(self): self.client.start() # Get info self.user = self.client.get_me() self.uid = self.user.id # Record start time and dispatch start event self.start_time_us = util.time_us() self.dispatch_event('start', self.start_time_us) # Register handlers with new info self.client.add_handler(tg.MessageHandler(self.on_message), group=1) self.register_command_handler() # Save config in the background self.writer_thread = threading.Thread(target=self.writer) self.writer_thread.daemon = True self.writer_thread.start() print('Bot is ready')
quote=True, disable_web_page_preview=True, disable_notification=True, ) except Exception as e: work_area = os.path.join(Config.TMP_DOWNLOAD_DIRECTORY, str(time.time())) # create download directory, if not exist if not os.path.isdir(work_area): os.makedirs(work_area) temp_writing_file = os.path.join(work_area, "json.text") with open(temp_writing_file, "w+", encoding="utf8") as out_file: out_file.write(str(message)) await message.reply_document(document=temp_writing_file, caption=str(e), disable_notification=True, quote=True) os.remove(temp_writing_file) if __name__ == "__main__": # create download directory, if not exist if not os.path.isdir(Config.TMP_DOWNLOAD_DIRECTORY): os.makedirs(Config.TMP_DOWNLOAD_DIRECTORY) app = pyrogram.Client("PyroJsonDumpBot", bot_token=Config.TG_BOT_TOKEN, api_id=Config.APP_ID, api_hash=Config.API_HASH) app.add_handler(pyrogram.MessageHandler(new_message_event)) app.run()
def decorator(func): self.add_handler(pyrogram.MessageHandler(func, filters), group) return func
def register_command_handler(self): self.cmd_handler = self.client.add_handler(tg.MessageHandler( self.on_command, tg.Filters.user(self.uid) & tg.Filters.command( list(self.commands.keys()), prefix=self.prefix)), group=0)
description = " " + " \r\n ❤️ @Bfas237Bots " sent = bot.send_document(update.from_user.id, required_file_name, progress = prog, progress_args = (update.message.message_id, update.from_user.id, required_file_name), caption='**File Size**: {}\n\n**Completed in**: `{}` **Seconds**\n'.format(str(pretty_size(total_length)), str(int(t2 - t1))), reply_to_message_id=update.message.message_id) time.sleep(1) bot.edit_message_caption(update.from_user.id,sent.message_id, caption='{}'.format(description)) os.remove(required_file_name) else: bot.edit_message_text(update.from_user.id, update.message.message_id, "No valid Download link was found.\n\n The server terminated all request. Kindly try again") except Exception as Err: bot.edit_message_text(update.from_user.id, update.message.message_id, Err) traceback.print_exc() if __name__ == "__main__" : # create download directory, if not exist if not os.path.isdir(Config.DOWNLOAD_LOCATION): os.makedirs(Config.DOWNLOAD_LOCATION) app.add_handler(pyrogram.MessageHandler(start, pyrogram.Filters.command(["start"]))) app.add_handler(pyrogram.MessageHandler(ft, pyrogram.Filters.command(["ft"]))) app.add_handler(pyrogram.MessageHandler(fo, pyrogram.Filters.command(["fo"]))) app.add_handler(pyrogram.MessageHandler(search, pyrogram.Filters.command(["search" , "s"]))) app.add_handler(pyrogram.MessageHandler(help, pyrogram.Filters.command(["help"]))) app.add_handler(pyrogram.MessageHandler(messages, pyrogram.Filters.text)) app.add_handler(pyrogram.CallbackQueryHandler(button)) app.run()