一个monkeypatcher插件,用于热解图
pyromod的Python项目详细描述
派洛莫德
一个monkeypatcher附加组件,用于热图
简介
pyromod是我为扩展Pyrogram的个人用途而开发的一个实用程序的汇编。后来我开始使用它和更多的机器人,现在我发布了它,使它更容易安装在新项目中。 它与pyrogram一起工作,这是not一个fork或moded版本。它做了猴子补丁来增加特性的图表类。在
重要提示:您应该已经安装了asyncio pyrogram。在
使用
在脚本中至少导入一次pyromod
,这样就可以在同一进程的所有文件中使用修改后的pyrogram。示例:
# config.pyimportpyromod.listenfrompyrogramimportClientapp=Client('my_session')^{pr2}$
我在软件包之间分开了补丁,这样你就可以只导入你想要的东西了。每个包的__init__.py
在导入后立即自动执行monkeypatch(除了pyromod.helpers
,它提供了应该显式导入的类和函数)。在
pyromod.listen
只需导入它,它将自动执行monkeypatch,您将获得以下新方法:
- 在
在await pyrogram.Client.listen(chat_id, filters=None, timeout=30)
在指定的聊天中等待新消息并返回 您可以像处理更新处理程序一样,将更新过滤器传递给Filters参数。e、 g.filters=filters.photo & filters.bot
- 在
在await pyrogram.Client.ask(text, chat_id, filters=None, timeout=30)
与上面的.listen()
相同,但在等待之前发送一条消息 您可以将自定义参数传递给它的send_message()调用。检查下面的例子。在 - 在
绑定方法
在Chat.listen
、User.listen
、Chat.ask
和{}
示例:
frompyromodimportlisten# or import pyromod.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}')
pyromod.filters
导入它,以下更新筛选器将被monkeypatched到pyrogram.filters
:
filters.dice
骰子信息。在
pyromod.nav
用于创建导航键盘的工具。在
pyromod.nav.Pagination
创建完整的分页键盘。用法:
frompyrogramimportClient,filtersfrompyromod.navimportPaginationfrompyromod.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))
pyromod.helpers
创建内嵌键盘的工具要容易得多。在
pyromod.helpers.ikb
创建内联键盘。它的第一个也是唯一的参数必须是包含按钮列表(行)的列表(键盘)。 按钮也可以是列表或元组。我使用元组不用处理很多括号。 按钮语法必须是:(TEXT,CALLBACK_DATA)或(TEXT,VALUE,TYPE),其中TYPE可以是“url”或任何其他受支持的按钮类型,VALUE是其值。此语法将转换为{“text”:text,TYPE:VALUE)。如果TYPE是CALLBACK_DATA,您可以省略它,就像上面的第一个语法一样。 示例:
frompyromod.helpersimportikb...keyboard=ikb([[('Button 1','call_1'),('Button 2','call_2')],[('Another button','t.me/pyromod','url')]])awaitmessage.reply('Test',reply_markup=keyboard)
pyromod.helpers.array_chunk
将列表中的元素分为小的列表。i、 e.[1,2,3,4]可以变成[[1,2],[3,4]]。如果您想用多于一列的方式构建一个键盘,这是非常有用的。您只需将所有按钮放在一个列表中,然后运行:
lines=array_chunk(buttons,2)# generate a list of lines with 2 buttons on eachkeyboard=ikb(lines)
版权和许可证
这个项目可能包括一些图表代码
- Python的pythogram-Telegram MTProto-API客户端库。版权所有(C)2017-2020 Dan<;https://github.com/delivrance>
根据GNU Lesser General Public License v3 or later (LGPLv3+)条款授权
- 项目
标签: