Fixed lowercase cmds & channel mentions
Fixed commands from private mcchat being lowercased Added channel mention support (#51) Added version command (#51)
This commit is contained in:
parent
12a21461c0
commit
d79b1674eb
6 changed files with 67 additions and 5 deletions
|
@ -27,6 +27,7 @@ public abstract class DiscordCommandBase {
|
|||
commands.put("mcchat", new MCChatCommand());
|
||||
commands.put("channelcon", new ChannelconCommand());
|
||||
commands.put("debug", new DebugCommand());
|
||||
commands.put("version", new VersionCommand());
|
||||
}
|
||||
|
||||
public static void runCommand(String cmd, String args, IMessage message) {
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import lombok.val;
|
||||
import sx.blah.discord.handle.obj.IMessage;
|
||||
|
||||
public class VersionCommand extends DiscordCommandBase {
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "version";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean run(IMessage message, String args) {
|
||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), String.join("\n", getVersion()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getHelpText() {
|
||||
return VersionCommand.getVersion(); //Heh
|
||||
}
|
||||
|
||||
public static String[] getVersion() {
|
||||
val desc = DiscordPlugin.plugin.getDescription();
|
||||
return new String[]{ //
|
||||
desc.getFullName(), //
|
||||
desc.getWebsite() //
|
||||
};
|
||||
}
|
||||
}
|
|
@ -477,6 +477,9 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
final String nick = u.getNicknameForGuild(DiscordPlugin.mainServer);
|
||||
dmessage = dmessage.replace(u.mention(true), "@" + (nick != null ? nick : u.getName()));
|
||||
}
|
||||
for (IChannel ch : event.getMessage().getChannelMentions()) {
|
||||
dmessage = dmessage.replace(ch.mention(), "#" + ch.getName()); // TODO: IG Formatting
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -496,7 +499,8 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
event.getMessage().delete();
|
||||
});
|
||||
//preprocessChat(dsender, dmessage); - Same is done below
|
||||
final String cmdlowercased = dmessage.substring(1).toLowerCase();
|
||||
final String cmd = dmessage.substring(1);
|
||||
final String cmdlowercased = cmd.toLowerCase();
|
||||
if (dsender instanceof DiscordSender && Arrays.stream(UnconnectedCmds)
|
||||
.noneMatch(s -> cmdlowercased.equals(s) || cmdlowercased.startsWith(s + " "))) {
|
||||
// Command not whitelisted
|
||||
|
@ -529,7 +533,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
if (!ch.isPresent())
|
||||
Bukkit.getScheduler().runTask(DiscordPlugin.plugin,
|
||||
() -> {
|
||||
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmdlowercased);
|
||||
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd);
|
||||
Bukkit.getLogger().info(dsender.getName() + " issued command from Discord: /" + cmdlowercased);
|
||||
});
|
||||
else {
|
||||
|
@ -552,7 +556,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
dsender.sendMessage("You're now talking in: "
|
||||
+ DPUtils.sanitizeString(dsender.getMcchannel().DisplayName));
|
||||
} else { // Send single message
|
||||
final String msg = event.getMessage().getContent().substring(spi + 2);
|
||||
final String msg = cmd.substring(spi + 1);
|
||||
val cmb = ChatMessage.builder(chc, dsender, user, getChatMessage.apply(msg)).fromCommand(true);
|
||||
if (clmd == null)
|
||||
TBMCChatAPI.SendChatMessage(cmb.build());
|
||||
|
|
|
@ -162,6 +162,11 @@ public class MCListener implements Listener {
|
|||
MCChatListener.sendSystemMessageToChat(event.getMessage());
|
||||
}
|
||||
|
||||
/*@EventHandler
|
||||
public void onYEEHAW(TBMCYEEHAWEvent event) {
|
||||
MCChatListener.forAllowedCustomMCChat();event.getSender().getName()+" <:YEEHAW:"+DiscordPlugin.mainServer.getEmojiByName("YEEHAW").getStringID()+">s"//TODO: :YEEHAW:s - Change from broadcastMessage() in ButtonChat
|
||||
}*/
|
||||
|
||||
private static final String[] EXCLUDED_PLUGINS = {"ProtocolLib", "LibsDisguises"};
|
||||
|
||||
public static void callEventExcludingSome(Event event) {
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package buttondevteam.discordplugin.mccommands;
|
||||
|
||||
import buttondevteam.discordplugin.commands.VersionCommand;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@CommandClass(path = "discord version")
|
||||
public class VersionMCCommand extends TBMCCommandBase {
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender commandSender, String s, String[] strings) {
|
||||
commandSender.sendMessage(VersionCommand.getVersion());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String s) {
|
||||
return VersionCommand.getVersion(); //Heh
|
||||
}
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
name: DiscordPlugin
|
||||
main: buttondevteam.discordplugin.DiscordPlugin
|
||||
version: 1.0
|
||||
author: TBMCPlugins
|
||||
author: NorbiPeti
|
||||
depend: [ButtonCore]
|
||||
commands:
|
||||
discord:
|
||||
website: 'https://github.com/TBMCPlugins/DiscordPlugin'
|
||||
|
|
Loading…
Reference in a new issue