Brtoggle & cmd fix
#89 Channelcon Attempted to support chat rooms in custom chat
This commit is contained in:
parent
0cbc22eb72
commit
0c9da49add
6 changed files with 65 additions and 41 deletions
|
@ -9,6 +9,7 @@ import buttondevteam.discordplugin.exceptions.ExceptionListenerModule;
|
||||||
import buttondevteam.discordplugin.fun.FunModule;
|
import buttondevteam.discordplugin.fun.FunModule;
|
||||||
import buttondevteam.discordplugin.listeners.CommonListeners;
|
import buttondevteam.discordplugin.listeners.CommonListeners;
|
||||||
import buttondevteam.discordplugin.listeners.MCListener;
|
import buttondevteam.discordplugin.listeners.MCListener;
|
||||||
|
import buttondevteam.discordplugin.mcchat.ChannelconCommand;
|
||||||
import buttondevteam.discordplugin.mcchat.MCChatPrivate;
|
import buttondevteam.discordplugin.mcchat.MCChatPrivate;
|
||||||
import buttondevteam.discordplugin.mcchat.MCChatUtils;
|
import buttondevteam.discordplugin.mcchat.MCChatUtils;
|
||||||
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
|
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
|
||||||
|
@ -128,6 +129,7 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
|
||||||
DiscordCommandBase.registerCommands();
|
DiscordCommandBase.registerCommands();
|
||||||
getManager().registerCommand(new VersionCommand());
|
getManager().registerCommand(new VersionCommand());
|
||||||
getManager().registerCommand(new UserinfoCommand());
|
getManager().registerCommand(new UserinfoCommand());
|
||||||
|
getManager().registerCommand(new ChannelconCommand());
|
||||||
if (ResetMCCommand.resetting) //These will only execute if the chat is enabled
|
if (ResetMCCommand.resetting) //These will only execute if the chat is enabled
|
||||||
ChromaBot.getInstance().sendMessageCustomAsWell("", new EmbedBuilder().withColor(Color.CYAN)
|
ChromaBot.getInstance().sendMessageCustomAsWell("", new EmbedBuilder().withColor(Color.CYAN)
|
||||||
.withTitle("Discord plugin restarted - chat connected.").build(), ChannelconBroadcast.RESTART); //Really important to note the chat, hmm
|
.withTitle("Discord plugin restarted - chat connected.").build(), ChannelconBroadcast.RESTART); //Really important to note the chat, hmm
|
||||||
|
|
|
@ -24,7 +24,6 @@ public abstract class DiscordCommandBase {
|
||||||
commands.put("connect", new ConnectCommand()); // TODO: API for adding commands?
|
commands.put("connect", new ConnectCommand()); // TODO: API for adding commands?
|
||||||
commands.put("help", new HelpCommand());
|
commands.put("help", new HelpCommand());
|
||||||
commands.put("mcchat", new MCChatCommand());
|
commands.put("mcchat", new MCChatCommand());
|
||||||
commands.put("channelcon", new ChannelconCommand());
|
|
||||||
commands.put("debug", new DebugCommand());
|
commands.put("debug", new DebugCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,10 +63,11 @@ public class CommandListener {
|
||||||
private static boolean checkanddeletemention(StringBuilder cmdwithargs, String mention, IMessage message) {
|
private static boolean checkanddeletemention(StringBuilder cmdwithargs, String mention, IMessage message) {
|
||||||
if (message.getContent().startsWith(mention)) // TODO: Resolve mentions: Compound arguments, either a mention or text
|
if (message.getContent().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 x = mention.length(), px = x;
|
int i = cmdwithargs.indexOf(" ", mention.length());
|
||||||
while ((x = cmdwithargs.indexOf(" ", px + 1)) != -1) //Removes any space before the command
|
//noinspection StatementWithEmptyBody
|
||||||
px = x;
|
for (; i < cmdwithargs.length() && cmdwithargs.charAt(i) == ' '; i++)
|
||||||
cmdwithargs.delete(0, px + 1);
|
; //Removes any space before the command
|
||||||
|
cmdwithargs.delete(0, i);
|
||||||
cmdwithargs.insert(0, DiscordPlugin.getPrefix()); //Always use the prefix for processing
|
cmdwithargs.insert(0, DiscordPlugin.getPrefix()); //Always use the prefix for processing
|
||||||
} else
|
} else
|
||||||
cmdwithargs.replace(0, cmdwithargs.length(), DiscordPlugin.getPrefix() + "help");
|
cmdwithargs.replace(0, cmdwithargs.length(), DiscordPlugin.getPrefix() + "help");
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package buttondevteam.discordplugin.commands;
|
package buttondevteam.discordplugin.mcchat;
|
||||||
|
|
||||||
import buttondevteam.core.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
|
import buttondevteam.core.component.channel.ChatRoom;
|
||||||
import buttondevteam.discordplugin.*;
|
import buttondevteam.discordplugin.*;
|
||||||
import buttondevteam.discordplugin.mcchat.MCChatCustom;
|
import buttondevteam.discordplugin.commands.Command2DCSender;
|
||||||
|
import buttondevteam.discordplugin.commands.ICommand2DC;
|
||||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||||
import buttondevteam.lib.chat.Command2;
|
import buttondevteam.lib.chat.Command2;
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
|
@ -14,12 +16,12 @@ import sx.blah.discord.handle.obj.Permissions;
|
||||||
import sx.blah.discord.util.PermissionUtils;
|
import sx.blah.discord.util.PermissionUtils;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@CommandClass(helpText = {"---- Channel connect ---", //
|
@CommandClass(helpText = {"Channel connect", //
|
||||||
"This command allows you to connect a Minecraft channel to a Discord channel (just like how the global chat is connected to #minecraft-chat).", //
|
"This command allows you to connect a Minecraft channel to a Discord channel (just like how the global chat is connected to #minecraft-chat).", //
|
||||||
"You need to have access to the MC channel and have manage permissions on the Discord channel.", //
|
"You need to have access to the MC channel and have manage permissions on the Discord channel.", //
|
||||||
"You also need to have your Minecraft account connected. In #bot use /connect <mcname>.", //
|
"You also need to have your Minecraft account connected. In #bot use /connect <mcname>.", //
|
||||||
|
@ -47,9 +49,10 @@ public class ChannelconCommand extends ICommand2DC {
|
||||||
val message = sender.getMessage();
|
val message = sender.getMessage();
|
||||||
if (checkPerms(message)) return true;
|
if (checkPerms(message)) return true;
|
||||||
val cc = MCChatCustom.getCustomChat(message.getChannel());
|
val cc = MCChatCustom.getCustomChat(message.getChannel());
|
||||||
assert cc != null; //It's not null
|
if (cc == null)
|
||||||
|
return respond(sender, "this channel isn't connected.");
|
||||||
Supplier<String> togglesString = () -> Arrays.stream(ChannelconBroadcast.values()).map(t -> t.toString().toLowerCase() + ": " + ((cc.toggles & t.flag) == 0 ? "disabled" : "enabled")).collect(Collectors.joining("\n"))
|
Supplier<String> togglesString = () -> Arrays.stream(ChannelconBroadcast.values()).map(t -> t.toString().toLowerCase() + ": " + ((cc.toggles & t.flag) == 0 ? "disabled" : "enabled")).collect(Collectors.joining("\n"))
|
||||||
+ "\n\n" + TBMCSystemChatEvent.BroadcastTarget.stream().map(TBMCSystemChatEvent.BroadcastTarget::getName).collect(Collectors.joining("\n"));
|
+ "\n\n" + TBMCSystemChatEvent.BroadcastTarget.stream().map(target -> target.getName() + ": " + (cc.brtoggles.contains(target) ? "enabled" : "disabled")).collect(Collectors.joining("\n"));
|
||||||
if (toggle == null) {
|
if (toggle == null) {
|
||||||
message.reply("toggles:\n" + togglesString.get());
|
message.reply("toggles:\n" + togglesString.get());
|
||||||
return true;
|
return true;
|
||||||
|
@ -82,14 +85,14 @@ public class ChannelconCommand extends ICommand2DC {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command2.Subcommand
|
@Command2.Subcommand
|
||||||
public boolean def(Command2DCSender sender, String args) {
|
public boolean def(Command2DCSender sender, String channelID) {
|
||||||
val message = sender.getMessage();
|
val message = sender.getMessage();
|
||||||
if (checkPerms(message)) return true;
|
if (checkPerms(message)) return true;
|
||||||
if (MCChatCustom.hasCustomChat(message.getChannel()))
|
if (MCChatCustom.hasCustomChat(message.getChannel()))
|
||||||
return respond(sender, "this channel is already connected to a Minecraft channel. Use `@ChromaBot channelcon remove` to remove it.");
|
return respond(sender, "this channel is already connected to a Minecraft channel. Use `@ChromaBot channelcon remove` to remove it.");
|
||||||
val chan = Channel.getChannels().filter(ch -> ch.ID.equalsIgnoreCase(args) || (Arrays.stream(ch.IDs().get()).anyMatch(cid -> cid.equalsIgnoreCase(args)))).findAny();
|
val chan = Channel.getChannels().filter(ch -> ch.ID.equalsIgnoreCase(channelID) || (Arrays.stream(ch.IDs().get()).anyMatch(cid -> cid.equalsIgnoreCase(channelID)))).findAny();
|
||||||
if (!chan.isPresent()) { //TODO: Red embed that disappears over time (kinda like the highlight messages in OW)
|
if (!chan.isPresent()) { //TODO: Red embed that disappears over time (kinda like the highlight messages in OW)
|
||||||
message.reply("MC channel with ID '" + args + "' not found! The ID is the command for it without the /.");
|
message.reply("MC channel with ID '" + channelID + "' not found! The ID is the command for it without the /.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
val dp = DiscordPlayer.getUser(message.getAuthor().getStringID(), DiscordPlayer.class);
|
val dp = DiscordPlayer.getUser(message.getAuthor().getStringID(), DiscordPlayer.class);
|
||||||
|
@ -101,15 +104,22 @@ public class ChannelconCommand extends ICommand2DC {
|
||||||
DiscordConnectedPlayer dcp = new DiscordConnectedPlayer(message.getAuthor(), message.getChannel(), chp.getUUID(), Bukkit.getOfflinePlayer(chp.getUUID()).getName());
|
DiscordConnectedPlayer dcp = new DiscordConnectedPlayer(message.getAuthor(), message.getChannel(), chp.getUUID(), Bukkit.getOfflinePlayer(chp.getUUID()).getName());
|
||||||
//Using a fake player with no login/logout, should be fine for this event
|
//Using a fake player with no login/logout, should be fine for this event
|
||||||
String groupid = chan.get().getGroupID(dcp);
|
String groupid = chan.get().getGroupID(dcp);
|
||||||
if (groupid == null) {
|
if (groupid == null && !(chan.get() instanceof ChatRoom)) { //ChatRooms don't allow it unless the user joins, which happens later
|
||||||
message.reply("sorry, that didn't work. You cannot use that Minecraft channel.");
|
message.reply("sorry, you cannot use that Minecraft channel.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (chan.get() instanceof ChatRoom) { //ChatRooms don't work well
|
||||||
|
message.reply("chat rooms are not supported yet.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/*if (MCChatListener.getCustomChats().stream().anyMatch(cc -> cc.groupID.equals(groupid) && cc.mcchannel.ID.equals(chan.get().ID))) {
|
/*if (MCChatListener.getCustomChats().stream().anyMatch(cc -> cc.groupID.equals(groupid) && cc.mcchannel.ID.equals(chan.get().ID))) {
|
||||||
message.reply("sorry, this MC chat is already connected to a different channel, multiple channels are not supported atm.");
|
message.reply("sorry, this MC chat is already connected to a different channel, multiple channels are not supported atm.");
|
||||||
return true;
|
return true;
|
||||||
}*/ //TODO: "Channel admins" that can connect channels?
|
}*/ //TODO: "Channel admins" that can connect channels?
|
||||||
MCChatCustom.addCustomChat(message.getChannel(), groupid, chan.get(), message.getAuthor(), dcp, 0, new ArrayList<>());
|
MCChatCustom.addCustomChat(message.getChannel(), groupid, chan.get(), message.getAuthor(), dcp, 0, new HashSet<>());
|
||||||
|
if (chan.get() instanceof ChatRoom)
|
||||||
|
message.reply("alright, connection made to the room!");
|
||||||
|
else
|
||||||
message.reply("alright, connection made to group `" + groupid + "`!");
|
message.reply("alright, connection made to group `" + groupid + "`!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -123,9 +133,9 @@ public class ChannelconCommand extends ICommand2DC {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getHelpText(Method method) {
|
public String[] getHelpText(Method method, Command2.Subcommand ann) {
|
||||||
return new String[]{ //
|
return new String[]{ //
|
||||||
"---- Channel connect ---", //
|
"Channel connect", //
|
||||||
"This command allows you to connect a Minecraft channel to a Discord channel (just like how the global chat is connected to #minecraft-chat).", //
|
"This command allows you to connect a Minecraft channel to a Discord channel (just like how the global chat is connected to #minecraft-chat).", //
|
||||||
"You need to have access to the MC channel and have manage permissions on the Discord channel.", //
|
"You need to have access to the MC channel and have manage permissions on the Discord channel.", //
|
||||||
"You also need to have your Minecraft account connected. In " + DPUtils.botmention() + " use " + DiscordPlugin.getPrefix() + "connect <mcname>.", //
|
"You also need to have your Minecraft account connected. In " + DPUtils.botmention() + " use " + DiscordPlugin.getPrefix() + "connect <mcname>.", //
|
|
@ -1,6 +1,7 @@
|
||||||
package buttondevteam.discordplugin.mcchat;
|
package buttondevteam.discordplugin.mcchat;
|
||||||
|
|
||||||
import buttondevteam.core.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
|
import buttondevteam.core.component.channel.ChatRoom;
|
||||||
import buttondevteam.discordplugin.DiscordConnectedPlayer;
|
import buttondevteam.discordplugin.DiscordConnectedPlayer;
|
||||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -12,6 +13,7 @@ import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MCChatCustom {
|
public class MCChatCustom {
|
||||||
/**
|
/**
|
||||||
|
@ -19,7 +21,11 @@ public class MCChatCustom {
|
||||||
*/
|
*/
|
||||||
static ArrayList<CustomLMD> lastmsgCustom = new ArrayList<>();
|
static ArrayList<CustomLMD> lastmsgCustom = new ArrayList<>();
|
||||||
|
|
||||||
public static void addCustomChat(IChannel channel, String groupid, Channel mcchannel, IUser user, DiscordConnectedPlayer dcp, int toggles, List<TBMCSystemChatEvent.BroadcastTarget> brtoggles) {
|
public static void addCustomChat(IChannel channel, String groupid, Channel mcchannel, IUser user, DiscordConnectedPlayer dcp, int toggles, Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles) {
|
||||||
|
if (mcchannel instanceof ChatRoom) {
|
||||||
|
((ChatRoom) mcchannel).joinRoom(dcp);
|
||||||
|
if (groupid == null) groupid = mcchannel.getGroupID(dcp);
|
||||||
|
}
|
||||||
val lmd = new CustomLMD(channel, user, groupid, mcchannel, dcp, toggles, brtoggles);
|
val lmd = new CustomLMD(channel, user, groupid, mcchannel, dcp, toggles, brtoggles);
|
||||||
lastmsgCustom.add(lmd);
|
lastmsgCustom.add(lmd);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +41,13 @@ public class MCChatCustom {
|
||||||
|
|
||||||
public static boolean removeCustomChat(IChannel channel) {
|
public static boolean removeCustomChat(IChannel channel) {
|
||||||
MCChatUtils.lastmsgfromd.remove(channel.getLongID());
|
MCChatUtils.lastmsgfromd.remove(channel.getLongID());
|
||||||
return lastmsgCustom.removeIf(lmd -> lmd.channel.getLongID() == channel.getLongID());
|
return lastmsgCustom.removeIf(lmd -> {
|
||||||
|
if (lmd.channel.getLongID() != channel.getLongID())
|
||||||
|
return false;
|
||||||
|
if (lmd.mcchannel instanceof ChatRoom)
|
||||||
|
((ChatRoom) lmd.mcchannel).leaveRoom(lmd.dcp);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<CustomLMD> getCustomChats() {
|
public static List<CustomLMD> getCustomChats() {
|
||||||
|
@ -47,10 +59,10 @@ public class MCChatCustom {
|
||||||
public final Channel mcchannel;
|
public final Channel mcchannel;
|
||||||
public final DiscordConnectedPlayer dcp;
|
public final DiscordConnectedPlayer dcp;
|
||||||
public int toggles;
|
public int toggles;
|
||||||
public List<TBMCSystemChatEvent.BroadcastTarget> brtoggles;
|
public Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles;
|
||||||
|
|
||||||
private CustomLMD(@NonNull IChannel channel, @NonNull IUser user,
|
private CustomLMD(@NonNull IChannel channel, @NonNull IUser user,
|
||||||
@NonNull String groupid, @NonNull Channel mcchannel, @NonNull DiscordConnectedPlayer dcp, int toggles, List<TBMCSystemChatEvent.BroadcastTarget> brtoggles) {
|
@NonNull String groupid, @NonNull Channel mcchannel, @NonNull DiscordConnectedPlayer dcp, int toggles, Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles) {
|
||||||
super(channel, user);
|
super(channel, user);
|
||||||
groupID = groupid;
|
groupID = groupid;
|
||||||
this.mcchannel = mcchannel;
|
this.mcchannel = mcchannel;
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class MinecraftChatModule extends Component {
|
||||||
continue;
|
continue;
|
||||||
Bukkit.getScheduler().runTask(getPlugin(), () -> { //<-- Needed because of occasional ConcurrentModificationExceptions when creating the player (PermissibleBase)
|
Bukkit.getScheduler().runTask(getPlugin(), () -> { //<-- Needed because of occasional ConcurrentModificationExceptions when creating the player (PermissibleBase)
|
||||||
val dcp = new DiscordConnectedPlayer(user, ch, UUID.fromString(chcon.getString("mcuid")), chcon.getString("mcname"));
|
val dcp = new DiscordConnectedPlayer(user, ch, UUID.fromString(chcon.getString("mcuid")), chcon.getString("mcname"));
|
||||||
MCChatCustom.addCustomChat(ch, groupid, mcch.get(), user, dcp, toggles, brtoggles.stream().map(TBMCSystemChatEvent.BroadcastTarget::get).filter(Objects::nonNull).collect(Collectors.toList()));
|
MCChatCustom.addCustomChat(ch, groupid, mcch.get(), user, dcp, toggles, brtoggles.stream().map(TBMCSystemChatEvent.BroadcastTarget::get).filter(Objects::nonNull).collect(Collectors.toSet()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue