2022-11-20 18:56:57 +01:00
|
|
|
package wtf.beatrice.hidekobot.commands.slash;
|
2022-11-20 16:07:04 +01:00
|
|
|
|
2022-11-21 16:11:16 +01:00
|
|
|
import net.dv8tion.jda.api.EmbedBuilder;
|
|
|
|
import net.dv8tion.jda.api.entities.Message;
|
2022-11-20 16:20:50 +01:00
|
|
|
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
2022-11-21 16:11:16 +01:00
|
|
|
import net.dv8tion.jda.api.entities.emoji.Emoji;
|
2022-11-20 16:07:04 +01:00
|
|
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
2022-11-22 16:39:31 +01:00
|
|
|
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
|
|
|
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
2022-11-21 16:11:16 +01:00
|
|
|
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
|
|
|
import net.dv8tion.jda.api.requests.restaction.WebhookMessageEditAction;
|
2022-11-20 16:20:50 +01:00
|
|
|
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
|
2022-11-20 16:07:04 +01:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2022-11-21 20:20:11 +01:00
|
|
|
import wtf.beatrice.hidekobot.Cache;
|
2022-11-21 16:11:16 +01:00
|
|
|
import wtf.beatrice.hidekobot.HidekoBot;
|
2022-11-22 16:39:31 +01:00
|
|
|
import wtf.beatrice.hidekobot.objects.SlashCommandImpl;
|
2022-11-20 16:07:04 +01:00
|
|
|
|
2022-11-22 16:39:31 +01:00
|
|
|
public class InviteCommand extends SlashCommandImpl
|
2022-11-20 16:07:04 +01:00
|
|
|
{
|
2022-11-22 14:32:22 +01:00
|
|
|
|
|
|
|
@Override
|
2022-11-22 16:39:31 +01:00
|
|
|
public CommandData getSlashCommandData()
|
|
|
|
{
|
|
|
|
return Commands.slash("invite", "Get an invite link for the bot.");
|
2022-11-22 14:32:22 +01:00
|
|
|
}
|
|
|
|
|
2022-11-22 16:39:31 +01:00
|
|
|
|
2022-11-22 14:32:22 +01:00
|
|
|
@Override
|
2022-11-20 22:09:58 +01:00
|
|
|
public void runSlashCommand(@NotNull SlashCommandInteractionEvent event)
|
2022-11-20 16:07:04 +01:00
|
|
|
{
|
2022-11-21 16:11:16 +01:00
|
|
|
// defer reply because this might take a moment
|
|
|
|
ReplyCallbackAction replyCallbackAction = event.deferReply();
|
2022-11-20 16:20:50 +01:00
|
|
|
// only make message permanent in DMs
|
2022-11-21 16:11:16 +01:00
|
|
|
if(event.getChannelType() != ChannelType.PRIVATE)
|
2022-11-20 16:20:50 +01:00
|
|
|
{
|
2022-11-21 16:11:16 +01:00
|
|
|
replyCallbackAction = replyCallbackAction.setEphemeral(true);
|
2022-11-20 16:20:50 +01:00
|
|
|
}
|
2022-11-21 16:11:16 +01:00
|
|
|
replyCallbackAction.queue();
|
|
|
|
|
|
|
|
EmbedBuilder embedBuilder = new EmbedBuilder();
|
|
|
|
|
|
|
|
//embed processing
|
|
|
|
{
|
2022-11-21 20:20:11 +01:00
|
|
|
embedBuilder.setColor(Cache.getBotColor());
|
2022-11-21 16:11:16 +01:00
|
|
|
String avatarUrl = HidekoBot.getAPI().getSelfUser().getAvatarUrl();
|
|
|
|
if(avatarUrl != null) embedBuilder.setThumbnail(avatarUrl);
|
|
|
|
embedBuilder.setTitle("Invite");
|
|
|
|
embedBuilder.appendDescription("Click on the button below to invite " +
|
2022-11-21 20:20:11 +01:00
|
|
|
Cache.getBotName() +
|
2022-11-21 16:11:16 +01:00
|
|
|
" to your server!");
|
|
|
|
}
|
|
|
|
|
2022-11-21 20:20:11 +01:00
|
|
|
String inviteUrl = Cache.getInviteUrl();
|
|
|
|
Button inviteButton = Button.link(inviteUrl, "Invite " + Cache.getBotName())
|
2022-11-21 16:24:21 +01:00
|
|
|
.withEmoji(Emoji.fromUnicode("\uD83C\uDF1F"));
|
2022-11-21 16:11:16 +01:00
|
|
|
|
|
|
|
WebhookMessageEditAction<Message> reply =
|
|
|
|
event.getHook()
|
|
|
|
.editOriginalEmbeds(embedBuilder.build())
|
|
|
|
.setActionRow(inviteButton);
|
2022-11-20 16:20:50 +01:00
|
|
|
|
|
|
|
reply.queue();
|
2022-11-20 16:07:04 +01:00
|
|
|
}
|
|
|
|
}
|