Implement basic say command
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Bea 2022-11-21 15:37:12 +01:00
parent 4382f7d490
commit b35b962ac6
6 changed files with 47 additions and 10 deletions

View File

@ -6,13 +6,10 @@ import net.dv8tion.jda.api.interactions.commands.Command;
import org.jetbrains.annotations.NotNull;
import wtf.beatrice.hidekobot.Configuration;
import wtf.beatrice.hidekobot.HidekoBot;
import wtf.beatrice.hidekobot.utils.TimeUtil;
import wtf.beatrice.hidekobot.utils.FormatUtil;
import java.lang.management.ManagementFactory;
import java.text.DecimalFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
public class BotInfoCommand
@ -75,12 +72,12 @@ public class BotInfoCommand
embedBuilder.addField("Author", authorMention, true);
// uptime field
embedBuilder.addField("Uptime", TimeUtil.getNiceUptime(), true);
embedBuilder.addField("Uptime", FormatUtil.getNiceUptime(), true);
// issue tracker field
embedBuilder.addField("Support",
"[Issue tracker](https://git.beatrice.wtf/mind-overflow/HidekoBot/issues)",
true);
true); //todo: we should probably make this a final field in the config class
}
event.getHook().editOriginalEmbeds(embedBuilder.build()).queue();

View File

@ -38,8 +38,8 @@ public class ClearChatCommand
/* get the amount from the command args.
NULL should not be possible because we specified them as mandatory,
but apparently the mobile app doesn't care and still sends the command if you omit the args. */
OptionMapping amountMapping = event.getOption("amount");
int toDeleteAmount = amountMapping == null ? 1 : amountMapping.getAsInt();
OptionMapping amountOption = event.getOption("amount");
int toDeleteAmount = amountOption == null ? 1 : amountOption.getAsInt();
if(toDeleteAmount <= 0)
{

View File

@ -0,0 +1,36 @@
package wtf.beatrice.hidekobot.commands.slash;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import org.jetbrains.annotations.NotNull;
public class SayCommand
{
public void runSlashCommand(@NotNull SlashCommandInteractionEvent event)
{
MessageChannel channel = event.getChannel();
// get the text to send
OptionMapping textOption = event.getOption("text");
String messageContent = "";
if(textOption != null)
{
messageContent = textOption.getAsString();
}
if(textOption == null || messageContent.isEmpty())
{
event.reply("Hey, you have to tell me what to say!")
.setEphemeral(true)
.queue();
return;
}
channel.sendMessage(messageContent).queue();
event.reply("Message sent!")
.setEphemeral(true)
.queue();
}
}

View File

@ -20,6 +20,7 @@ public class SlashCommandListener extends ListenerAdapter
case "help" -> new HelpCommand().runSlashCommand(event);
case "invite" -> new InviteCommand().runSlashCommand(event);
case "ping" -> new PingCommand().runSlashCommand(event);
case "say" -> new SayCommand().runSlashCommand(event);
}
}
}

View File

@ -6,12 +6,12 @@ import java.time.Duration;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
public class TimeUtil
public class FormatUtil
{
/**
* Generate a nicely formatted uptime String that omits unnecessary data
* (eg. 0 days, 0 hours, 4 minutes, 32 seconds -> 4m 32s)
* (e.g. 0 days, 0 hours, 4 minutes, 32 seconds -> 4m 32s)
*
* @return the formatter String
*/

View File

@ -34,6 +34,9 @@ public class SlashCommandUtil
add(Commands.slash("help", "Get general help on the bot."));
add(Commands.slash("invite", "Get an invite link for the bot."));
add(Commands.slash("ping", "Test if the bot is responsive."));
add(Commands.slash("say", "Make the bot say something.")
.addOption(OptionType.STRING, "text", "The message to send.", true, false)
.setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.MESSAGE_MANAGE)));
}};
public static void updateSlashCommands(boolean force)