Coder Social home page Coder Social logo

satori.net's Introduction

Satori.NET

Satori 协议 .NET SDK

Satori Protocol Version .NET Version

包名 版本 描述
Satori.Protocol Version 协议核心部分,包含消息元素、事件、模型定义;支持对 消息元素 的序列化与反序列化
Satori.Client Version 对接 Satori 协议的客户端

消息元素

Satori 使用消息元素来表示一个消息的内容,形式类似于 HTML。例如:

<!-- 提及 (@) 用户 -->
<at id="1a2b3c4d5e6f"/>

<!-- 引用(回复)消息 -->
<quote id="1f1e33">
    <!-- 提及某个频道 -->
    <sharp id="channel_id"/>
    Hello Satori!
</quote>

Satori.NET 支持使用 ElementSerializer 类对消息元素进行序列化与反序列化。

序列化

将一个 Element 对象序列化为字符串:

var element = new ImageElement
{
    Src = "https://example.com/img.jpg",
    Width = 114514,
    Height = 1919810
};

// <img width="114514" height="1919810" src="https://example.com/img.jpg" />
var text = ElementSerializer.Serialize(element);

支持一个 Element 数组:

var element1 = new AuthorElement { UserId = "satori" };
var element2 = new SharpElement { Id = "satori-channel" };
var element3 = new TextElement { Text = "text" };

// <author user-id="satori" /><sharp id="satori-channel" />text
var text = ElementSerializer.Serialize(new Element[] { element1, element2, element3 });

反序列化

将一个字符串反序列化为 Element[]:

var text = "<a href=\"https://example.com\">Test</a>";
var elements = ElementSerializer.Deserialize(text);

// elements[0]: LinkElement
// elements[0].ChildElements[0]: TextElement

示例

Satori.Client.Example

备注

本 SDK 目前虽然基本完成,仍可能遇到些许小问题,如果遇到可以发布 Issue

欢迎 PR!

开源

MIT License

satori.net's People

Contributors

bsdayo avatar

Stargazers

 avatar 深淵の鴿子 avatar  avatar momo avatar LazuliKao avatar  avatar DreamPrism avatar Shigma avatar  avatar Il Harper avatar  avatar Linwenxuan avatar  avatar

Watchers

 avatar

satori.net's Issues

关于示例代码的问题

bot.MessageCreated += async (_, e) =>
{
    Console.WriteLine($"Received message from {e.Channel!.Id}: {e.Message!.Content}");
    await bot.CreateMessageAsync(e.Channel.Id,
        new TextElement { Text = "非常好 Satori,爱来自 Satori.Client" });
};

MessageCreated事件触发后,又CreateMessageAsync,会造成无限调用。
建议:

bot.MessageCreated += async (_, e) =>
{
    if (e.User!.Id == selfId) return;
    Console.WriteLine($"Received message from {e.Channel!.Id}: {e.Message!.Content}");
    await bot.CreateMessageAsync(e.Channel.Id,
        new TextElement { Text = "非常好 Satori,爱来自 Satori.Client" });
};

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.