All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.blankcat.demo.HelloWordMessageHandler Maven / Gradle / Ivy

There is a newer version: 2.1.3
Show newest version
package cn.blankcat.demo;

import cn.blankcat.dto.message.Message;
import cn.blankcat.dto.message.MessageToCreate;
import cn.blankcat.openapi.MessageService;
import cn.blankcat.openapi.OpenapiService;
import cn.blankcat.websocket.WebsocketService;
import cn.blankcat.websocket.handler.WebsocketHandler;

import java.io.IOException;

public class HelloWordMessageHandler implements WebsocketHandler {

    @Override
    public void handle(String message) {
        Message guildMessage = toType(message, Message.class);
        if (guildMessage.getContent().contains("@")){
            OpenapiService openapiService = new OpenapiService();
            MessageToCreate messageToCreate = new MessageToCreate();
            messageToCreate.setContent("hello world");
            messageToCreate.setMsgID(guildMessage.getId());
            try {
                openapiService.create(MessageService.class).postChannelMessages(guildMessage.getChannelId(), messageToCreate).execute().body();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        WebsocketService websocketService = new WebsocketService();
        new HelloWordMessageHandler().register(Message.class);
        websocketService.connect();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy