diff --git a/discordbot/src/main/java/zone/themcgamer/discordbot/MGZBot.java b/discordbot/src/main/java/zone/themcgamer/discordbot/MGZBot.java index f11acb2..acbef76 100644 --- a/discordbot/src/main/java/zone/themcgamer/discordbot/MGZBot.java +++ b/discordbot/src/main/java/zone/themcgamer/discordbot/MGZBot.java @@ -37,7 +37,8 @@ public class MGZBot { commandClientBuilder.addCommand(new SetActivityCommand()); commandClientBuilder.addCommand(new ToggleNewsRoleCommand()); commandClientBuilder.addCommand(new InviteCommand()); - commandClientBuilder.addCommand(new SayCommand()); + commandClientBuilder.addCommand(new MessageCommand()); + commandClientBuilder.addCommand(new EditMessageCommand()); try { jda = JDABuilder.createDefault(BotConstants.TOKEN) diff --git a/discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/EditMessageCommand.java b/discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/EditMessageCommand.java new file mode 100644 index 0000000..bf55877 --- /dev/null +++ b/discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/EditMessageCommand.java @@ -0,0 +1,57 @@ +package zone.themcgamer.discordbot.command.impl; + +import com.jagrosh.jdautilities.command.CommandEvent; +import lombok.RequiredArgsConstructor; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.TextChannel; +import zone.themcgamer.discordbot.MGZBot; +import zone.themcgamer.discordbot.command.BaseCommand; +import zone.themcgamer.discordbot.guild.Guild; +import zone.themcgamer.discordbot.utilities.EmbedUtils; +import zone.themcgamer.discordbot.utilities.MessageUtils; + +import java.util.Arrays; +import java.util.List; + +public class EditMessageCommand extends BaseCommand { + + public EditMessageCommand() { + name = "edit"; + aliases = new String[]{"editmessage"}; + help = "Edit a message from the bot."; + arguments = " <description>"; + userPermissions = new Permission[] { Permission.ADMINISTRATOR }; + guildOnly = true; + guilds = Arrays.asList(Guild.MAIN, Guild.TEAM, Guild.TEST); + } + + @Override + protected void execute(CommandEvent event, List<String> args) { + if (args.size() < 3) { + MessageUtils.sendUsageMessage(event.getTextChannel(),this); + return; + } + + TextChannel textChannelById = MGZBot.getInstance().getJda().getTextChannelById(args.get(1)); + if (textChannelById == null) { + event.reply("Channel does not exist!"); + return; + } + + EmbedBuilder embedBuilder = EmbedUtils.defaultEmbed(); + embedBuilder.setTitle(args.get(3).replace("_", " ")); + embedBuilder.setDescription(event.getMessage().getContentRaw() + .replace("." + args.get(0), "") + .replace(args.get(1), "") + .replace(args.get(2), "") + .replace(args.get(3), "")); + textChannelById.editMessageById(args.get(2), embedBuilder.build()).queue(message -> { + event.replySuccess("Message has been edited!"); + }, error -> { + event.reply("Message with this ID does not exist, are you sure this is the right id?"); + }); + } +} diff --git a/discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/SayCommand.java b/discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/MessageCommand.java similarity index 90% rename from discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/SayCommand.java rename to discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/MessageCommand.java index 9283da9..9940f05 100644 --- a/discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/SayCommand.java +++ b/discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/MessageCommand.java @@ -11,11 +11,11 @@ import zone.themcgamer.discordbot.utilities.MessageUtils; import java.util.Arrays; import java.util.List; -public class SayCommand extends BaseCommand { +public class MessageCommand extends BaseCommand { - public SayCommand() { - name = "say"; - aliases = new String[]{"announce"}; + public MessageCommand() { + name = "message"; + aliases = new String[]{"say"}; help = "Announce something in an embed format."; arguments = "<title> <description>"; userPermissions = new Permission[] { Permission.ADMINISTRATOR };