Git Product home page Git Product logo

Comments (5)

st1020 avatar st1020 commented on June 13, 2024

这里的文档不是这个意思,内置消息类是一个抽象基类(abstract base class),文档中的代码只是一个例子,这里的文档不是很清晰,我之后改一下。

还有确实不支持文本中内嵌CQ码,因为AliceBot对此进行了封装,通过消息和消息段来实现富文本。

这里是使用CQHTTP适配器的发送富文本的例子:

from alicebot.plugin import Plugin
from alicebot.adapter.cqhttp.event import MessageEvent
from alicebot.adapter.cqhttp.message import CQHTTPMessage, CQHTTPMessageSegment


class Test(Plugin[MessageEvent, None]):  # 这里的泛型参数参考插件进阶篇的插件类的泛型支持
    async def handle(self) -> None:
        msg = CQHTTPMessage()
        for i in ["a", "b", "c"]:
            msg += CQHTTPMessageSegment.text(i)
            msg += CQHTTPMessageSegment.image("file:///path/temp.png")
        await self.event.reply(msg)

    async def rule(self) -> bool:
        if self.event.adapter.name != "cqhttp":
            return False
        if self.event.type != "message":
            return False
        return True

from alicebot.

Adsicmes avatar Adsicmes commented on June 13, 2024

那么那个MessageSegment类实际上有什么用途呢

from alicebot.

Adsicmes avatar Adsicmes commented on June 13, 2024

作为抽象类给其他具体的消息段类进行继承吗

from alicebot.

st1020 avatar st1020 commented on June 13, 2024

是的,它是提供给适配器开发者继承用的基类,不应该直接实例化,应该使用适配器提供的Message和MessageSegment

from alicebot.

Adsicmes avatar Adsicmes commented on June 13, 2024

好的,了解

from alicebot.

Related Issues (20)

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.