Implement basic say command
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
4382f7d490
commit
b35b962ac6
@ -6,13 +6,10 @@ import net.dv8tion.jda.api.interactions.commands.Command;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import wtf.beatrice.hidekobot.Configuration;
|
import wtf.beatrice.hidekobot.Configuration;
|
||||||
import wtf.beatrice.hidekobot.HidekoBot;
|
import wtf.beatrice.hidekobot.HidekoBot;
|
||||||
import wtf.beatrice.hidekobot.utils.TimeUtil;
|
import wtf.beatrice.hidekobot.utils.FormatUtil;
|
||||||
|
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.time.Duration;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BotInfoCommand
|
public class BotInfoCommand
|
||||||
@ -75,12 +72,12 @@ public class BotInfoCommand
|
|||||||
embedBuilder.addField("Author", authorMention, true);
|
embedBuilder.addField("Author", authorMention, true);
|
||||||
|
|
||||||
// uptime field
|
// uptime field
|
||||||
embedBuilder.addField("Uptime", TimeUtil.getNiceUptime(), true);
|
embedBuilder.addField("Uptime", FormatUtil.getNiceUptime(), true);
|
||||||
|
|
||||||
// issue tracker field
|
// issue tracker field
|
||||||
embedBuilder.addField("Support",
|
embedBuilder.addField("Support",
|
||||||
"[Issue tracker](https://git.beatrice.wtf/mind-overflow/HidekoBot/issues)",
|
"[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();
|
event.getHook().editOriginalEmbeds(embedBuilder.build()).queue();
|
||||||
|
@ -38,8 +38,8 @@ public class ClearChatCommand
|
|||||||
/* get the amount from the command args.
|
/* get the amount from the command args.
|
||||||
NULL should not be possible because we specified them as mandatory,
|
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. */
|
but apparently the mobile app doesn't care and still sends the command if you omit the args. */
|
||||||
OptionMapping amountMapping = event.getOption("amount");
|
OptionMapping amountOption = event.getOption("amount");
|
||||||
int toDeleteAmount = amountMapping == null ? 1 : amountMapping.getAsInt();
|
int toDeleteAmount = amountOption == null ? 1 : amountOption.getAsInt();
|
||||||
|
|
||||||
if(toDeleteAmount <= 0)
|
if(toDeleteAmount <= 0)
|
||||||
{
|
{
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,7 @@ public class SlashCommandListener extends ListenerAdapter
|
|||||||
case "help" -> new HelpCommand().runSlashCommand(event);
|
case "help" -> new HelpCommand().runSlashCommand(event);
|
||||||
case "invite" -> new InviteCommand().runSlashCommand(event);
|
case "invite" -> new InviteCommand().runSlashCommand(event);
|
||||||
case "ping" -> new PingCommand().runSlashCommand(event);
|
case "ping" -> new PingCommand().runSlashCommand(event);
|
||||||
|
case "say" -> new SayCommand().runSlashCommand(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,12 @@ import java.time.Duration;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
|
||||||
public class TimeUtil
|
public class FormatUtil
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a nicely formatted uptime String that omits unnecessary data
|
* 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
|
* @return the formatter String
|
||||||
*/
|
*/
|
@ -34,6 +34,9 @@ public class SlashCommandUtil
|
|||||||
add(Commands.slash("help", "Get general help on the bot."));
|
add(Commands.slash("help", "Get general help on the bot."));
|
||||||
add(Commands.slash("invite", "Get an invite link for 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("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)
|
public static void updateSlashCommands(boolean force)
|
||||||
|
Loading…
Reference in New Issue
Block a user