further fixes should be good now

This commit is contained in:
jenzuffer 2020-11-01 17:51:29 +01:00
parent 7977e87608
commit 651aa309bc
13 changed files with 66 additions and 32 deletions

View File

@ -225,7 +225,7 @@ public class Datahandler {
hlStatsMessages.put(str, hlStatsMessages.size()); hlStatsMessages.put(str, hlStatsMessages.size());
} }
} }
int capacity = 50; int capacity = 150;
hlStatsMessages.keySet().forEach(str -> { hlStatsMessages.keySet().forEach(str -> {
if (!str.startsWith("!") && MessageResponseHandler.getStr().values().size() < capacity) { if (!str.startsWith("!") && MessageResponseHandler.getStr().values().size() < capacity) {
String orElse = strCacheLocal.values().parallelStream().filter(e -> e.equals(str)).findAny().orElse(null); String orElse = strCacheLocal.values().parallelStream().filter(e -> e.equals(str)).findAny().orElse(null);
@ -641,12 +641,15 @@ public class Datahandler {
if (str1.contains("AM*")) { if (str1.contains("AM*")) {
str1 = str1.substring(str1.indexOf("AM*") + 3); str1 = str1.substring(str1.indexOf("AM*") + 3);
} }
for (Character c : str1.toCharArray()) { if (str1.contains("?") || str1.contains("°"))
if (c == '?' || c == '°') { {
if (!str1.contains("http"))
{
str1 = str1.replace("?", " <:wlenny:514861023002624001> "); str1 = str1.replace("?", " <:wlenny:514861023002624001> ");
str1 = str1.replace("°", " <:wlenny:514861023002624001> "); str1 = str1.replace("°", " <:wlenny:514861023002624001> ");
} }
} }
if (str1.contains("(Counter-Terrorist)")) { if (str1.contains("(Counter-Terrorist)")) {
str1 = str1.replace("(Counter-Terrorist)", " "); str1 = str1.replace("(Counter-Terrorist)", " ");
} }

View File

@ -6,13 +6,17 @@
package FunctionLayer; package FunctionLayer;
import PresentationLayer.DiscordHandler; import PresentationLayer.DiscordHandler;
import discord4j.core.event.domain.message.MessageCreateEvent;
import discord4j.core.object.entity.User;
import discord4j.core.object.entity.channel.TextChannel;
import java.math.BigInteger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.javacord.api.DiscordApi; import reactor.core.publisher.Flux;
import org.javacord.api.entity.user.User; import reactor.core.publisher.Mono;
import org.javacord.api.event.message.MessageCreateEvent;
/** /**
* *
@ -26,17 +30,25 @@ public class DoStuff {
return occupied; return occupied;
} }
public static void doStuff(MessageCreateEvent event, DiscordApi api) { public static void doStuff(MessageCreateEvent event, String usernameBot) {
if (!event.getMessage().getAuthor().isYourself()) { String username = null;
try {
username = event.getMessage().getAuthor().get().getUsername();
} catch (java.util.NoSuchElementException e) {
username = null;
}
if (username != null && !username.equals(usernameBot)) {
occupied = true; occupied = true;
String strtest = event.getServerTextChannel().get().getCategory().toString(); TextChannel block = event.getMessage().getChannel().cast(TextChannel.class).block();
strtest = strtest.substring(9, strtest.length() - 1); String name = block.getCategory().block().getName();
name = name.toLowerCase();
String channelName = block.getName().toLowerCase();
boolean channelpermissionsDenied = false; boolean channelpermissionsDenied = false;
switch (strtest) { switch (name) {
case "Public Area": { case "public area": {
break; break;
} }
case "Information Area": { case "information area": {
break; break;
} }
default: { default: {
@ -44,25 +56,35 @@ public class DoStuff {
break; break;
} }
} }
if (!channelpermissionsDenied) { List<User> blockLast = event.getMessage().getUserMentions().buffer().blockLast();
List<User> userlist = event.getMessage().getMentionedUsers(); if (!channelpermissionsDenied && blockLast != null) {
String strresult = event.getMessage().toString(); String content = event.getMessage().getContent();
if (userlist != null) { if (blockLast != null) {
for (User user : userlist) { for (User user : blockLast) {
strresult = strresult.replace(user.getIdAsString(), ""); content = content.replace(user.getId().asString(), "");
} }
} }
MessageResponseHandler.getMessage(strresult); MessageResponseHandler.getMessage(content);
} }
if (event.getMessage().getMentionedUsers().contains(api.getYourself()) boolean mentionedBot = false;
|| event.getServerTextChannel().get().toString().contains("general-autism")) { if (blockLast != null){
for (User user : blockLast)
{
if (user.getUsername().equals(usernameBot))
{
mentionedBot = true;
break;
}
}
}
if (mentionedBot || channelName.contains("general-autism")) {
try { try {
String ResponseStr; String ResponseStr;
String person = event.getMessageAuthor().getName(); String content = event.getMessage().getContent();
ResponseStr = MessageResponseHandler.selectReponseMessage(event.getMessage().toString(), person); ResponseStr = MessageResponseHandler.selectReponseMessage(content, username);
if (!ResponseStr.isEmpty()) { if (!ResponseStr.isEmpty()) {
System.out.print("\nResponseStr3: " + ResponseStr + "\n"); System.out.print("\nResponseStr3: " + ResponseStr + "\n");
event.getChannel().sendMessage(ResponseStr); event.getMessage().getChannel().block().createMessage(ResponseStr).block();
} }
} catch (CustomError ex) { } catch (CustomError ex) {
Logger.getLogger(DoStuff.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(DoStuff.class.getName()).log(Level.SEVERE, null, ex);

View File

@ -17,14 +17,19 @@ package PresentationLayer;
import FunctionLayer.Datahandler; import FunctionLayer.Datahandler;
import FunctionLayer.DoStuff; import FunctionLayer.DoStuff;
import FunctionLayer.PipelineJMWESingleton; import FunctionLayer.PipelineJMWESingleton;
import discord4j.core.DiscordClient;
import discord4j.core.GatewayDiscordClient;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.javacord.api.DiscordApi; import DataLayer.settings;
import org.javacord.api.DiscordApiBuilder; import discord4j.common.util.Snowflake;
import discord4j.core.event.domain.message.MessageCreateEvent;
import java.math.BigInteger;
/** /**
* *
@ -48,15 +53,19 @@ public class DiscordHandler {
System.out.println("FINISHED ALL ANNOTATIONS"); System.out.println("FINISHED ALL ANNOTATIONS");
Datahandler.instance.addHLstatsMessages(); Datahandler.instance.addHLstatsMessages();
Datahandler.instance.updateStringCache(); Datahandler.instance.updateStringCache();
String token = "NTI5NzAxNTk5NjAyMjc4NDAx.Dw0vDg.7-aMjVWdQMYPl8qVNyvTCPS5F_A"; //String token = "NTI5NzAxNTk5NjAyMjc4NDAx.Dw0vDg.7-aMjVWdQMYPl8qVNyvTCPS5F_A";
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join(); String token = new settings().getDiscordToken();
final DiscordClient client = DiscordClient.create(token);
final GatewayDiscordClient gateway = client.login().block();
String usernameBot = gateway.getSelf().block().getUsername();
new Thread(() -> { new Thread(() -> {
Datahandler.instance.update_autismo_socket_msg(); Datahandler.instance.update_autismo_socket_msg();
}).start(); }).start();
api.addMessageCreateListener(event -> { gateway.on(MessageCreateEvent.class).subscribe(event -> {
if (!FunctionLayer.DoStuff.isOccupied()) { if (!FunctionLayer.DoStuff.isOccupied()) {
FunctionLayer.DoStuff.doStuff(event, api); FunctionLayer.DoStuff.doStuff(event, usernameBot);
} }
}); });
gateway.onDisconnect().block();
} }
} }

View File

@ -1,5 +1,5 @@
#Generated by Maven #Generated by Maven
#Sat Feb 02 20:31:02 CET 2019 #Sun Nov 01 17:40:51 CET 2020
version=1.0 version=1.0
groupId=com.mycompany groupId=com.mycompany
artifactId=ArtificialAutism artifactId=ArtificialAutism