Added, 5xFixed
Added mcchat login/logout messages Only printing timings messages if debug is on Fixed #93 F i x e d Fixed command handled status Fixed debug command Fixed error reporting limit Fixed Discord YEEHAW
This commit is contained in:
parent
545b8130e0
commit
5472929113
10 changed files with 24 additions and 20 deletions
2
pom.xml
2
pom.xml
|
@ -72,7 +72,7 @@
|
||||||
<relocations>
|
<relocations>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>io.netty</pattern>
|
<pattern>io.netty</pattern>
|
||||||
<shadedPattern>buttondevteam.discordplugin.io.netty</shadedPattern>
|
<shadedPattern>btndvtm.dp.io.netty</shadedPattern>
|
||||||
<excludes>
|
<excludes>
|
||||||
</excludes>
|
</excludes>
|
||||||
</relocation>
|
</relocation>
|
||||||
|
|
|
@ -4,14 +4,18 @@ import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
import buttondevteam.discordplugin.listeners.CommonListeners;
|
import buttondevteam.discordplugin.listeners.CommonListeners;
|
||||||
import buttondevteam.lib.chat.Command2;
|
import buttondevteam.lib.chat.Command2;
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
@CommandClass(helpText = {
|
@CommandClass(helpText = {
|
||||||
"Switches debug mode."
|
"Switches debug mode."
|
||||||
})
|
})
|
||||||
public class DebugCommand extends ICommand2DC {
|
public class DebugCommand extends ICommand2DC {
|
||||||
@Command2.Subcommand
|
@Command2.Subcommand
|
||||||
public boolean def(Command2DCSender sender, String args) {
|
public boolean def(Command2DCSender sender) {
|
||||||
sender.getMessage().getAuthorAsMember()
|
sender.getMessage().getAuthorAsMember()
|
||||||
|
.switchIfEmpty(sender.getMessage().getAuthor() //Support DMs
|
||||||
|
.map(u -> u.asMember(DiscordPlugin.mainServer.getId()))
|
||||||
|
.orElse(Mono.empty()))
|
||||||
.flatMap(m -> DiscordPlugin.plugin.modRole().get()
|
.flatMap(m -> DiscordPlugin.plugin.modRole().get()
|
||||||
.map(mr -> m.getRoleIds().stream().anyMatch(r -> r.equals(mr.getId()))))
|
.map(mr -> m.getRoleIds().stream().anyMatch(r -> r.equals(mr.getId()))))
|
||||||
.subscribe(success -> {
|
.subscribe(success -> {
|
||||||
|
|
|
@ -66,8 +66,8 @@ public class ExceptionListenerModule extends Component<DiscordPlugin> implements
|
||||||
String stackTrace = Arrays.stream(ExceptionUtils.getStackTrace(e).split("\\n"))
|
String stackTrace = Arrays.stream(ExceptionUtils.getStackTrace(e).split("\\n"))
|
||||||
.filter(s -> !s.contains("\tat ") || s.contains("\tat buttondevteam."))
|
.filter(s -> !s.contains("\tat ") || s.contains("\tat buttondevteam."))
|
||||||
.collect(Collectors.joining("\n"));
|
.collect(Collectors.joining("\n"));
|
||||||
if (sb.length() + stackTrace.length() >= 2000)
|
if (sb.length() + stackTrace.length() >= 1980)
|
||||||
stackTrace = stackTrace.substring(0, 1999 - sb.length());
|
stackTrace = stackTrace.substring(0, 1980 - sb.length());
|
||||||
sb.append(stackTrace).append("\n");
|
sb.append(stackTrace).append("\n");
|
||||||
sb.append("```");
|
sb.append("```");
|
||||||
return channel.flatMap(ch -> ch.createMessage(sb.toString()));
|
return channel.flatMap(ch -> ch.createMessage(sb.toString()));
|
||||||
|
|
|
@ -25,6 +25,9 @@ import java.util.Random;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The YEEHAW event uses an emoji named :YEEHAW: if available
|
||||||
|
*/
|
||||||
public class FunModule extends Component<DiscordPlugin> implements Listener {
|
public class FunModule extends Component<DiscordPlugin> implements Listener {
|
||||||
private static final String[] serverReadyStrings = new String[]{"In one week from now", // Ali
|
private static final String[] serverReadyStrings = new String[]{"In one week from now", // Ali
|
||||||
"Between now and the heat-death of the universe.", // Ghostise
|
"Between now and the heat-death of the universe.", // Ghostise
|
||||||
|
|
|
@ -62,12 +62,13 @@ public class CommandListener {
|
||||||
try {
|
try {
|
||||||
timings.printElapsed("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)
|
||||||
|
.map(m -> false);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TBMCCoreAPI.SendException("Failed to process Discord command: " + cmdwithargsString, e);
|
TBMCCoreAPI.SendException("Failed to process Discord command: " + cmdwithargsString, e);
|
||||||
}
|
}
|
||||||
return Mono.empty();
|
return Mono.just(false); //If the command succeeded or there was an error, return false
|
||||||
}).map(m -> false).defaultIfEmpty(true);
|
}).defaultIfEmpty(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class CommonListeners {
|
||||||
val commandChannel = DiscordPlugin.plugin.commandChannel().get();
|
val commandChannel = DiscordPlugin.plugin.commandChannel().get();
|
||||||
val commandCh = DPUtils.getMessageChannel(DiscordPlugin.plugin.commandChannel());
|
val commandCh = DPUtils.getMessageChannel(DiscordPlugin.plugin.commandChannel());
|
||||||
return commandCh.filterWhen(ch -> event.getMessage().getChannel().map(mch ->
|
return commandCh.filterWhen(ch -> event.getMessage().getChannel().map(mch ->
|
||||||
commandChannel != null && event.getMessage().getChannelId().asLong() == commandChannel.asLong() //If mentioned, that's higher than chat
|
(commandChannel != null && mch.getId().asLong() == commandChannel.asLong()) //If mentioned, that's higher than chat
|
||||||
|| 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
|
||||||
|
|
|
@ -269,14 +269,12 @@ public class MCChatListener implements Listener {
|
||||||
rectask.cancel();
|
rectask.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
System.out.println("Processing...");
|
|
||||||
val sender = event.getMessage().getAuthor().orElse(null);
|
val sender = event.getMessage().getAuthor().orElse(null);
|
||||||
String dmessage = event.getMessage().getContent().orElse("");
|
String dmessage = event.getMessage().getContent().orElse("");
|
||||||
try {
|
try {
|
||||||
final DiscordSenderBase dsender = MCChatUtils.getSender(event.getMessage().getChannelId(), sender);
|
final DiscordSenderBase dsender = MCChatUtils.getSender(event.getMessage().getChannelId(), sender);
|
||||||
val user = dsender.getChromaUser();
|
val user = dsender.getChromaUser();
|
||||||
|
|
||||||
System.out.println("Mentions start");
|
|
||||||
for (User u : event.getMessage().getUserMentions().toIterable()) { //TODO: Role mentions
|
for (User u : event.getMessage().getUserMentions().toIterable()) { //TODO: Role mentions
|
||||||
dmessage = dmessage.replace(u.getMention(), "@" + u.getUsername()); // TODO: IG Formatting
|
dmessage = dmessage.replace(u.getMention(), "@" + u.getUsername()); // TODO: IG Formatting
|
||||||
val m = u.asMember(DiscordPlugin.mainServer.getId()).block();
|
val m = u.asMember(DiscordPlugin.mainServer.getId()).block();
|
||||||
|
@ -288,7 +286,6 @@ public class MCChatListener implements Listener {
|
||||||
for (GuildChannel ch : event.getGuild().flux().flatMap(Guild::getChannels).toIterable()) {
|
for (GuildChannel ch : event.getGuild().flux().flatMap(Guild::getChannels).toIterable()) {
|
||||||
dmessage = dmessage.replace(ch.getMention(), "#" + ch.getName()); // TODO: IG Formatting
|
dmessage = dmessage.replace(ch.getMention(), "#" + ch.getName()); // TODO: IG Formatting
|
||||||
}
|
}
|
||||||
System.out.println("Mentions end");
|
|
||||||
|
|
||||||
dmessage = EmojiParser.parseToAliases(dmessage, EmojiParser.FitzpatrickAction.PARSE); //Converts emoji to text- TODO: Add option to disable (resource pack?)
|
dmessage = EmojiParser.parseToAliases(dmessage, EmojiParser.FitzpatrickAction.PARSE); //Converts emoji to text- TODO: Add option to disable (resource pack?)
|
||||||
dmessage = dmessage.replaceAll(":(\\S+)\\|type_(?:(\\d)|(1)_2):", ":$1::skin-tone-$2:"); //Convert to Discord's format so it still shows up
|
dmessage = dmessage.replaceAll(":(\\S+)\\|type_(?:(\\d)|(1)_2):", ":$1::skin-tone-$2:"); //Convert to Discord's format so it still shows up
|
||||||
|
@ -302,9 +299,7 @@ public class MCChatListener implements Listener {
|
||||||
|
|
||||||
boolean react = false;
|
boolean react = false;
|
||||||
|
|
||||||
System.out.println("Getting channel...");
|
|
||||||
val sendChannel = event.getMessage().getChannel().block();
|
val sendChannel = event.getMessage().getChannel().block();
|
||||||
System.out.println("Got channel");
|
|
||||||
boolean isPrivate = sendChannel instanceof PrivateChannel;
|
boolean isPrivate = sendChannel instanceof PrivateChannel;
|
||||||
if (dmessage.startsWith("/")) { // Ingame command
|
if (dmessage.startsWith("/")) { // Ingame command
|
||||||
if (!isPrivate)
|
if (!isPrivate)
|
||||||
|
@ -380,7 +375,6 @@ public class MCChatListener implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {// Not a command
|
} else {// Not a command
|
||||||
System.out.println("Not a command");
|
|
||||||
if (dmessage.length() == 0 && event.getMessage().getAttachments().size() == 0
|
if (dmessage.length() == 0 && event.getMessage().getAttachments().size() == 0
|
||||||
&& !isPrivate && event.getMessage().getType() == Message.Type.CHANNEL_PINNED_MESSAGE) {
|
&& !isPrivate && event.getMessage().getType() == Message.Type.CHANNEL_PINNED_MESSAGE) {
|
||||||
val rtr = clmd != null ? clmd.mcchannel.getRTR(clmd.dcp)
|
val rtr = clmd != null ? clmd.mcchannel.getRTR(clmd.dcp)
|
||||||
|
@ -390,13 +384,11 @@ public class MCChatListener implements Listener {
|
||||||
: dsender.getName()) + " pinned a message on Discord.", TBMCSystemChatEvent.BroadcastTarget.ALL);
|
: dsender.getName()) + " pinned a message on Discord.", TBMCSystemChatEvent.BroadcastTarget.ALL);
|
||||||
} else {
|
} else {
|
||||||
val cmb = ChatMessage.builder(dsender, user, getChatMessage.apply(dmessage)).fromCommand(false);
|
val cmb = ChatMessage.builder(dsender, user, getChatMessage.apply(dmessage)).fromCommand(false);
|
||||||
System.out.println("Message created");
|
|
||||||
if (clmd != null)
|
if (clmd != null)
|
||||||
TBMCChatAPI.SendChatMessage(cmb.permCheck(clmd.dcp).build(), clmd.mcchannel);
|
TBMCChatAPI.SendChatMessage(cmb.permCheck(clmd.dcp).build(), clmd.mcchannel);
|
||||||
else
|
else
|
||||||
TBMCChatAPI.SendChatMessage(cmb.build());
|
TBMCChatAPI.SendChatMessage(cmb.build());
|
||||||
react = true;
|
react = true;
|
||||||
System.out.println("Message sent");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (react) {
|
if (react) {
|
||||||
|
|
|
@ -332,6 +332,7 @@ public class MCChatUtils {
|
||||||
}
|
}
|
||||||
callEventExcludingSome(new PlayerJoinEvent(dcp, ""));
|
callEventExcludingSome(new PlayerJoinEvent(dcp, ""));
|
||||||
dcp.setLoggedIn(true);
|
dcp.setLoggedIn(true);
|
||||||
|
DPUtils.getLogger().info(dcp.getName() + " (" + dcp.getUniqueId() + ") logged in from Discord");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,6 +348,7 @@ public class MCChatUtils {
|
||||||
if (needsSync) callEventSync(event);
|
if (needsSync) callEventSync(event);
|
||||||
else callEventExcludingSome(event);
|
else callEventExcludingSome(event);
|
||||||
dcp.setLoggedIn(false);
|
dcp.setLoggedIn(false);
|
||||||
|
DPUtils.getLogger().info(dcp.getName() + " (" + dcp.getUniqueId() + ") logged out from Discord");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void callEventSync(Event event) {
|
static void callEventSync(Event event) {
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.bukkit.event.server.BroadcastMessageEvent;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
class MCListener implements Listener {
|
class MCListener implements Listener {
|
||||||
|
@ -144,8 +145,9 @@ class MCListener implements Listener {
|
||||||
String name = event.getSender() instanceof Player ? ((Player) event.getSender()).getDisplayName()
|
String name = event.getSender() instanceof Player ? ((Player) event.getSender()).getDisplayName()
|
||||||
: event.getSender().getName();
|
: event.getSender().getName();
|
||||||
//Channel channel = ChromaGamerBase.getFromSender(event.getSender()).channel().get(); - TODO
|
//Channel channel = ChromaGamerBase.getFromSender(event.getSender()).channel().get(); - TODO
|
||||||
DiscordPlugin.mainServer.getEmojis().filter(e -> "YEEHAW".equals(e.getName())).subscribe(yeehaw ->
|
DiscordPlugin.mainServer.getEmojis().filter(e -> "YEEHAW".equals(e.getName()))
|
||||||
MCChatUtils.forAllMCChat(MCChatUtils.send(name + (yeehaw != null ? " <:YEEHAW:" + yeehaw.getId().asString() + ">s" : " YEEHAWs"))));
|
.take(1).singleOrEmpty().map(Optional::of).defaultIfEmpty(Optional.empty()).subscribe(yeehaw ->
|
||||||
|
MCChatUtils.forAllMCChat(MCChatUtils.send(name + (yeehaw.map(guildEmoji -> " <:YEEHAW:" + guildEmoji.getId().asString() + ">s").orElse(" YEEHAWs")))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package buttondevteam.discordplugin.util;
|
package buttondevteam.discordplugin.util;
|
||||||
|
|
||||||
import buttondevteam.discordplugin.DPUtils;
|
import buttondevteam.discordplugin.listeners.CommonListeners;
|
||||||
|
|
||||||
public class Timings {
|
public class Timings {
|
||||||
private long start;
|
private long start;
|
||||||
|
@ -10,7 +10,7 @@ public class Timings {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printElapsed(String message) {
|
public void printElapsed(String message) {
|
||||||
DPUtils.getLogger().info(message + " (" + (System.nanoTime() - start) / 1000000L + ")");
|
CommonListeners.debug(message + " (" + (System.nanoTime() - start) / 1000000L + ")");
|
||||||
start = System.nanoTime();
|
start = System.nanoTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue