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

View File

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

View File

@ -17,14 +17,19 @@ package PresentationLayer;
import FunctionLayer.Datahandler;
import FunctionLayer.DoStuff;
import FunctionLayer.PipelineJMWESingleton;
import discord4j.core.DiscordClient;
import discord4j.core.GatewayDiscordClient;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.javacord.api.DiscordApi;
import org.javacord.api.DiscordApiBuilder;
import DataLayer.settings;
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");
Datahandler.instance.addHLstatsMessages();
Datahandler.instance.updateStringCache();
String token = "NTI5NzAxNTk5NjAyMjc4NDAx.Dw0vDg.7-aMjVWdQMYPl8qVNyvTCPS5F_A";
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
//String token = "NTI5NzAxNTk5NjAyMjc4NDAx.Dw0vDg.7-aMjVWdQMYPl8qVNyvTCPS5F_A";
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(() -> {
Datahandler.instance.update_autismo_socket_msg();
}).start();
api.addMessageCreateListener(event -> {
gateway.on(MessageCreateEvent.class).subscribe(event -> {
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
#Sat Feb 02 20:31:02 CET 2019
#Sun Nov 01 17:40:51 CET 2020
version=1.0
groupId=com.mycompany
artifactId=ArtificialAutism