Search in sources :

Example 1 with AIDataService

use of ai.api.AIDataService in project Gary by help-chat.

the class AI method execute.

@Override
protected void execute(MessageReceivedEvent e, String[] args) {
    MessageChannel channel = e.getChannel();
    if (channel.getIdLong() == 339674158596358145L) {
        AIConfiguration config = new AIConfiguration(this.config.getItem("config", "aitoken"));
        AIDataService data = new AIDataService(config);
        try {
            AIRequest request = new AIRequest(e.getMessage().getContentRaw().replace("!", ""));
            request.setSessionId(e.getAuthor().getId());
            AIResponse response = data.request(request);
            if (response.getStatus().getCode() == 200) {
                if (e.getMessage().getContentRaw().startsWith("!say ")) {
                    channel.sendMessage(mutil.format(e, e.getMessage().getContentRaw().replace("!say ", ""))).queue();
                } else {
                    channel.sendMessage(mutil.format(e, response.getResult().getFulfillment().getSpeech())).queue();
                }
            } else {
                System.out.println(response.getStatus().getErrorDetails());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
Also used : AIDataService(ai.api.AIDataService) AIResponse(ai.api.model.AIResponse) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) AIConfiguration(ai.api.AIConfiguration) AIRequest(ai.api.model.AIRequest)

Aggregations

AIConfiguration (ai.api.AIConfiguration)1 AIDataService (ai.api.AIDataService)1 AIRequest (ai.api.model.AIRequest)1 AIResponse (ai.api.model.AIResponse)1 MessageChannel (net.dv8tion.jda.core.entities.MessageChannel)1