Package: pyroaddon
pyroaddonA monkeypatcher add-on forPyrogramIntroductionpyroaddon contains the same functionalities aspyromodplus some more. So basically it's
pyromod on steroids.pyroaddon workstogetherwith pyrogram, this isnota fork nor modded version. It does monkey patching to add features to Pyrogram classes.UsageImportpyroaddonat least one time in your script, so you'll be able to use modified pyrogram in all files of the same proccess. Example:# config.pyimportpyroaddonfrompyrogramimportClientapp=Client('my_session')# any other .pyfromconfigimportapp# no need to import pyroaddon again, pyrogram is already monkeypatched globally (at the same proccess)New FeaturesMessage.inputImport pyroaddon to add the propertyinputtopyrogram.types.Message. When a message contains a command,Message.inputwill contain the text in front of the command if there are any.Example: if/command text in frontis in message.text, ThenMessage.input = "text in front"Note:Message.inputwill preserve any spaces between the text.Client.get_all_groupspyrogram.Client.get_all_groups()will return any group chats that the client is joined in.Client.get_chat_administratorspyrogram.Client.get_chat_administrators(chat_id, has_creator=False)will return chat administrators. Ifhas_creatoris set toTrue, It will also contain the owner.pyroaddon.filtersImport it and the following Update Filters will be monkeypatched topyrogram.filters:filters.video_stickerA video sticker message.filters.ttl_messageA ttl message.Old Featurespyroaddon.listenJust import it, it will automatically do the monkeypatch and you'll get these new methods:await pyrogram.Client.listen(chat_id, filters=None, timeout=30)Awaits for a new message in the specified chat and returns it
You can pass Update Filters to the filters parameter just like you do for the update handlers. e.g.filters=filters.photo & filters.botawait pyrogram.Client.ask(text, chat_id, filters=None, timeout=30)Same of.listen()above, but sends a message before awaiting
You can pass custom parameters to its send_message() call. Check the example below.The bound methodsChat.listen,User.listen,Chat.askandUser.askExample:frompyroaddonimportlisten# or import pyroaddon.listenfrompyrogramimportClientclient=Client(...)...answer=awaitclient.ask(chat_id,'*Send me your name:*',parse_mode='Markdown')awaitclient.send_message(chat_id,f'Your name is:{answer.text}')pyroaddon.navTools for creating navigation keyboards.pyroaddon.nav.PaginationCreates a full pagination keyboard. Usage:frompyrogramimportClient,filtersfrompyroaddon.navimportPaginationfrompyroaddon.helpersimportikbdefpage_data(page):returnf'view_page{page}'defitem_data(item,page):returnf'view_item{item}{page}'defitem_title(item,page):returnf'Item{item}of page{page}'@Client.on_message(filters.regex('/nav'))asyncdefon_nav(c,m):objects=[*range(1,100)]page=Pagination(objects,page_data=page_data,# callback to define the callback_data for page buttons in the bottomitem_data=item_data,# callback to define the callback_data for each item buttonitem_title=item_title# callback to define the text for each item button)index=0# in which page is it now?lines=5# how many lines of the keyboard to include for the itemscolumns=howmanycolumnsincludeineachitems' linekb=page.create(index,lines,columns)awaitm.reply('Test',reply_markup=ikb(kb))pyroaddon.helpersTools for creating inline keyboards a lot easier.pyroaddon.helpers.ikbCreates a inline keyboard. It's first and only argument must be a list (the keyboard) containing lists (the lines) of buttons.
The buttons can also be lists or tuples. I use tuples to not have to deal with a lot of brackets.
The button syntax must be this: (TEXT, CALLBACK_DATA) or (TEXT, VALUE, TYPE), where TYPE can be 'url' or any other supported button type and VALUE is its value. This syntax will be converted to {"text": TEXT, TYPE: VALUE). If TYPE is CALLBACK_DATA, you can omit it, just like the fist syntax above.
Examples:frompyroaddon.helpersimportikb...keyboard=ikb([[('Button 1','call_1'),('Button 2','call_2')],[('Another button','t.me/pyroaddon','url')]])awaitmessage.reply('Test',reply_markup=keyboard)pyroaddon.helpers.array_chunkChunk the elements of a list into small lists. i.e. [1, 2, 3, 4] can become [[1,2], [3,4]]. This is extremely useful if you want to build a keyboard dinamically with more than 1 column. You just put all buttons together in a list and run:lines=array_chunk(buttons,2)# generate a list of lines with 2 buttons on eachkeyboard=ikb(lines)Copyright & LicenseThis project may include snippets of Pyrogram codePyrogram - Telegram MTProto API Client Library for Python. Copyright (C) 2017-2022 Dan <https://github.com/delivrance>Licensed under the terms of theGNU Lesser General Public License v3 or later (LGPLv3+)