use of ai.api.AIConfiguration 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();
}
}
}
Aggregations