Code Monkey home page Code Monkey logo

yutori's Introduction

Yutori

基于 Satori 协议的 Java 机器人开发工具包

jdk-version

快速开始

  1. 创建一个 Maven 项目
  2. 依赖引入
  3. 基本配置
  4. 进阶

依赖引入

Maven

<dependencies>
    <dependency>
        <groupId>io.github.nyayurn</groupId>
        <artifactId>yutori</artifactId>
        <version>0.1.0</version>
    </dependency>
</dependencies>

基本配置

启动类

public class Main {
    private final ListenerContainer listenerContainer = new ListenerContainer();
    private final PropertiesEntity properties = new PropertiesEntity("127.0.0.1:5500", "token");

    public Main() {
        // new 一个对象以触发监听器的注册
        new TestListener(listenerContainer, properties);
    }

    private void run() {
        try {
            // 新建一个 WebSocket 连接
            new MyWebSocketClient(properties.getAddress(), properties.getToken(), listenerContainer).connect();
        } catch (URISyntaxException e) {
            log.error(e.getLocalizedMessage());
        }
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

第一个监听器

public class TestListener {
    private final PropertiesEntity properties;

    public TestListener(ListenerContainer listenerContainer, PropertiesEntity properties) {
        this.properties = properties;
        // 通过在构造器内对 listenerContainer 添加一个事件实现注册
        listenerContainer.addOnEventListener(event -> {
            // 判断事件的类型是否为 message-created(新消息创建, 即接收到消息)
            if (event.getType().equals(MessageEvents.MESSAGE_CREATED)) {
                this.onMessage(event);
            }
        });
    }

    public void onMessage(EventEntity event) {
        if ("test".equals(event.getMessage().getContent())) {
            ChannelEntity channel = event.getChannel();
            // 通过对应 API 类的方法发送消息
            MessageApi messageApi = new MessageApi(event.getPlatform(), event.getSelfId(), properties);
            messageApi.createMessage((channel.getType().equals(ChannelEntity.DIRECT) ? "private:" : "") + channel.getId(),
                    "test done!");
        }
    }
}

进阶

  • 框架整体与 Satori 架构基本一致, 请参考 Satori 文档
  • 源码内有 javadoc 方便阅读, 请自行阅读源码
API 描述
ChannelApi 频道相关的 API
GuildApi 群组相关的 API
GuildMemberApi 群组成员相关的 API
GuildRoleApi 群组角色相关的 API
LoginApi 登录信息相关的 API
MessageApi 消息相关的 API
ReactionApi 表态相关的 API
UserApi 用户相关的 API
MessageElement 描述
AtElement AT
HrefElement 超链接
SharpElement 提及频道
TextElement 纯文本
BoldElement
StrongElement
粗体
DeleteElement
StrikethroughElement
删除线
EmElement
ItalicElement
斜线
InsElement
UnderlineElement
下划线
CodeElement 代码片段
SplElement 剧透
SubElement 下标
SupElement 上标
AuthorElement 作者
QuoteElement 引用
AudioElement 语音
FileElement 文件
ImgElement 图片
VideoElement 视频
BrElement 换行
MessageElement 消息
ParagraphElement 段落

迁移

如果你想从 0.0.9 之前的版本迁移到 0.0.9, 请删除所有的 import, 并重新导入

其他

Yutori: 作者名称 Yurn 与 Satori 协议名称的结合而来

yutori's People

Contributors

nyayurn avatar

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.