finnaly fixed sticker crashing and moved logic a bit around. also made it learn from other channels again to increase data collection
This commit is contained in:
parent
b3f6534e54
commit
7eba2a4ef6
@ -174,7 +174,7 @@ public class Datahandler {
|
|||||||
return new StanfordCoreNLP(propsSentiment);
|
return new StanfordCoreNLP(propsSentiment);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String trimString(String str) {
|
public String trimString(String str) {
|
||||||
String message = str.trim();
|
String message = str.trim();
|
||||||
if (message.startsWith("<@")) {
|
if (message.startsWith("<@")) {
|
||||||
message = message.substring(message.indexOf("> ") + 2);
|
message = message.substring(message.indexOf("> ") + 2);
|
||||||
@ -202,7 +202,7 @@ public class Datahandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getResponseFutures(String strF, StanfordCoreNLP stanfordCoreNLP, StanfordCoreNLP stanfordCoreNLPSentiment) {
|
public String getResponseFutures(String strF, StanfordCoreNLP stanfordCoreNLP, StanfordCoreNLP stanfordCoreNLPSentiment) {
|
||||||
|
|
||||||
Annotation strAnno = new Annotation(strF);
|
Annotation strAnno = new Annotation(strF);
|
||||||
strAnno.compact();
|
strAnno.compact();
|
||||||
@ -616,6 +616,7 @@ public class Datahandler {
|
|||||||
StanfordCoreNLP stanfordCoreNLPSentiment, Boolean ingameResponse) {
|
StanfordCoreNLP stanfordCoreNLPSentiment, Boolean ingameResponse) {
|
||||||
String responseFutures = "";
|
String responseFutures = "";
|
||||||
String strF = trimString(str);
|
String strF = trimString(str);
|
||||||
|
//System.out.println("post trimstring(). strF: " + strF);
|
||||||
responseFutures = getResponseFutures(strF, stanfordCoreNLP, stanfordCoreNLPSentiment);
|
responseFutures = getResponseFutures(strF, stanfordCoreNLP, stanfordCoreNLPSentiment);
|
||||||
if (!ingameResponse) {
|
if (!ingameResponse) {
|
||||||
responseFutures = checkPersonPresentInSentence(personName, responseFutures, strF, stanfordCoreNLP,
|
responseFutures = checkPersonPresentInSentence(personName, responseFutures, strF, stanfordCoreNLP,
|
||||||
|
@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
package FunctionLayer;
|
|
||||||
|
|
||||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
|
||||||
import discord4j.core.object.entity.User;
|
|
||||||
import discord4j.core.object.entity.channel.TextChannel;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author install1
|
|
||||||
*/
|
|
||||||
public class DoStuff {
|
|
||||||
|
|
||||||
public static void doStuff(MessageCreateEvent event, String usernameBot, Datahandler datahandler,
|
|
||||||
StanfordCoreNLP stanfordCoreNLP, StanfordCoreNLP stanfordCoreNLPSentiment) {
|
|
||||||
String username = "";
|
|
||||||
try {
|
|
||||||
username = event.getMessage().getAuthor().get().getUsername();
|
|
||||||
} catch (java.util.NoSuchElementException e) {
|
|
||||||
username = null;
|
|
||||||
}
|
|
||||||
if (username != null && !username.equals(usernameBot)) {
|
|
||||||
TextChannel block = event.getMessage().getChannel().cast(TextChannel.class).block();
|
|
||||||
String name = block.getCategory().block().getName();
|
|
||||||
name = name.toLowerCase();
|
|
||||||
String channelName = block.getName().toLowerCase();
|
|
||||||
boolean channelpermissionsDenied = false;
|
|
||||||
if (channelName.contains("suggestion-box")) {
|
|
||||||
channelpermissionsDenied = true;
|
|
||||||
}
|
|
||||||
switch (name) {
|
|
||||||
case "public area":
|
|
||||||
case "information area": {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
channelpermissionsDenied = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!channelpermissionsDenied) {
|
|
||||||
List<User> blockLast = event.getMessage().getUserMentions();
|
|
||||||
String content = event.getMessage().getContent();
|
|
||||||
if (blockLast != null) {
|
|
||||||
for (User user : blockLast) {
|
|
||||||
content = content.replace(user.getId().asString(), "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
boolean mentionedBot = false;
|
|
||||||
if (blockLast != null) {
|
|
||||||
for (User user : blockLast) {
|
|
||||||
if (user.getUsername().equals(usernameBot)) {
|
|
||||||
mentionedBot = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mentionedBot || channelName.contains("general-autism")) {
|
|
||||||
String ResponseStr;
|
|
||||||
ResponseStr = datahandler.getResponseMsg(content, username, stanfordCoreNLP, stanfordCoreNLPSentiment,
|
|
||||||
false);
|
|
||||||
if (!ResponseStr.isEmpty()) {
|
|
||||||
System.out.print("\nResponseStr3: " + ResponseStr + "\n");
|
|
||||||
//event.getMessage().getChannel().block().createMessage(ResponseStr).block();
|
|
||||||
event.getMessage().getChannel().flatMap(chan -> chan.createMessage(ResponseStr)).subscribe();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,6 +6,9 @@ import FunctionLayer.PipelineJMWESingleton;
|
|||||||
import discord4j.core.DiscordClient;
|
import discord4j.core.DiscordClient;
|
||||||
import discord4j.core.GatewayDiscordClient;
|
import discord4j.core.GatewayDiscordClient;
|
||||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||||
|
import discord4j.core.object.entity.Sticker;
|
||||||
|
import discord4j.core.object.entity.User;
|
||||||
|
import discord4j.core.object.entity.channel.TextChannel;
|
||||||
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
|
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -13,6 +16,7 @@ import java.io.UnsupportedEncodingException;
|
|||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,7 +108,70 @@ public class DiscordHandler {
|
|||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
gateway.on(MessageCreateEvent.class).subscribe(event -> {
|
gateway.on(MessageCreateEvent.class).subscribe(event -> {
|
||||||
FunctionLayer.DoStuff.doStuff(event, usernameBot, datahandler, stanfordCoreNLP, stanfordCoreNLPSentiment);
|
String username = "";
|
||||||
|
try {
|
||||||
|
username = event.getMessage().getAuthor().get().getUsername();
|
||||||
|
} catch (java.util.NoSuchElementException e) {
|
||||||
|
username = null;
|
||||||
|
}
|
||||||
|
//System.out.println("past event.getMessage().getAuthor().get().getUsername()");
|
||||||
|
List<User> blockLast = event.getMessage().getUserMentions();
|
||||||
|
String content = event.getMessage().getContent();
|
||||||
|
if (blockLast != null) {
|
||||||
|
for (User user : blockLast) {
|
||||||
|
content = content.replace(user.getId().asString(), "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//System.out.println("past event.getMessage().getContent()");
|
||||||
|
|
||||||
|
if (username != null && !username.equals(usernameBot) && !content.isEmpty()) {
|
||||||
|
TextChannel block = event.getMessage().getChannel().cast(TextChannel.class).block();
|
||||||
|
String name = block.getCategory().block().getName();
|
||||||
|
name = name.toLowerCase();
|
||||||
|
String channelName = block.getName().toLowerCase();
|
||||||
|
boolean channelpermissionsDenied = false;
|
||||||
|
if (channelName.contains("suggestion-box")) {
|
||||||
|
channelpermissionsDenied = true;
|
||||||
|
}
|
||||||
|
switch (name) {
|
||||||
|
case "public area":
|
||||||
|
case "information area": {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
channelpermissionsDenied = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!channelpermissionsDenied) {
|
||||||
|
//System.out.println("past !channelpermissionsDenied");
|
||||||
|
boolean mentionedBot = false;
|
||||||
|
if (blockLast != null) {
|
||||||
|
for (User user : blockLast) {
|
||||||
|
if (user.getUsername().equals(usernameBot)) {
|
||||||
|
mentionedBot = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mentionedBot || channelName.contains("general-autism")) {
|
||||||
|
String ResponseStr;
|
||||||
|
ResponseStr = datahandler.getResponseMsg(content, username, stanfordCoreNLP, stanfordCoreNLPSentiment,
|
||||||
|
false);
|
||||||
|
if (!ResponseStr.isEmpty()) {
|
||||||
|
System.out.print("\nResponseStr3: " + ResponseStr + "\n");
|
||||||
|
event.getMessage().getChannel().flatMap(chan -> chan.createMessage(ResponseStr)).block();
|
||||||
|
//event.getMessage().getChannel().block().createMessage(ResponseStr).block();
|
||||||
|
//System.out.print("past event.getMessage().getChannel()");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//System.out.println("pre else statement trimString");
|
||||||
|
String strF = datahandler.trimString(content);
|
||||||
|
//System.out.println("post else statement trimString. strf: " + strF);
|
||||||
|
datahandler.getResponseFutures(strF, stanfordCoreNLP, stanfordCoreNLPSentiment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
gateway.onDisconnect().block();
|
gateway.onDisconnect().block();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user