GithubHelp home page GithubHelp logo

rf-tar-railt / cesloi Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 1.0 240 KB

一个简易,基于 mirai-api-http v2 的Python SDK

License: GNU Affero General Public License v3.0

Python 100.00%
python asyncio qqbot mirai-api-http bot qq

cesloi's Introduction

Cesloi

pesis rin usi ti oinio, mo atem

简介

Licence PyPI PyPI - Python Version

一个简易(?),基于 mirai-api-http v2 的 Python SDK。

本项目适用于 mirai-api-http 2.0 以上版本

项目仍处于开发阶段,部分内容可能会有较大改变

注: mirai-api-http 需要启用ws adapter和http adapter

依赖

本项目依赖于ArcletProject下的LetodereaAlconna

文档

Cesloi暂时的文档

安装

pip install cesloi

简单的开始

通常版本

from arclet.cesloi.bot_client import Cesloi
from arclet.cesloi.model.relation import Friend
from arclet.cesloi.communicate_with_mah import BotSession

bot = Cesloi(bot_session=BotSession(host="http://localhost:8080", account=1234567890, verify_key="INITKEYWylsVdbr"),debug=False)

@bot.register("FriendMessage")
async def test(app: Cesloi, friend: Friend):
    await app.send_with(friend, "Hello, World!", nudge=True)
    
bot.start()

使用插件的版本

In main.py :

from arclet.cesloi.bot_client import Cesloi
from arclet.cesloi.communicate_with_mah import BotSession

bot = Cesloi(bot_session=BotSession(host="http://localhost:8080", account=1234567890, verify_key="INITKEYWylsVdbr"), debug=False)
bot.install_plugins("test_plugins")
bot.start()

In test_plugins/example_plugin.py :

from arclet.cesloi.bot_client import Cesloi
from arclet.cesloi.model.relation import Friend
from arclet.cesloi.plugin import Bellidin as bd

@bd.model_register("FriendMessage")
async def test(app: Cesloi, friend: Friend):
    await app.send_with(friend, "Hello, World!", nudge=True)

未来开发计划

一期计划

  • CommandAnalysis, 一个抽象的命令/命令参数处理器
  • TimeScheduler, 一个根据时间选择是否执行目标函数的容器
  • PluginManager, 不局限于在一个文件中运行方法

二期计划

  • Interrupt, 中断处理
  • Decorator,用户自定义的处理器

三期计划

  • Commander, 基于Alconna的指令系统
  • 网络层调整
  • 完善文档

鸣谢&相关项目

这些项目也很棒, 去他们的项目页看看, 点个 Star 以鼓励他们的开发工作, 毕竟没有他们也没有 Cesloi.

特别感谢 mamoe 给我们带来这些精彩的项目:

  • mirai: 一个高性能, 高可扩展性的 QQ 协议库
  • mirai-console: 一个基于 mirai 开发的插件式可扩展开发平台
  • mirai-api-http: 为本项目提供与 mirai 交互方式的 mirai-console 插件

GraiaProject 下的项目:

  • Broadcast Control: 本项目关于参数解析与事件循环的的解剖学习对象。
  • Application: 本项目的通用功能的解剖学习与参考对象。
  • Ariadne: 本项目关于网络部分的学习与参考对象。

许可证

GNU AGPLv3 是本项目的开源许可证.

cesloi's People

Contributors

rf-tar-railt avatar sourcery-ai-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

sourcery-ai-bot

cesloi's Issues

Publisher的作用或许要提高一些

Cesloi 的事件系统是用的”发布--订阅“模型

在C#中,事件在类中声明且生成,且通过使用同一个类或其他类中的委托与事件处理程序关联。包含事件的类用于发布事件。这被称为 发布器(publisher) 类。其他接受该事件的类被称为 订阅器(subscriber) 类。事件使用 发布-订阅(publisher-subscriber) 模型。此处的委托(delegate)相当于一类拥有相同参数类型与返回值类型的方法的统称。

发布器(publisher) 是一个包含事件和委托定义的对象。事件和委托之间的联系也定义在这个对象中。发布器(publisher)类的对象调用这个事件,并通知其他的对象。

订阅器(subscriber) 是一个接受事件并提供事件处理程序的对象。在发布器(publisher)类中的委托调用订阅器(subscriber)类中的方法(事件处理程序)。一个事件可以处理多个经过委托注册的订阅器类中的方法。

对应此处的Cesloi的delegatesystem,Publisher类包含订阅器列表 (Subscriber List) 与绑定事件类型 (Bind Event), 而委托则扩大为EventDelegate,用来处理所有的订阅器类中的事件处理程序(Callable Function)。

如果可行,那么是否可以将委托的概念缩小,塞入发布器类中?
通信模块收到来自api的事件消息,根据类型传递给相应发布器中的委托进行数据分析,再由委托将分析好的参数值传递给订阅器中的处理程序

command有问题

当函数不要求获取messageChain时command_handle是收不到事件可能传递的message的
或考虑在将事件参数传递给函数前先经过command_handle

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.