Added timings and a line that solves everything
cb.setStoreService(new JdkStoreService());
This commit is contained in:
parent
bf538d9bd0
commit
545b8130e0
7 changed files with 58 additions and 39 deletions
2
pom.xml
2
pom.xml
|
@ -187,7 +187,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.discord4j</groupId>
|
<groupId>com.discord4j</groupId>
|
||||||
<artifactId>discord4j-core</artifactId>
|
<artifactId>discord4j-core</artifactId>
|
||||||
<version>3.0.5</version>
|
<version>3.0.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14 -->
|
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -12,6 +12,7 @@ import buttondevteam.discordplugin.mcchat.MCChatUtils;
|
||||||
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
|
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
|
||||||
import buttondevteam.discordplugin.mccommands.DiscordMCCommand;
|
import buttondevteam.discordplugin.mccommands.DiscordMCCommand;
|
||||||
import buttondevteam.discordplugin.role.GameRoleModule;
|
import buttondevteam.discordplugin.role.GameRoleModule;
|
||||||
|
import buttondevteam.discordplugin.util.Timings;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import buttondevteam.lib.architecture.ButtonPlugin;
|
import buttondevteam.lib.architecture.ButtonPlugin;
|
||||||
import buttondevteam.lib.architecture.Component;
|
import buttondevteam.lib.architecture.Component;
|
||||||
|
@ -29,6 +30,7 @@ import discord4j.core.object.presence.Activity;
|
||||||
import discord4j.core.object.presence.Presence;
|
import discord4j.core.object.presence.Presence;
|
||||||
import discord4j.core.object.reaction.ReactionEmoji;
|
import discord4j.core.object.reaction.ReactionEmoji;
|
||||||
import discord4j.core.object.util.Snowflake;
|
import discord4j.core.object.util.Snowflake;
|
||||||
|
import discord4j.store.jdk.JdkStoreService;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
@ -108,6 +110,7 @@ public class DiscordPlugin extends ButtonPlugin {
|
||||||
}
|
}
|
||||||
val cb = new DiscordClientBuilder(token);
|
val cb = new DiscordClientBuilder(token);
|
||||||
cb.setInitialPresence(Presence.doNotDisturb(Activity.playing("booting")));
|
cb.setInitialPresence(Presence.doNotDisturb(Activity.playing("booting")));
|
||||||
|
cb.setStoreService(new JdkStoreService()); //The default doesn't work for some reason - it's waaay faster now
|
||||||
dc = cb.build();
|
dc = cb.build();
|
||||||
dc.getEventDispatcher().on(ReadyEvent.class) // Listen for ReadyEvent(s)
|
dc.getEventDispatcher().on(ReadyEvent.class) // Listen for ReadyEvent(s)
|
||||||
.map(event -> event.getGuilds().size()) // Get how many guilds the bot is in
|
.map(event -> event.getGuilds().size()) // Get how many guilds the bot is in
|
||||||
|
@ -138,11 +141,6 @@ public class DiscordPlugin extends ButtonPlugin {
|
||||||
getLogger().warning("Main server set to first one: " + mainServer.getName());
|
getLogger().warning("Main server set to first one: " + mainServer.getName());
|
||||||
mainServer().set(mainServer); //Save in config
|
mainServer().set(mainServer); //Save in config
|
||||||
}
|
}
|
||||||
if (!TBMCCoreAPI.IsTestServer()) { //Don't change conditions here, see mainServer=devServer=null in onDisable()
|
|
||||||
dc.updatePresence(Presence.online(Activity.playing("Minecraft"))).subscribe();
|
|
||||||
} else {
|
|
||||||
dc.updatePresence(Presence.online(Activity.playing("testing"))).subscribe();
|
|
||||||
}
|
|
||||||
SafeMode = false;
|
SafeMode = false;
|
||||||
DPUtils.disableIfConfigError(null, commandChannel(), modRole()); //Won't disable, just prints the warning here
|
DPUtils.disableIfConfigError(null, commandChannel(), modRole()); //Won't disable, just prints the warning here
|
||||||
|
|
||||||
|
@ -196,6 +194,11 @@ public class DiscordPlugin extends ButtonPlugin {
|
||||||
setupProviders();
|
setupProviders();
|
||||||
|
|
||||||
IHaveConfig.pregenConfig(this, null);
|
IHaveConfig.pregenConfig(this, null);
|
||||||
|
if (!TBMCCoreAPI.IsTestServer()) {
|
||||||
|
dc.updatePresence(Presence.online(Activity.playing("Minecraft"))).subscribe();
|
||||||
|
} else {
|
||||||
|
dc.updatePresence(Presence.online(Activity.playing("testing"))).subscribe();
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TBMCCoreAPI.SendException("An error occurred while enabling DiscordPlugin!", e);
|
TBMCCoreAPI.SendException("An error occurred while enabling DiscordPlugin!", e);
|
||||||
}
|
}
|
||||||
|
@ -209,9 +212,10 @@ public class DiscordPlugin extends ButtonPlugin {
|
||||||
@Override
|
@Override
|
||||||
public void pluginPreDisable() {
|
public void pluginPreDisable() {
|
||||||
if (ChromaBot.getInstance() == null) return; //Failed to load
|
if (ChromaBot.getInstance() == null) return; //Failed to load
|
||||||
System.out.println("Disable start");
|
Timings timings = new Timings();
|
||||||
|
timings.printElapsed("Disable start");
|
||||||
MCChatUtils.forCustomAndAllMCChat(chan -> chan.flatMap(ch -> ch.createEmbed(ecs -> {
|
MCChatUtils.forCustomAndAllMCChat(chan -> chan.flatMap(ch -> ch.createEmbed(ecs -> {
|
||||||
System.out.println("Sending message to " + ch.getMention());
|
timings.printElapsed("Sending message to " + ch.getMention());
|
||||||
if (DiscordMCCommand.resetting)
|
if (DiscordMCCommand.resetting)
|
||||||
ecs.setColor(Color.ORANGE).setTitle("Discord plugin restarting");
|
ecs.setColor(Color.ORANGE).setTitle("Discord plugin restarting");
|
||||||
else
|
else
|
||||||
|
@ -226,16 +230,17 @@ public class DiscordPlugin extends ButtonPlugin {
|
||||||
+ "kicked the hell out.") //TODO: Make configurable
|
+ "kicked the hell out.") //TODO: Make configurable
|
||||||
: ""); //If 'restart' is disabled then this isn't shown even if joinleave is enabled
|
: ""); //If 'restart' is disabled then this isn't shown even if joinleave is enabled
|
||||||
})).subscribe(), ChannelconBroadcast.RESTART, false);
|
})).subscribe(), ChannelconBroadcast.RESTART, false);
|
||||||
System.out.println("Updating player list");
|
timings.printElapsed("Updating player list");
|
||||||
ChromaBot.getInstance().updatePlayerList();
|
ChromaBot.getInstance().updatePlayerList();
|
||||||
System.out.println("Done");
|
timings.printElapsed("Done");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pluginDisable() {
|
public void pluginDisable() {
|
||||||
System.out.println("Actual disable start (logout)");
|
Timings timings = new Timings();
|
||||||
|
timings.printElapsed("Actual disable start (logout)");
|
||||||
MCChatPrivate.logoutAll();
|
MCChatPrivate.logoutAll();
|
||||||
System.out.println("Config setup");
|
timings.printElapsed("Config setup");
|
||||||
getConfig().set("serverup", false);
|
getConfig().set("serverup", false);
|
||||||
if (ChromaBot.getInstance() == null) return; //Failed to load
|
if (ChromaBot.getInstance() == null) return; //Failed to load
|
||||||
|
|
||||||
|
@ -243,9 +248,9 @@ public class DiscordPlugin extends ButtonPlugin {
|
||||||
try {
|
try {
|
||||||
SafeMode = true; // Stop interacting with Discord
|
SafeMode = true; // Stop interacting with Discord
|
||||||
ChromaBot.delete();
|
ChromaBot.delete();
|
||||||
System.out.println("Updating presence...");
|
timings.printElapsed("Updating presence...");
|
||||||
dc.updatePresence(Presence.idle(Activity.playing("Chromacraft"))).block(); //No longer using the same account for testing
|
dc.updatePresence(Presence.idle(Activity.playing("Chromacraft"))).block(); //No longer using the same account for testing
|
||||||
System.out.println("Logging out...");
|
timings.printElapsed("Logging out...");
|
||||||
dc.logout().block();
|
dc.logout().block();
|
||||||
//Configs are emptied so channels and servers are fetched again
|
//Configs are emptied so channels and servers are fetched again
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package buttondevteam.discordplugin.listeners;
|
||||||
import buttondevteam.discordplugin.DPUtils;
|
import buttondevteam.discordplugin.DPUtils;
|
||||||
import buttondevteam.discordplugin.DiscordPlugin;
|
import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
import buttondevteam.discordplugin.commands.Command2DCSender;
|
import buttondevteam.discordplugin.commands.Command2DCSender;
|
||||||
|
import buttondevteam.discordplugin.util.Timings;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import discord4j.core.object.entity.Message;
|
import discord4j.core.object.entity.Message;
|
||||||
import discord4j.core.object.entity.MessageChannel;
|
import discord4j.core.object.entity.MessageChannel;
|
||||||
|
@ -22,44 +23,44 @@ public class CommandListener {
|
||||||
* @return Whether it <b>did not run</b> the command
|
* @return Whether it <b>did not run</b> the command
|
||||||
*/
|
*/
|
||||||
public static Mono<Boolean> runCommand(Message message, MessageChannel commandChannel, boolean mentionedonly) {
|
public static Mono<Boolean> runCommand(Message message, MessageChannel commandChannel, boolean mentionedonly) {
|
||||||
|
Timings timings = CommonListeners.timings;
|
||||||
Mono<Boolean> ret = Mono.just(true);
|
Mono<Boolean> ret = Mono.just(true);
|
||||||
if (!message.getContent().isPresent())
|
if (!message.getContent().isPresent())
|
||||||
return ret; //Pin messages and such, let the mcchat listener deal with it
|
return ret; //Pin messages and such, let the mcchat listener deal with it
|
||||||
val content = message.getContent().get();
|
val content = message.getContent().get();
|
||||||
System.out.println("A");
|
timings.printElapsed("A");
|
||||||
return message.getChannel().flatMap(channel -> {
|
return message.getChannel().flatMap(channel -> {
|
||||||
Mono<?> tmp = ret;
|
Mono<?> tmp = ret;
|
||||||
if (!mentionedonly) { //mentionedonly conditions are in CommonListeners
|
if (!mentionedonly) { //mentionedonly conditions are in CommonListeners
|
||||||
System.out.println("B");
|
timings.printElapsed("B");
|
||||||
//System.out.println("Channel type: " + commandChannel.getClass().getSimpleName());
|
|
||||||
//System.out.println("Guild: " + ((TextChannel) commandChannel).getGuildId());
|
|
||||||
if (!(channel instanceof PrivateChannel)
|
if (!(channel instanceof PrivateChannel)
|
||||||
&& !(content.charAt(0) == DiscordPlugin.getPrefix()
|
&& !(content.charAt(0) == DiscordPlugin.getPrefix()
|
||||||
&& channel.getId().asLong() == commandChannel.getId().asLong())) //
|
&& channel.getId().asLong() == commandChannel.getId().asLong())) //
|
||||||
return ret;
|
return ret;
|
||||||
System.out.println("C");
|
timings.printElapsed("C");
|
||||||
tmp = ret.then(channel.type()).thenReturn(true); // Fun (this true is ignored - x)
|
tmp = ret.then(channel.type()).thenReturn(true); // Fun (this true is ignored - x)
|
||||||
}
|
}
|
||||||
final StringBuilder cmdwithargs = new StringBuilder(content);
|
final StringBuilder cmdwithargs = new StringBuilder(content);
|
||||||
val gotmention = new AtomicBoolean();
|
val gotmention = new AtomicBoolean();
|
||||||
|
timings.printElapsed("Before self");
|
||||||
return tmp.flatMapMany(x ->
|
return tmp.flatMapMany(x ->
|
||||||
DiscordPlugin.dc.getSelf().flatMap(self -> self.asMember(DiscordPlugin.mainServer.getId()))
|
DiscordPlugin.dc.getSelf().flatMap(self -> self.asMember(DiscordPlugin.mainServer.getId()))
|
||||||
.flatMapMany(self -> {
|
.flatMapMany(self -> {
|
||||||
System.out.println("D");
|
timings.printElapsed("D");
|
||||||
gotmention.set(checkanddeletemention(cmdwithargs, self.getMention(), message));
|
gotmention.set(checkanddeletemention(cmdwithargs, self.getMention(), message));
|
||||||
gotmention.set(checkanddeletemention(cmdwithargs, self.getNicknameMention(), message) || gotmention.get());
|
gotmention.set(checkanddeletemention(cmdwithargs, self.getNicknameMention(), message) || gotmention.get());
|
||||||
val mentions = message.getRoleMentions();
|
val mentions = message.getRoleMentions();
|
||||||
return self.getRoles().filterWhen(r -> mentions.any(rr -> rr.getName().equals(r.getName())))
|
return self.getRoles().filterWhen(r -> mentions.any(rr -> rr.getName().equals(r.getName())))
|
||||||
.map(Role::getMention);
|
.map(Role::getMention);
|
||||||
}).map(mentionRole -> {
|
}).map(mentionRole -> {
|
||||||
System.out.println("E");
|
timings.printElapsed("E");
|
||||||
gotmention.set(checkanddeletemention(cmdwithargs, mentionRole, message) || gotmention.get()); // Delete all mentions
|
gotmention.set(checkanddeletemention(cmdwithargs, mentionRole, message) || gotmention.get()); // Delete all mentions
|
||||||
return !mentionedonly || gotmention.get(); //Stops here if false
|
return !mentionedonly || gotmention.get(); //Stops here if false
|
||||||
}).switchIfEmpty(Mono.fromSupplier(() -> !mentionedonly || gotmention.get())))
|
}).switchIfEmpty(Mono.fromSupplier(() -> !mentionedonly || gotmention.get())))
|
||||||
.filter(b -> b).last(false).filter(b -> b).doOnNext(b -> channel.type().subscribe()).flatMap(b -> {
|
.filter(b -> b).last(false).filter(b -> b).doOnNext(b -> channel.type().subscribe()).flatMap(b -> {
|
||||||
String cmdwithargsString = cmdwithargs.toString();
|
String cmdwithargsString = cmdwithargs.toString();
|
||||||
try {
|
try {
|
||||||
System.out.println("F");
|
timings.printElapsed("F");
|
||||||
if (!DiscordPlugin.plugin.getManager().handleCommand(new Command2DCSender(message), cmdwithargsString))
|
if (!DiscordPlugin.plugin.getManager().handleCommand(new Command2DCSender(message), cmdwithargsString))
|
||||||
return DPUtils.reply(message, channel, "Unknown command. Do " + DiscordPlugin.getPrefix() + "help for help.\n" + cmdwithargsString);
|
return DPUtils.reply(message, channel, "Unknown command. Do " + DiscordPlugin.getPrefix() + "help for help.\n" + cmdwithargsString);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
import buttondevteam.discordplugin.fun.FunModule;
|
import buttondevteam.discordplugin.fun.FunModule;
|
||||||
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
|
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
|
||||||
import buttondevteam.discordplugin.role.GameRoleModule;
|
import buttondevteam.discordplugin.role.GameRoleModule;
|
||||||
|
import buttondevteam.discordplugin.util.Timings;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import buttondevteam.lib.architecture.Component;
|
import buttondevteam.lib.architecture.Component;
|
||||||
import discord4j.core.event.EventDispatcher;
|
import discord4j.core.event.EventDispatcher;
|
||||||
|
@ -19,6 +20,8 @@ import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
public class CommonListeners {
|
public class CommonListeners {
|
||||||
|
|
||||||
|
public static final Timings timings = new Timings();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MentionEvent:
|
MentionEvent:
|
||||||
- CommandListener (starts with mention, only 'channelcon' and not in #bot)
|
- CommandListener (starts with mention, only 'channelcon' and not in #bot)
|
||||||
|
@ -30,14 +33,13 @@ public class CommonListeners {
|
||||||
*/
|
*/
|
||||||
public static void register(EventDispatcher dispatcher) {
|
public static void register(EventDispatcher dispatcher) {
|
||||||
dispatcher.on(MessageCreateEvent.class).flatMap(event -> {
|
dispatcher.on(MessageCreateEvent.class).flatMap(event -> {
|
||||||
|
timings.printElapsed("Message received");
|
||||||
val def = Mono.empty();
|
val def = Mono.empty();
|
||||||
if (DiscordPlugin.SafeMode)
|
if (DiscordPlugin.SafeMode)
|
||||||
return def;
|
return def;
|
||||||
val author = event.getMessage().getAuthor();
|
val author = event.getMessage().getAuthor();
|
||||||
if (!author.isPresent() || author.get().isBot())
|
if (!author.isPresent() || author.get().isBot())
|
||||||
return def;
|
return def;
|
||||||
//System.out.println("Author: "+author.get());
|
|
||||||
//System.out.println("Bot: "+author.get().isBot());
|
|
||||||
if (FunModule.executeMemes(event.getMessage()))
|
if (FunModule.executeMemes(event.getMessage()))
|
||||||
return def;
|
return def;
|
||||||
val commandChannel = DiscordPlugin.plugin.commandChannel().get();
|
val commandChannel = DiscordPlugin.plugin.commandChannel().get();
|
||||||
|
@ -47,25 +49,20 @@ public class CommonListeners {
|
||||||
|| mch instanceof PrivateChannel
|
|| mch instanceof PrivateChannel
|
||||||
|| event.getMessage().getContent().orElse("").contains("channelcon"))) //Only 'channelcon' is allowed in other channels
|
|| event.getMessage().getContent().orElse("").contains("channelcon"))) //Only 'channelcon' is allowed in other channels
|
||||||
.filterWhen(ch -> { //Only continue if this doesn't handle the event
|
.filterWhen(ch -> { //Only continue if this doesn't handle the event
|
||||||
System.out.println("Run command 1");
|
timings.printElapsed("Run command 1");
|
||||||
return CommandListener.runCommand(event.getMessage(), ch, true); //#bot is handled here
|
return CommandListener.runCommand(event.getMessage(), ch, true); //#bot is handled here
|
||||||
}).filterWhen(ch -> {
|
}).filterWhen(ch -> {
|
||||||
System.out.println("mcchat");
|
timings.printElapsed("mcchat");
|
||||||
val mcchat = Component.getComponents().get(MinecraftChatModule.class);
|
val mcchat = Component.getComponents().get(MinecraftChatModule.class);
|
||||||
if (mcchat != null && mcchat.isEnabled()) //ComponentManager.isEnabled() searches the component again
|
if (mcchat != null && mcchat.isEnabled()) //ComponentManager.isEnabled() searches the component again
|
||||||
return ((MinecraftChatModule) mcchat).getListener().handleDiscord(event); //Also runs Discord commands in chat channels
|
return ((MinecraftChatModule) mcchat).getListener().handleDiscord(event); //Also runs Discord commands in chat channels
|
||||||
return Mono.empty(); //Wasn't handled, continue
|
return Mono.empty(); //Wasn't handled, continue
|
||||||
}).filterWhen(ch -> {
|
}).filterWhen(ch -> {
|
||||||
System.out.println("Run command 2");
|
timings.printElapsed("Run command 2");
|
||||||
return CommandListener.runCommand(event.getMessage(), ch, false);
|
return CommandListener.runCommand(event.getMessage(), ch, false);
|
||||||
});
|
});
|
||||||
}).onErrorContinue((err, obj) -> TBMCCoreAPI.SendException("An error occured while handling a message!", err))
|
}).onErrorContinue((err, obj) -> TBMCCoreAPI.SendException("An error occured while handling a message!", err))
|
||||||
.subscribe();
|
.subscribe();
|
||||||
/*dispatcher.on(MessageCreateEvent.class).doOnNext(x -> System.out.println("Got message"))
|
|
||||||
.flatMap(MessageCreateEvent::getGuild)
|
|
||||||
.flatMap(guild -> DiscordPlugin.dc.getSelf())
|
|
||||||
.flatMap(self -> self.asMember(DiscordPlugin.mainServer.getId()))
|
|
||||||
.flatMap(Member::getRoles).subscribe(roles -> System.out.println("Roles: " + roles));*/
|
|
||||||
dispatcher.on(PresenceUpdateEvent.class).subscribe(event -> {
|
dispatcher.on(PresenceUpdateEvent.class).subscribe(event -> {
|
||||||
if (DiscordPlugin.SafeMode)
|
if (DiscordPlugin.SafeMode)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -8,7 +8,9 @@ import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
import buttondevteam.discordplugin.DiscordSender;
|
import buttondevteam.discordplugin.DiscordSender;
|
||||||
import buttondevteam.discordplugin.DiscordSenderBase;
|
import buttondevteam.discordplugin.DiscordSenderBase;
|
||||||
import buttondevteam.discordplugin.listeners.CommandListener;
|
import buttondevteam.discordplugin.listeners.CommandListener;
|
||||||
|
import buttondevteam.discordplugin.listeners.CommonListeners;
|
||||||
import buttondevteam.discordplugin.playerfaker.VanillaCommandListener;
|
import buttondevteam.discordplugin.playerfaker.VanillaCommandListener;
|
||||||
|
import buttondevteam.discordplugin.util.Timings;
|
||||||
import buttondevteam.lib.*;
|
import buttondevteam.lib.*;
|
||||||
import buttondevteam.lib.chat.ChatMessage;
|
import buttondevteam.lib.chat.ChatMessage;
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
|
@ -222,17 +224,18 @@ public class MCChatListener implements Listener {
|
||||||
val ret = Mono.just(true);
|
val ret = Mono.just(true);
|
||||||
if (!ComponentManager.isEnabled(MinecraftChatModule.class))
|
if (!ComponentManager.isEnabled(MinecraftChatModule.class))
|
||||||
return ret;
|
return ret;
|
||||||
System.out.println("Chat event");
|
Timings timings = CommonListeners.timings;
|
||||||
|
timings.printElapsed("Chat event");
|
||||||
val author = ev.getMessage().getAuthor();
|
val author = ev.getMessage().getAuthor();
|
||||||
final boolean hasCustomChat = MCChatCustom.hasCustomChat(ev.getMessage().getChannelId());
|
final boolean hasCustomChat = MCChatCustom.hasCustomChat(ev.getMessage().getChannelId());
|
||||||
return ev.getMessage().getChannel().filter(channel -> {
|
return ev.getMessage().getChannel().filter(channel -> {
|
||||||
System.out.println("Filter 1");
|
timings.printElapsed("Filter 1");
|
||||||
return !(ev.getMessage().getChannelId().asLong() != module.chatChannel().get().asLong()
|
return !(ev.getMessage().getChannelId().asLong() != module.chatChannel().get().asLong()
|
||||||
&& !(channel instanceof PrivateChannel
|
&& !(channel instanceof PrivateChannel
|
||||||
&& author.map(u -> MCChatPrivate.isMinecraftChatEnabled(u.getId().asString())).orElse(false)
|
&& author.map(u -> MCChatPrivate.isMinecraftChatEnabled(u.getId().asString())).orElse(false)
|
||||||
&& !hasCustomChat)); //Chat isn't enabled on this channel
|
&& !hasCustomChat)); //Chat isn't enabled on this channel
|
||||||
}).filter(channel -> {
|
}).filter(channel -> {
|
||||||
System.out.println("Filter 2");
|
timings.printElapsed("Filter 2");
|
||||||
return !(channel instanceof PrivateChannel //Only in private chat
|
return !(channel instanceof PrivateChannel //Only in private chat
|
||||||
&& ev.getMessage().getContent().isPresent()
|
&& ev.getMessage().getContent().isPresent()
|
||||||
&& ev.getMessage().getContent().get().length() < "/mcchat<>".length()
|
&& ev.getMessage().getContent().get().length() < "/mcchat<>".length()
|
||||||
|
@ -244,7 +247,7 @@ public class MCChatListener implements Listener {
|
||||||
.filter(channel -> {
|
.filter(channel -> {
|
||||||
MCChatUtils.resetLastMessage(channel);
|
MCChatUtils.resetLastMessage(channel);
|
||||||
recevents.add(ev);
|
recevents.add(ev);
|
||||||
System.out.println("Message event added");
|
timings.printElapsed("Message event added");
|
||||||
if (rectask != null)
|
if (rectask != null)
|
||||||
return true;
|
return true;
|
||||||
recrun = () -> { //Don't return in a while loop next time
|
recrun = () -> { //Don't return in a while loop next time
|
||||||
|
|
|
@ -218,17 +218,14 @@ public class MCChatUtils {
|
||||||
*/
|
*/
|
||||||
public static void resetLastMessage(Channel channel) {
|
public static void resetLastMessage(Channel channel) {
|
||||||
if (notEnabled()) return;
|
if (notEnabled()) return;
|
||||||
System.out.println("Reset last message");
|
|
||||||
if (channel.getId().asLong() == module.chatChannel().get().asLong()) {
|
if (channel.getId().asLong() == module.chatChannel().get().asLong()) {
|
||||||
(lastmsgdata == null ? lastmsgdata = new LastMsgData(module.chatChannelMono().block(), null)
|
(lastmsgdata == null ? lastmsgdata = new LastMsgData(module.chatChannelMono().block(), null)
|
||||||
: lastmsgdata).message = null;
|
: lastmsgdata).message = null;
|
||||||
System.out.println("Reset done: public chat");
|
|
||||||
return;
|
return;
|
||||||
} // Don't set the whole object to null, the player and channel information should be preserved
|
} // Don't set the whole object to null, the player and channel information should be preserved
|
||||||
for (LastMsgData data : channel instanceof PrivateChannel ? MCChatPrivate.lastmsgPerUser : MCChatCustom.lastmsgCustom) {
|
for (LastMsgData data : channel instanceof PrivateChannel ? MCChatPrivate.lastmsgPerUser : MCChatCustom.lastmsgCustom) {
|
||||||
if (data.channel.getId().asLong() == channel.getId().asLong()) {
|
if (data.channel.getId().asLong() == channel.getId().asLong()) {
|
||||||
data.message = null;
|
data.message = null;
|
||||||
System.out.println("Reset done: private/custom chat");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
src/main/java/buttondevteam/discordplugin/util/Timings.java
Normal file
16
src/main/java/buttondevteam/discordplugin/util/Timings.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package buttondevteam.discordplugin.util;
|
||||||
|
|
||||||
|
import buttondevteam.discordplugin.DPUtils;
|
||||||
|
|
||||||
|
public class Timings {
|
||||||
|
private long start;
|
||||||
|
|
||||||
|
public Timings() {
|
||||||
|
start = System.nanoTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printElapsed(String message) {
|
||||||
|
DPUtils.getLogger().info(message + " (" + (System.nanoTime() - start) / 1000000L + ")");
|
||||||
|
start = System.nanoTime();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue