Restrict reflip button to user who ran the 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
7562e956bc
commit
0da3eecd29
@ -187,6 +187,5 @@ public class ClearChatCommand
|
|||||||
{
|
{
|
||||||
event.getInteraction().getMessage().delete().queue();
|
event.getInteraction().getMessage().delete().queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
package wtf.beatrice.hidekobot.commands.slash;
|
package wtf.beatrice.hidekobot.commands.slash;
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.entities.emoji.Emoji;
|
import net.dv8tion.jda.api.entities.emoji.Emoji;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||||
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import wtf.beatrice.hidekobot.Configuration;
|
||||||
import wtf.beatrice.hidekobot.utils.RandomUtil;
|
import wtf.beatrice.hidekobot.utils.RandomUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -21,11 +24,26 @@ public class CoinFlipCommand
|
|||||||
// perform coin flip
|
// perform coin flip
|
||||||
event.reply(genRandom())
|
event.reply(genRandom())
|
||||||
.addActionRow(reflipButton)
|
.addActionRow(reflipButton)
|
||||||
.queue();
|
.queue((interaction) ->
|
||||||
|
{
|
||||||
|
// set the command as expiring and restrict it to the user who ran it
|
||||||
|
interaction.retrieveOriginal().queue((message) ->
|
||||||
|
{
|
||||||
|
trackAndRestrict(message, event.getUser());
|
||||||
|
}, (error) -> {});
|
||||||
|
}, (error) -> {});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buttonReFlip(ButtonInteractionEvent event)
|
public void buttonReFlip(ButtonInteractionEvent event)
|
||||||
{
|
{
|
||||||
|
// check if the user interacting is the same one who ran the command
|
||||||
|
if(!(Configuration.getDatabaseManager().isUserTrackedFor(event.getUser().getId(), event.getMessageId())))
|
||||||
|
{
|
||||||
|
event.reply("❌ You did not run this command!").setEphemeral(true).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// set old message's button as disabled
|
// set old message's button as disabled
|
||||||
List<ActionRow> actionRows = event.getMessage().getActionRows();
|
List<ActionRow> actionRows = event.getMessage().getActionRows();
|
||||||
actionRows.set(0, actionRows.get(0).asDisabled());
|
actionRows.set(0, actionRows.get(0).asDisabled());
|
||||||
@ -34,7 +52,22 @@ public class CoinFlipCommand
|
|||||||
// perform coin flip
|
// perform coin flip
|
||||||
event.getHook().sendMessage(genRandom())
|
event.getHook().sendMessage(genRandom())
|
||||||
.addActionRow(reflipButton)
|
.addActionRow(reflipButton)
|
||||||
.queue();
|
.queue((message) ->
|
||||||
|
{
|
||||||
|
// set the command as expiring and restrict it to the user who ran it
|
||||||
|
trackAndRestrict(message, event.getUser());
|
||||||
|
}, (error) -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void trackAndRestrict(Message replyMessage, User user)
|
||||||
|
{
|
||||||
|
String replyMessageId = replyMessage.getId();
|
||||||
|
String replyChannelId = replyMessage.getId();
|
||||||
|
String replyGuildId = replyMessage.getGuild().getId();
|
||||||
|
String userId = user.getId();
|
||||||
|
|
||||||
|
Configuration.getDatabaseManager().queueDisabling(replyGuildId, replyChannelId, replyMessageId);
|
||||||
|
Configuration.getDatabaseManager().trackRanCommandReply(replyGuildId, replyChannelId, replyMessageId, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String genRandom()
|
private String genRandom()
|
||||||
|
Loading…
Reference in New Issue
Block a user