Added SayCommand

This commit is contained in:
Joel 2021-02-20 02:16:51 +01:00
parent d3362b9f91
commit d79a13fa2d
5 changed files with 62 additions and 12 deletions

@ -7,10 +7,7 @@ import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.requests.GatewayIntent;
import zone.themcgamer.discordbot.command.impl.InviteCommand;
import zone.themcgamer.discordbot.command.impl.SetActivityCommand;
import zone.themcgamer.discordbot.command.impl.SuggestCommand;
import zone.themcgamer.discordbot.command.impl.ToggleNewsRoleCommand;
import zone.themcgamer.discordbot.command.impl.*;
import zone.themcgamer.discordbot.events.GuildMemberJoinQuitListener;
import javax.security.auth.login.LoginException;
@ -39,6 +36,7 @@ public class MGZBot {
commandClientBuilder.addCommand(new SetActivityCommand());
commandClientBuilder.addCommand(new ToggleNewsRoleCommand());
commandClientBuilder.addCommand(new InviteCommand());
commandClientBuilder.addCommand(new SayCommand());
try {
jda = JDABuilder.createDefault(BotConstants.TOKEN)

@ -0,0 +1,41 @@
package zone.themcgamer.discordbot.command.impl;
import com.jagrosh.jdautilities.command.CommandEvent;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;
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;
import java.util.stream.Collectors;
public class SayCommand extends BaseCommand {
public SayCommand() {
name = "say";
aliases = new String[]{"announce"};
help = "Announce something in an embed format.";
arguments = "<title> <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() < 1) {
MessageUtils.sendUsageMessage(event.getTextChannel(),this);
return;
}
//TODO a way to add images, and such to the embeds.
String description = args.stream().skip(2).collect(Collectors.joining(" "));
EmbedBuilder embedBuilder = EmbedUtils.defaultEmbed();
embedBuilder.setTitle(args.get(1));
embedBuilder.setDescription(description);
event.getChannel().sendMessage(embedBuilder.build()).queue();
}
}

@ -8,6 +8,7 @@ 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;
@ -29,10 +30,7 @@ public class SetActivityCommand extends BaseCommand {
@Override
protected void execute(CommandEvent event, List<String> args) {
if (args.size() < 1) {
event.getChannel().sendMessage(EmbedUtils.errorEmbed()
.appendDescription("Usage: " + BotConstants.PREFIX + name + " " + arguments)
.build()
).queue();
MessageUtils.sendUsageMessage(event.getTextChannel(),this);
return;
}
String activity = args.stream().skip(1).collect(Collectors.joining(" "));

@ -7,6 +7,7 @@ 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.Collections;
import java.util.List;
@ -28,10 +29,7 @@ public class SuggestCommand extends BaseCommand {
@Override
protected void execute(CommandEvent event, List<String> args) {
if (args.size() < 1) {
event.getChannel().sendMessage(EmbedUtils.errorEmbed()
.appendDescription("Usage: " + BotConstants.PREFIX + name + " " + arguments)
.build()
).queue();
MessageUtils.sendUsageMessage(event.getTextChannel(),this);
return;
}
TextChannel channel = MGZBot.getInstance().getJda().getTextChannelById(BotConstants.SUGGESTIONS);

@ -0,0 +1,15 @@
package zone.themcgamer.discordbot.utilities;
import net.dv8tion.jda.api.entities.TextChannel;
import zone.themcgamer.discordbot.BotConstants;
import zone.themcgamer.discordbot.command.BaseCommand;
public class MessageUtils {
public static void sendUsageMessage(TextChannel textChannel, BaseCommand command) {
textChannel.sendMessage(EmbedUtils.errorEmbed()
.appendDescription("Usage: " + BotConstants.PREFIX + command.getName() + " " + command.getArguments())
.build()
).queue();
}
}