fix invite log channel
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m2s

This commit is contained in:
Lee 2024-07-04 14:36:07 +01:00
parent 0d9b6ed8f8
commit 7bf468b470
2 changed files with 22 additions and 11 deletions

@ -13,6 +13,7 @@ import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import lombok.NonNull;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
@ -47,6 +48,13 @@ public class ListSubCommand extends BatCommand implements EventListener {
return;
}
// The person who clicked the button is not the person who executed the command
Message referencedMessage = event.getMessage().getReferencedMessage();
if (referencedMessage != null && !referencedMessage.getAuthor().getId().equals(user.getId())) {
event.reply("%s, you cannot use this button.".formatted(user.getDiscordUser().getAsMention())).setEphemeral(true).queue();
return;
}
// Home
if (event.getComponentId().equals("logs-home")) {
event.editMessageEmbeds(getHelpMessage()).queue();

@ -9,6 +9,7 @@ import cc.fascinated.bat.model.BatGuild;
import lombok.NonNull;
import lombok.extern.log4j.Log4j2;
import net.dv8tion.jda.api.entities.Invite;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.events.guild.invite.GuildInviteCreateEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
@ -31,19 +32,21 @@ public class GuildListener implements EventListener {
public void onGuildInviteCreate(@NonNull BatGuild guild, @NonNull Invite invite, @NonNull GuildInviteCreateEvent event) {
log.info("Invite created in guild \"{}\" with code \"{}\"", guild.getGuild().getName(), invite.getCode());
guild.getDiscordGuild().retrieveInvites().queue(invites -> {
Invite newInvite = invites.stream().filter(i -> i.getCode().equals(invite.getCode())).findFirst().orElse(null);
if (newInvite == null) {
return;
invite.expand().queue(expandedInvite -> {
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Invite Created");
description.appendLine("Invite: %s".formatted(expandedInvite.getUrl()), true);
if (expandedInvite.getChannel() != null) {
description.appendLine("Channel: %s".formatted(
expandedInvite.getChannel().getType() == ChannelType.TEXT ?
"<#%s>".formatted(expandedInvite.getChannel().getId()) : expandedInvite.getChannel().getName()
), true);
}
newInvite.expand().queue(expanded -> logFeature.sendLog(guild, LogType.INVITE_CREATE, EmbedUtils.successEmbed()
.setDescription(new EmbedDescriptionBuilder("Invite Created")
.appendLine("Invite: %s".formatted(expanded.getUrl()), true)
.appendLine("Channel: %s".formatted(expanded.getChannel()), true)
.appendLine("Max Uses: `%s`".formatted(expanded.getMaxUses() == 0 ? "Infinite" : expanded.getMaxUses()), true)
.appendLine("Creator: %s".formatted(expanded.getInviter() == null ? "Unknown" : expanded.getInviter().getAsMention()), true)
description.appendLine("Max Uses: `%s`".formatted(expandedInvite.getMaxUses() == 0 ? "Infinite" : expandedInvite.getMaxUses()), true);
description.appendLine("Creator: %s".formatted(expandedInvite.getInviter() == null ? "Unknown" : expandedInvite.getInviter().getAsMention()), true);;
logFeature.sendLog(guild, LogType.INVITE_CREATE, EmbedUtils.successEmbed()
.setDescription(description
.build())
.build()));
.build());
});
}
}