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 cc.fascinated.bat.model.BatUser;
import lombok.NonNull; import lombok.NonNull;
import net.dv8tion.jda.api.entities.Member; 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.MessageEmbed;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
@ -47,6 +48,13 @@ public class ListSubCommand extends BatCommand implements EventListener {
return; 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 // Home
if (event.getComponentId().equals("logs-home")) { if (event.getComponentId().equals("logs-home")) {
event.editMessageEmbeds(getHelpMessage()).queue(); event.editMessageEmbeds(getHelpMessage()).queue();

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