parent
e2e8a58c4e
commit
eeb1955ebe
13 changed files with 145 additions and 148 deletions
7
pom.xml
7
pom.xml
|
@ -174,7 +174,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.discord4j</groupId>
|
<groupId>com.discord4j</groupId>
|
||||||
<artifactId>discord4j-core</artifactId>
|
<artifactId>discord4j-core</artifactId>
|
||||||
<version>3.0.2</version>
|
<version>3.0.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14 -->
|
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -200,11 +200,6 @@
|
||||||
<version>2.13.1</version>
|
<version>2.13.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.xaanit</groupId>
|
|
||||||
<artifactId>D4J-OAuth</artifactId>
|
|
||||||
<version>master-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
|
|
@ -58,7 +58,10 @@ public final class DPUtils {
|
||||||
|
|
||||||
public static ConfigData<MessageChannel> channelData(IHaveConfig config, String key, long defID) {
|
public static ConfigData<MessageChannel> channelData(IHaveConfig config, String key, long defID) {
|
||||||
return config.getDataPrimDef(key, defID, id -> {
|
return config.getDataPrimDef(key, defID, id -> {
|
||||||
Channel ch = DiscordPlugin.dc.getChannelById(Snowflake.of((long) id)).block();
|
Channel ch = DiscordPlugin.dc.getChannelById(Snowflake.of((long) id)).onErrorResume(e -> {
|
||||||
|
getLogger().warning("Failed to get channel data for " + key + "=" + id + " - " + e.getMessage());
|
||||||
|
return Mono.empty();
|
||||||
|
}).block();
|
||||||
if (ch instanceof MessageChannel)
|
if (ch instanceof MessageChannel)
|
||||||
return (MessageChannel) ch;
|
return (MessageChannel) ch;
|
||||||
else
|
else
|
||||||
|
@ -127,4 +130,8 @@ public final class DPUtils {
|
||||||
? original.getAuthor().get().getMention() + ", " : "") + message));
|
? original.getAuthor().get().getMention() + ", " : "") + message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String nickMention(Snowflake userId) {
|
||||||
|
return "<@!" + userId.asString() + ">";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import discord4j.core.DiscordClient;
|
import discord4j.core.DiscordClient;
|
||||||
import discord4j.core.DiscordClientBuilder;
|
import discord4j.core.DiscordClientBuilder;
|
||||||
|
import discord4j.core.event.domain.guild.GuildCreateEvent;
|
||||||
import discord4j.core.event.domain.lifecycle.ReadyEvent;
|
import discord4j.core.event.domain.lifecycle.ReadyEvent;
|
||||||
import discord4j.core.object.entity.Guild;
|
import discord4j.core.object.entity.Guild;
|
||||||
import discord4j.core.object.entity.MessageChannel;
|
import discord4j.core.object.entity.MessageChannel;
|
||||||
|
@ -35,14 +36,14 @@ import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DiscordPlugin extends ButtonPlugin {
|
public class DiscordPlugin extends ButtonPlugin {
|
||||||
|
@ -105,15 +106,16 @@ public class DiscordPlugin extends ButtonPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val cb = new DiscordClientBuilder(token);
|
val cb = new DiscordClientBuilder(token);
|
||||||
|
cb.setInitialPresence(Presence.doNotDisturb(Activity.playing("booting")));
|
||||||
dc = cb.build();
|
dc = cb.build();
|
||||||
dc.getEventDispatcher().on(ReadyEvent.class).subscribe(this::handleReady);
|
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
|
||||||
.flatMap(size -> dc.getEventDispatcher()
|
.flatMap(size -> dc.getEventDispatcher()
|
||||||
.on(GuildCreateEvent.class) // Listen for GuildCreateEvent(s)
|
.on(GuildCreateEvent.class) // Listen for GuildCreateEvent(s)
|
||||||
.take(size) // Take only the first `size` GuildCreateEvent(s) to be received
|
.take(size) // Take only the first `size` GuildCreateEvent(s) to be received
|
||||||
.collectList()) // Take all received GuildCreateEvents and make it a List
|
.collectList()) // Take all received GuildCreateEvents and make it a List
|
||||||
.subscribe(events -> /* All guilds have been received, client is fully connected *);*/ //TODO
|
.subscribe(this::handleReady); /* All guilds have been received, client is fully connected */
|
||||||
|
dc.login().subscribe();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Bukkit.getPluginManager().disablePlugin(this);
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
|
@ -122,86 +124,68 @@ public class DiscordPlugin extends ButtonPlugin {
|
||||||
|
|
||||||
public static Guild mainServer;
|
public static Guild mainServer;
|
||||||
|
|
||||||
private static volatile BukkitTask task;
|
private void handleReady(List<GuildCreateEvent> event) {
|
||||||
private static volatile boolean sent = false;
|
|
||||||
|
|
||||||
private void handleReady(ReadyEvent event) {
|
|
||||||
try {
|
try {
|
||||||
dc.updatePresence(Presence.doNotDisturb(Activity.playing("booting"))).subscribe();
|
mainServer = MainServer().get(); //Shouldn't change afterwards
|
||||||
val tries = new AtomicInteger();
|
if (mainServer == null) {
|
||||||
task = Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
|
if (event.size() == 0) {
|
||||||
tries.incrementAndGet();
|
|
||||||
if (tries.get() > 10) { //5 seconds
|
|
||||||
task.cancel();
|
|
||||||
getLogger().severe("Main server not found! Invite the bot and do /discord reset");
|
getLogger().severe("Main server not found! Invite the bot and do /discord reset");
|
||||||
//getIConfig().getConfig().set("mainServer", 219529124321034241L); //Needed because it won't save as long as it's null - made it save
|
|
||||||
saveConfig(); //Put default there
|
saveConfig(); //Put default there
|
||||||
return;
|
return; //We should have all guilds by now, no need to retry
|
||||||
}
|
}
|
||||||
mainServer = MainServer().get(); //Shouldn't change afterwards
|
mainServer = event.get(0).getGuild();
|
||||||
if (mainServer == null) {
|
getLogger().warning("Main server set to first one: " + mainServer.getName());
|
||||||
val guilds = dc.getGuilds();
|
MainServer().set(mainServer); //Save in config
|
||||||
if (guilds.count().blockOptional().orElse(0L) == 0L)
|
}
|
||||||
return; //If there are no guilds in cache, retry
|
if (!TBMCCoreAPI.IsTestServer()) { //Don't change conditions here, see mainServer=devServer=null in onDisable()
|
||||||
mainServer = guilds.blockFirst();
|
dc.updatePresence(Presence.online(Activity.playing("Minecraft"))).subscribe();
|
||||||
if (mainServer == null) return;
|
} else {
|
||||||
getLogger().warning("Main server set to first one: " + mainServer.getName());
|
dc.updatePresence(Presence.online(Activity.playing("testing"))).subscribe();
|
||||||
MainServer().set(mainServer); //Save in config
|
}
|
||||||
}
|
SafeMode = false;
|
||||||
if (!TBMCCoreAPI.IsTestServer()) { //Don't change conditions here, see mainServer=devServer=null in onDisable()
|
DPUtils.disableIfConfigError(null, CommandChannel(), ModRole()); //Won't disable, just prints the warning here
|
||||||
dc.updatePresence(Presence.online(Activity.playing("Minecraft")));
|
|
||||||
} else {
|
|
||||||
dc.updatePresence(Presence.online(Activity.playing("testing")));
|
|
||||||
}
|
|
||||||
SafeMode = false;
|
|
||||||
if (task != null)
|
|
||||||
task.cancel();
|
|
||||||
if (!sent) {
|
|
||||||
DPUtils.disableIfConfigError(null, CommandChannel(), ModRole()); //Won't disable, just prints the warning here
|
|
||||||
|
|
||||||
Component.registerComponent(this, new GeneralEventBroadcasterModule());
|
Component.registerComponent(this, new GeneralEventBroadcasterModule());
|
||||||
Component.registerComponent(this, new MinecraftChatModule());
|
Component.registerComponent(this, new MinecraftChatModule());
|
||||||
Component.registerComponent(this, new ExceptionListenerModule());
|
Component.registerComponent(this, new ExceptionListenerModule());
|
||||||
Component.registerComponent(this, new GameRoleModule()); //Needs the mainServer to be set
|
Component.registerComponent(this, new GameRoleModule()); //Needs the mainServer to be set
|
||||||
Component.registerComponent(this, new AnnouncerModule());
|
Component.registerComponent(this, new AnnouncerModule());
|
||||||
Component.registerComponent(this, new FunModule());
|
Component.registerComponent(this, new FunModule());
|
||||||
new ChromaBot(this).updatePlayerList(); //Initialize ChromaBot - The MCCHatModule is tested to be enabled
|
new ChromaBot(this).updatePlayerList(); //Initialize ChromaBot - The MCCHatModule is tested to be enabled
|
||||||
|
|
||||||
getManager().registerCommand(new VersionCommand());
|
getManager().registerCommand(new VersionCommand());
|
||||||
getManager().registerCommand(new UserinfoCommand());
|
getManager().registerCommand(new UserinfoCommand());
|
||||||
getManager().registerCommand(new HelpCommand());
|
getManager().registerCommand(new HelpCommand());
|
||||||
getManager().registerCommand(new DebugCommand());
|
getManager().registerCommand(new DebugCommand());
|
||||||
getManager().registerCommand(new ConnectCommand());
|
getManager().registerCommand(new ConnectCommand());
|
||||||
if (DiscordMCCommand.resetting) //These will only execute if the chat is enabled
|
if (DiscordMCCommand.resetting) //These will only execute if the chat is enabled
|
||||||
ChromaBot.getInstance().sendMessageCustomAsWell(ch->ch.createEmbed(ecs->ecs.setColor(Color.CYAN)
|
ChromaBot.getInstance().sendMessageCustomAsWell(ch -> ch.createEmbed(ecs -> ecs.setColor(Color.CYAN)
|
||||||
.setTitle("Discord plugin restarted - chat connected.")), ChannelconBroadcast.RESTART); //Really important to note the chat, hmm
|
.setTitle("Discord plugin restarted - chat connected.")), ChannelconBroadcast.RESTART); //Really important to note the chat, hmm
|
||||||
else if (getConfig().getBoolean("serverup", false)) {
|
else if (getConfig().getBoolean("serverup", false)) {
|
||||||
ChromaBot.getInstance().sendMessageCustomAsWell(ch->ch.createEmbed(ecs->ecs.setColor(Color.YELLOW)
|
ChromaBot.getInstance().sendMessageCustomAsWell(ch -> ch.createEmbed(ecs -> ecs.setColor(Color.YELLOW)
|
||||||
.setTitle("Server recovered from a crash - chat connected.")), ChannelconBroadcast.RESTART);
|
.setTitle("Server recovered from a crash - chat connected.")), ChannelconBroadcast.RESTART);
|
||||||
val thr = new Throwable(
|
val thr = new Throwable(
|
||||||
"The server shut down unexpectedly. See the log of the previous run for more details.");
|
"The server shut down unexpectedly. See the log of the previous run for more details.");
|
||||||
thr.setStackTrace(new StackTraceElement[0]);
|
thr.setStackTrace(new StackTraceElement[0]);
|
||||||
TBMCCoreAPI.SendException("The server crashed!", thr);
|
TBMCCoreAPI.SendException("The server crashed!", thr);
|
||||||
} else
|
} else
|
||||||
ChromaBot.getInstance().sendMessageCustomAsWell(ch -> ch.createEmbed(ecs -> ecs.setColor(Color.GREEN)
|
ChromaBot.getInstance().sendMessageCustomAsWell(ch -> ch.createEmbed(ecs -> ecs.setColor(Color.GREEN)
|
||||||
.setTitle("Server started - chat connected.")), ChannelconBroadcast.RESTART);
|
.setTitle("Server started - chat connected.")), ChannelconBroadcast.RESTART);
|
||||||
|
|
||||||
DiscordMCCommand.resetting = false; //This is the last event handling this flag
|
DiscordMCCommand.resetting = false; //This is the last event handling this flag
|
||||||
|
|
||||||
|
getConfig().set("serverup", true);
|
||||||
|
saveConfig();
|
||||||
|
if (TBMCCoreAPI.IsTestServer() && !Objects.requireNonNull(dc.getSelf().block()).getUsername().toLowerCase().contains("test")) {
|
||||||
|
TBMCCoreAPI.SendException(
|
||||||
|
"Won't load because we're in testing mode and not using a separate account.",
|
||||||
|
new Exception(
|
||||||
|
"The plugin refuses to load until you change the token to a testing account. (The account needs to have \"test\" in it's name.)"));
|
||||||
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
|
}
|
||||||
|
TBMCCoreAPI.SendUnsentExceptions();
|
||||||
|
TBMCCoreAPI.SendUnsentDebugMessages();
|
||||||
|
|
||||||
getConfig().set("serverup", true);
|
|
||||||
saveConfig();
|
|
||||||
sent = true;
|
|
||||||
if (TBMCCoreAPI.IsTestServer() && !event.getSelf().getUsername().toLowerCase().contains("test")) {
|
|
||||||
TBMCCoreAPI.SendException(
|
|
||||||
"Won't load because we're in testing mode and not using a separate account.",
|
|
||||||
new Exception(
|
|
||||||
"The plugin refuses to load until you change the token to a testing account. (The account needs to have \"test\" in it's name.)"));
|
|
||||||
Bukkit.getPluginManager().disablePlugin(this);
|
|
||||||
}
|
|
||||||
TBMCCoreAPI.SendUnsentExceptions();
|
|
||||||
TBMCCoreAPI.SendUnsentDebugMessages();
|
|
||||||
}
|
|
||||||
}, 0, 10);
|
|
||||||
CommonListeners.register(dc.getEventDispatcher());
|
CommonListeners.register(dc.getEventDispatcher());
|
||||||
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(), this);
|
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(), this);
|
||||||
getCommand2MC().registerCommand(new DiscordMCCommand());
|
getCommand2MC().registerCommand(new DiscordMCCommand());
|
||||||
|
@ -253,7 +237,6 @@ public class DiscordPlugin extends ButtonPlugin {
|
||||||
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
|
||||||
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
|
||||||
sent = false;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TBMCCoreAPI.SendException("An error occured while disabling DiscordPlugin!", e);
|
TBMCCoreAPI.SendException("An error occured while disabling DiscordPlugin!", e);
|
||||||
}
|
}
|
||||||
|
@ -263,7 +246,7 @@ public class DiscordPlugin extends ButtonPlugin {
|
||||||
|
|
||||||
public static Permission perms;
|
public static Permission perms;
|
||||||
|
|
||||||
public boolean setupProviders() {
|
private boolean setupProviders() {
|
||||||
try {
|
try {
|
||||||
Class.forName("net.milkbowl.vault.permission.Permission");
|
Class.forName("net.milkbowl.vault.permission.Permission");
|
||||||
Class.forName("net.milkbowl.vault.chat.Chat");
|
Class.forName("net.milkbowl.vault.chat.Chat");
|
||||||
|
|
|
@ -58,7 +58,7 @@ public abstract class DiscordSenderBase implements CommandSender {
|
||||||
msgtosend += "\n" + sendmsg;
|
msgtosend += "\n" + sendmsg;
|
||||||
if (sendtask == null)
|
if (sendtask == null)
|
||||||
sendtask = Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, () -> {
|
sendtask = Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, () -> {
|
||||||
channel.createMessage((!broadcast && user != null ? user.getMention() + "\n" : "") + msgtosend.trim());
|
channel.createMessage((!broadcast && user != null ? user.getMention() + "\n" : "") + msgtosend.trim()).subscribe();
|
||||||
sendtask = null;
|
sendtask = null;
|
||||||
msgtosend = "";
|
msgtosend = "";
|
||||||
}, 4); // Waits a 0.2 second to gather all/most of the different messages
|
}, 4); // Waits a 0.2 second to gather all/most of the different messages
|
||||||
|
|
|
@ -18,9 +18,12 @@ public class Command2DCSender implements Command2Sender {
|
||||||
message = DPUtils.sanitizeString(message);
|
message = DPUtils.sanitizeString(message);
|
||||||
message = Character.toLowerCase(message.charAt(0)) + message.substring(1);
|
message = Character.toLowerCase(message.charAt(0)) + message.substring(1);
|
||||||
val msg = message;
|
val msg = message;
|
||||||
val author = this.message.getAuthorAsMember().block();
|
/*this.message.getAuthorAsMember().flatMap(author ->
|
||||||
if (author == null) return;
|
this.message.getChannel().flatMap(ch ->
|
||||||
this.message.getChannel().subscribe(ch -> ch.createMessage(author.getNicknameMention() + ", " + msg));
|
ch.createMessage(author.getNicknameMention() + ", " + msg))).subscribe();*/
|
||||||
|
this.message.getChannel().flatMap(ch ->
|
||||||
|
ch.createMessage(this.message.getAuthor().map(u -> DPUtils.nickMention(u.getId()) + ", ").orElse("")
|
||||||
|
+ msg)).subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package buttondevteam.discordplugin.commands;
|
package buttondevteam.discordplugin.commands;
|
||||||
|
|
||||||
|
import buttondevteam.lib.chat.Command2;
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
|
|
||||||
@CommandClass(helpText = {
|
@CommandClass(helpText = {
|
||||||
|
@ -7,12 +8,17 @@ import buttondevteam.lib.chat.CommandClass;
|
||||||
"Shows some info about a command or lists the available commands.", //
|
"Shows some info about a command or lists the available commands.", //
|
||||||
})
|
})
|
||||||
public class HelpCommand extends ICommand2DC {
|
public class HelpCommand extends ICommand2DC {
|
||||||
@Override
|
@Command2.Subcommand
|
||||||
public boolean def(Command2DCSender sender, String args) {
|
public boolean def(Command2DCSender sender, @Command2.TextArg @Command2.OptionalArg String args) {
|
||||||
if (args.length() == 0)
|
if (args == null || args.length() == 0)
|
||||||
sender.sendMessage(getManager().getCommandsText());
|
sender.sendMessage(getManager().getCommandsText());
|
||||||
else
|
else {
|
||||||
sender.sendMessage("Soon:tm:"); //TODO
|
String[] ht = getManager().getHelpText(args);
|
||||||
return true;
|
if (ht == null)
|
||||||
|
sender.sendMessage("Command not found: " + args);
|
||||||
|
else
|
||||||
|
sender.sendMessage(ht);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class CommandListener {
|
||||||
if (!message.getContent().isPresent())
|
if (!message.getContent().isPresent())
|
||||||
return false; //Pin messages and such, let the mcchat listener deal with it
|
return false; //Pin messages and such, let the mcchat listener deal with it
|
||||||
final MessageChannel channel = message.getChannel().block();
|
final MessageChannel channel = message.getChannel().block();
|
||||||
@SuppressWarnings("OptionalGetWithoutIsPresent") val content = message.getContent().get();
|
val content = message.getContent().get();
|
||||||
if (channel == null) return false;
|
if (channel == null) return false;
|
||||||
if (!mentionedonly) { //mentionedonly conditions are in CommonListeners
|
if (!mentionedonly) { //mentionedonly conditions are in CommonListeners
|
||||||
if (!(channel instanceof PrivateChannel)
|
if (!(channel instanceof PrivateChannel)
|
||||||
|
@ -32,10 +32,10 @@ public class CommandListener {
|
||||||
channel.type().subscribe(); // Fun
|
channel.type().subscribe(); // Fun
|
||||||
}
|
}
|
||||||
final StringBuilder cmdwithargs = new StringBuilder(content);
|
final StringBuilder cmdwithargs = new StringBuilder(content);
|
||||||
val self=DiscordPlugin.dc.getSelf().block();
|
val self = DiscordPlugin.dc.getSelf().block();
|
||||||
if(self==null) return false;
|
if (self == null) return false;
|
||||||
val member=self.asMember(DiscordPlugin.mainServer.getId()).block();
|
val member = self.asMember(DiscordPlugin.mainServer.getId()).block();
|
||||||
if(member==null) return false;
|
if (member == null) return false;
|
||||||
final String mention = self.getMention();
|
final String mention = self.getMention();
|
||||||
final String mentionNick = member.getNicknameMention();
|
final String mentionNick = member.getNicknameMention();
|
||||||
boolean gotmention = checkanddeletemention(cmdwithargs, mention, message);
|
boolean gotmention = checkanddeletemention(cmdwithargs, mention, message);
|
||||||
|
@ -57,6 +57,7 @@ public class CommandListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean checkanddeletemention(StringBuilder cmdwithargs, String mention, Message message) {
|
private static boolean checkanddeletemention(StringBuilder cmdwithargs, String mention, Message message) {
|
||||||
|
final char prefix = DiscordPlugin.getPrefix();
|
||||||
if (message.getContent().orElse("").startsWith(mention)) // TODO: Resolve mentions: Compound arguments, either a mention or text
|
if (message.getContent().orElse("").startsWith(mention)) // TODO: Resolve mentions: Compound arguments, either a mention or text
|
||||||
if (cmdwithargs.length() > mention.length() + 1) {
|
if (cmdwithargs.length() > mention.length() + 1) {
|
||||||
int i = cmdwithargs.indexOf(" ", mention.length());
|
int i = cmdwithargs.indexOf(" ", mention.length());
|
||||||
|
@ -67,14 +68,16 @@ public class CommandListener {
|
||||||
for (; i < cmdwithargs.length() && cmdwithargs.charAt(i) == ' '; i++)
|
for (; i < cmdwithargs.length() && cmdwithargs.charAt(i) == ' '; i++)
|
||||||
; //Removes any space before the command
|
; //Removes any space before the command
|
||||||
cmdwithargs.delete(0, i);
|
cmdwithargs.delete(0, i);
|
||||||
cmdwithargs.insert(0, DiscordPlugin.getPrefix()); //Always use the prefix for processing
|
cmdwithargs.insert(0, prefix); //Always use the prefix for processing
|
||||||
} else
|
} else
|
||||||
cmdwithargs.replace(0, cmdwithargs.length(), DiscordPlugin.getPrefix() + "help");
|
cmdwithargs.replace(0, cmdwithargs.length(), prefix + "help");
|
||||||
else {
|
else {
|
||||||
|
if (cmdwithargs.length() == 0)
|
||||||
|
cmdwithargs.replace(0, cmdwithargs.length(), prefix + "help");
|
||||||
|
else if (cmdwithargs.charAt(0) != prefix)
|
||||||
|
cmdwithargs.insert(0, prefix);
|
||||||
return false; //Don't treat / as mention, mentions can be used in public mcchat
|
return false; //Don't treat / as mention, mentions can be used in public mcchat
|
||||||
}
|
}
|
||||||
if (cmdwithargs.length() == 0)
|
|
||||||
cmdwithargs.replace(0, cmdwithargs.length(), DiscordPlugin.getPrefix() + "help");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,48 +27,51 @@ public class CommonListeners {
|
||||||
- CommandListener (with the correct prefix in #bot, or in private)
|
- CommandListener (with the correct prefix in #bot, or in private)
|
||||||
*/
|
*/
|
||||||
public static void register(EventDispatcher dispatcher) {
|
public static void register(EventDispatcher dispatcher) {
|
||||||
dispatcher.on(MessageCreateEvent.class).subscribe(event->{
|
dispatcher.on(MessageCreateEvent.class).subscribe(event -> {
|
||||||
if (DiscordPlugin.SafeMode)
|
if (DiscordPlugin.SafeMode)
|
||||||
return;
|
return;
|
||||||
val author = event.getMessage().getAuthor();
|
val author = event.getMessage().getAuthor();
|
||||||
if (!author.isPresent() || author.get().isBot())
|
if (!author.isPresent() || author.get().isBot())
|
||||||
return;
|
return;
|
||||||
if (FunModule.executeMemes(event.getMessage()))
|
//System.out.println("Author: "+author.get());
|
||||||
return;
|
//System.out.println("Bot: "+author.get().isBot());
|
||||||
try {
|
if (FunModule.executeMemes(event.getMessage()))
|
||||||
boolean handled = false;
|
return;
|
||||||
val commandChannel = DiscordPlugin.plugin.CommandChannel().get();
|
try {
|
||||||
if ((commandChannel != null && event.getMessage().getChannelId().asLong() == commandChannel.getId().asLong()) //If mentioned, that's higher than chat
|
boolean handled = false;
|
||||||
|| event.getMessage().getContent().orElse("").contains("channelcon")) //Only 'channelcon' is allowed in other channels
|
val commandChannel = DiscordPlugin.plugin.CommandChannel().get();
|
||||||
handled = CommandListener.runCommand(event.getMessage(), true); //#bot is handled here
|
if ((commandChannel != null && event.getMessage().getChannelId().asLong() == commandChannel.getId().asLong()) //If mentioned, that's higher than chat
|
||||||
if (handled) return;
|
|| event.getMessage().getContent().orElse("").contains("channelcon")) //Only 'channelcon' is allowed in other channels
|
||||||
val mcchat = Component.getComponents().get(MinecraftChatModule.class);
|
handled = CommandListener.runCommand(event.getMessage(), true); //#bot is handled here
|
||||||
if (mcchat != null && mcchat.isEnabled()) //ComponentManager.isEnabled() searches the component again
|
if (handled) return;
|
||||||
handled = ((MinecraftChatModule) mcchat).getListener().handleDiscord(event); //Also runs Discord commands in chat channels
|
//System.out.println("Message handling");
|
||||||
if (!handled)
|
val mcchat = Component.getComponents().get(MinecraftChatModule.class);
|
||||||
handled = CommandListener.runCommand(event.getMessage(), false);
|
if (mcchat != null && mcchat.isEnabled()) //ComponentManager.isEnabled() searches the component again
|
||||||
} catch (Exception e) {
|
handled = ((MinecraftChatModule) mcchat).getListener().handleDiscord(event); //Also runs Discord commands in chat channels
|
||||||
TBMCCoreAPI.SendException("An error occured while handling a message!", e);
|
if (!handled)
|
||||||
}
|
handled = CommandListener.runCommand(event.getMessage(), false);
|
||||||
});
|
} catch (Exception e) {
|
||||||
dispatcher.on(PresenceUpdateEvent.class).subscribe(event->{
|
TBMCCoreAPI.SendException("An error occured while handling a message!", e);
|
||||||
if (DiscordPlugin.SafeMode)
|
}
|
||||||
return;
|
});
|
||||||
FunModule.handleFullHouse(event);
|
dispatcher.on(PresenceUpdateEvent.class).subscribe(event -> {
|
||||||
});
|
if (DiscordPlugin.SafeMode)
|
||||||
|
return;
|
||||||
|
FunModule.handleFullHouse(event);
|
||||||
|
});
|
||||||
dispatcher.on(RoleCreateEvent.class).subscribe(GameRoleModule::handleRoleEvent);
|
dispatcher.on(RoleCreateEvent.class).subscribe(GameRoleModule::handleRoleEvent);
|
||||||
dispatcher.on(RoleDeleteEvent.class).subscribe(GameRoleModule::handleRoleEvent);
|
dispatcher.on(RoleDeleteEvent.class).subscribe(GameRoleModule::handleRoleEvent);
|
||||||
dispatcher.on(RoleUpdateEvent.class).subscribe(GameRoleModule::handleRoleEvent);
|
dispatcher.on(RoleUpdateEvent.class).subscribe(GameRoleModule::handleRoleEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean debug = false;
|
private static boolean debug = false;
|
||||||
|
|
||||||
public static void debug(String debug) {
|
public static void debug(String debug) {
|
||||||
if (CommonListeners.debug) //Debug
|
if (CommonListeners.debug) //Debug
|
||||||
DPUtils.getLogger().info(debug);
|
DPUtils.getLogger().info(debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean debug() {
|
public static boolean debug() {
|
||||||
return debug = !debug;
|
return debug = !debug;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import buttondevteam.core.component.channel.ChatRoom;
|
||||||
import buttondevteam.discordplugin.DiscordConnectedPlayer;
|
import buttondevteam.discordplugin.DiscordConnectedPlayer;
|
||||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||||
import discord4j.core.object.entity.MessageChannel;
|
import discord4j.core.object.entity.MessageChannel;
|
||||||
import discord4j.core.object.entity.TextChannel;
|
|
||||||
import discord4j.core.object.entity.User;
|
import discord4j.core.object.entity.User;
|
||||||
import discord4j.core.object.util.Snowflake;
|
import discord4j.core.object.util.Snowflake;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -65,7 +64,7 @@ public class MCChatCustom {
|
||||||
|
|
||||||
private CustomLMD(@NonNull MessageChannel channel, @NonNull User user,
|
private CustomLMD(@NonNull MessageChannel channel, @NonNull User user,
|
||||||
@NonNull String groupid, @NonNull Channel mcchannel, @NonNull DiscordConnectedPlayer dcp, int toggles, Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles) {
|
@NonNull String groupid, @NonNull Channel mcchannel, @NonNull DiscordConnectedPlayer dcp, int toggles, Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles) {
|
||||||
super((TextChannel) channel, user);
|
super(channel, user);
|
||||||
groupID = groupid;
|
groupID = groupid;
|
||||||
this.mcchannel = mcchannel;
|
this.mcchannel = mcchannel;
|
||||||
this.dcp = dcp;
|
this.dcp = dcp;
|
||||||
|
|
|
@ -236,6 +236,7 @@ public class MCChatListener implements Listener {
|
||||||
if (CommandListener.runCommand(ev.getMessage(), true))
|
if (CommandListener.runCommand(ev.getMessage(), true))
|
||||||
return true; //Allow running commands in chat channels
|
return true; //Allow running commands in chat channels
|
||||||
MCChatUtils.resetLastMessage(channel);
|
MCChatUtils.resetLastMessage(channel);
|
||||||
|
//System.out.println("Message: "+ev.getMessage().getAuthor().toString());
|
||||||
recevents.add(ev);
|
recevents.add(ev);
|
||||||
if (rectask != null)
|
if (rectask != null)
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -7,7 +7,6 @@ import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
import buttondevteam.lib.player.TBMCPlayer;
|
||||||
import discord4j.core.object.entity.MessageChannel;
|
import discord4j.core.object.entity.MessageChannel;
|
||||||
import discord4j.core.object.entity.PrivateChannel;
|
import discord4j.core.object.entity.PrivateChannel;
|
||||||
import discord4j.core.object.entity.TextChannel;
|
|
||||||
import discord4j.core.object.entity.User;
|
import discord4j.core.object.entity.User;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -44,7 +43,7 @@ public class MCChatPrivate {
|
||||||
if (!start)
|
if (!start)
|
||||||
MCChatUtils.lastmsgfromd.remove(channel.getId().asLong());
|
MCChatUtils.lastmsgfromd.remove(channel.getId().asLong());
|
||||||
return start //
|
return start //
|
||||||
? lastmsgPerUser.add(new MCChatUtils.LastMsgData((TextChannel) channel, user)) // Doesn't support group DMs
|
? lastmsgPerUser.add(new MCChatUtils.LastMsgData(channel, user)) // Doesn't support group DMs
|
||||||
: lastmsgPerUser.removeIf(lmd -> lmd.channel.getId().asLong() == channel.getId().asLong());
|
: lastmsgPerUser.removeIf(lmd -> lmd.channel.getId().asLong() == channel.getId().asLong());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ import buttondevteam.lib.TBMCSystemChatEvent;
|
||||||
import buttondevteam.lib.architecture.Component;
|
import buttondevteam.lib.architecture.Component;
|
||||||
import buttondevteam.lib.architecture.ConfigData;
|
import buttondevteam.lib.architecture.ConfigData;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
|
||||||
import discord4j.core.object.entity.MessageChannel;
|
import discord4j.core.object.entity.MessageChannel;
|
||||||
import discord4j.core.object.util.Snowflake;
|
import discord4j.core.object.util.Snowflake;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
@ -74,7 +73,6 @@ public class MinecraftChatModule extends Component<DiscordPlugin> {
|
||||||
protected void enable() {
|
protected void enable() {
|
||||||
if (DPUtils.disableIfConfigError(this, chatChannel())) return;
|
if (DPUtils.disableIfConfigError(this, chatChannel())) return;
|
||||||
listener = new MCChatListener(this);
|
listener = new MCChatListener(this);
|
||||||
DiscordPlugin.dc.getEventDispatcher().on(MessageCreateEvent.class).subscribe(listener::handleDiscord);
|
|
||||||
TBMCCoreAPI.RegisterEventsForExceptions(listener, getPlugin());
|
TBMCCoreAPI.RegisterEventsForExceptions(listener, getPlugin());
|
||||||
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(this), getPlugin());//These get undone if restarting/resetting - it will ignore events if disabled
|
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(this), getPlugin());//These get undone if restarting/resetting - it will ignore events if disabled
|
||||||
getPlugin().getManager().registerCommand(new MCChatCommand());
|
getPlugin().getManager().registerCommand(new MCChatCommand());
|
||||||
|
|
|
@ -104,9 +104,9 @@ public class DiscordMCCommand extends ICommand2MC {
|
||||||
}
|
}
|
||||||
DiscordPlugin.mainServer.getInvites().limitRequest(1)
|
DiscordPlugin.mainServer.getInvites().limitRequest(1)
|
||||||
.switchIfEmpty(Mono.fromRunnable(() -> sender.sendMessage("§cNo invites found for the server.")))
|
.switchIfEmpty(Mono.fromRunnable(() -> sender.sendMessage("§cNo invites found for the server.")))
|
||||||
.subscribe(inv -> {//TODO: Needs manage server perms
|
.subscribe(inv -> {
|
||||||
sender.sendMessage("§bInvite link: https://discord.gg/" + inv.getCode());
|
sender.sendMessage("§bInvite link: https://discord.gg/" + inv.getCode());
|
||||||
});
|
}, e -> sender.sendMessage("§cThe invite link is not set and the bot has no permission to get it."));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue