一个无头客户端“Mirai”的框架。

python-mirai-core的Python项目详细描述


用于HTTP的Python SDK

中文

Python-Mirai派生。如果您决定Star这个项目,请 还有Star原始项目。在

一个瓶子状的Python包装纸Mirai-HTTP-API

请参阅完整文档here

与mirai core 1.0RC同步

安装

从PyPI安装

pip install python-mirai-core

从GitHub安装

^{pr2}$

TL;DR

请参见PyCharm或VSCode生成的代码完成。在

基本原理:

Bot和{}是与miraihttpapi交互的两个对象。在

Bot包含所有出站操作(例如send_message), 所有方法都有很好的文档记录,内部方法以_开头

Updater处理所有入站更新(例如接收事件或消息)

可用事件列表在mirai_core.models.Events下。在

可用消息组件列表(用于构造消息链)位于mirai_core.models.Message下。在

特点

  • 当控制台重新启动或会话过期时,会自动与mirai控制台进行更新程序握手

  • 类似于python telegram bot或aigram的逻辑

  • 消息类型在任何地方都是一个参数,不再发送“组/朋友/临时消息”

  • 支持单个事件的多个侦听器,请使用return True仅阻止对此事件的进一步调用

  • 支持Websocket(默认启用)

  • 支持xml/json/app消息

示例

frommirai_coreimportBot,Updaterfrommirai_core.modelsimportEvent,Message,Typesqq=123456host='127.0.0.1'port=18080auth_key='abcdefgh'bot=Bot(qq,host,port,auth_key)updater=Updater(bot)# for bot methods, see available methods under mirai_core.Bot# for event types, see mirai_core.models.Event# for enums, see mirai_core.models.Types# for exception types, see mirai_core.exceptions# this is how handling inbound events looks like@updater.add_handler([Event.Message])asyncdefhandler(event:Event.BaseEvent):"""    handler for multiple events    :param event: generic type of event    if only one type of event is handled by this method, the type hinting should be changed accordingly    e.g. async def handler(event: BaseEvent.Message):    in order to see detailed definition of a certain event, either use isinstance to restrict the type, or change the    type hinting in event handler's definition    e.g. if isinstance(event, BaseEvent.Message):    :return: True for block calling other event handlers for this event, None or False for keep calling the rest    """ifisinstance(event,Event.Message):# handle different types of events# see auto completion for event for available attributes# echoawaitbot.send_message(target=event.sender,message_type=event.type,message=event.messageChain,quote_source=event.messageChain.get_source())# custom message# see auto completion for Message for more available message componentsmessage_chain=[# see docstring for __init__ for argument descriptionsMessage.Plain(text='test')]ifevent.type==Types.MessageType.GROUP:message_chain.append(event.member.id)image=Message.Image(path='/root/whatever.jpg')message_chain.append(image)# see docstring for individual methodbot_message=awaitbot.send_message(target=event.sender,message_type=event.type,message=message_chain,# friend message can also quoted, but only viewable by QQ, not TIMquote_source=event.messageChain.get_source())# in case you want the message id for recallingprint(bot_message.messageId)# in case you want the image id (only available when sending via local path instead of url)# the image id is available for two weeks from the last time it is usedimage_id=image.imageIdprint(image_id)returnTrue# run the updater forever, block the program from exitingupdater.run()

综合示例:请参见UMR

谢谢

谢谢^{}给我们带来了{a7},一个伟大的工作^{} 为QQ机器人提供无限的可能性。在

感谢^{}的启发和数据解析。在

许可证

^{}

^{}相同

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java JavaFX TableView更新单元格,不更新对象值   在扫描器中使用分隔符的java   java OkHttp 4.9.2,连接无法重用,导致端口耗尽   eclipse中的c JNI:运行Java代码   java是否在出厂的所有硬件设备中都有/mnt/sdcard/Android/data文件夹(或等效文件夹)?   Java,在eclipse中访问资源文件夹中的图像   java为什么Bluemix dashDB操作抛出SqlSyntaxErrorException,SQLCODE=1667?   JavaHtmlUnitWebClient。getPage不处理javascript   Google API认证的java问题   java如何将JSON数组反序列化为Apache beam PCollection<javaObject>   ServerSocket停止接收命令,java/安卓   来自Java类的安卓 Toast消息   java如何自动重新加载应用程序引擎开发服务器?   java是否可以尝试/捕获一些东西来检查是否抛出了异常?   java如何做到这一点当我按下load game时,它不仅会加载信息,还会将您带到游戏中?   Java选项Xmx代表什么?   Java映射,它在插入时打印值   设置“ulimit c unlimited”后,java无法生成系统核心转储