fix welcomer placeholders and fix channel command

This commit is contained in:
Lee 2024-07-03 22:10:35 +01:00
parent 271a1cf88d
commit c2e447f416
3 changed files with 20 additions and 7 deletions

@ -27,6 +27,6 @@ public class WelcomerListener implements EventListener {
}
WelcomerProfile profile = guild.getWelcomerProfile();
profile.sendWelcomeMessage(user);
profile.sendWelcomeMessage(guild, user);
}
}

@ -1,6 +1,7 @@
package cc.fascinated.bat.features.welcomer;
import cc.fascinated.bat.common.Serializable;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.service.DiscordService;
import com.google.gson.Gson;
@ -72,9 +73,10 @@ public class WelcomerProfile extends Serializable {
/**
* Sends the welcome message to the user
*
* @param guild The guild to send the message in
* @param user The user to send the message to
*/
public void sendWelcomeMessage(BatUser user) {
public void sendWelcomeMessage(BatGuild guild, BatUser user) {
if (this.channel == null || (!this.isMessage() && !this.isEmbed())) {
return;
}
@ -82,11 +84,11 @@ public class WelcomerProfile extends Serializable {
if (welcomerEmbed.isPingBeforeSend()) { // Ping the user before sending the message
this.channel.sendMessage(user.getDiscordUser().getAsMention()).queue();
}
this.channel.sendMessageEmbeds(welcomerEmbed.buildEmbed(user).build()).queue();
this.channel.sendMessageEmbeds(welcomerEmbed.buildEmbed(guild, user).build()).queue();
return;
}
if (welcomerMessage != null) {
this.channel.sendMessage(welcomerMessage.buildMessage(user)).queue();
this.channel.sendMessage(welcomerMessage.buildMessage(guild, user)).queue();
}
}

@ -8,7 +8,10 @@ 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.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
import org.springframework.stereotype.Component;
@ -18,13 +21,21 @@ import org.springframework.stereotype.Component;
@Component("welcomer:channel.sub")
@CommandInfo(name = "channel", description = "Set the welcomer channel")
public class ChannelSubCommand extends BatSubCommand {
public ChannelSubCommand() {
super.addOption(OptionType.CHANNEL, "channel", "The channel to send the welcomer messages to", true);
}
@Override
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) {
WelcomerProfile profile = guild.getWelcomerProfile();
profile.setChannel(guild.getDiscordGuild().getTextChannelById(channel.getId()));
OptionMapping channelOption = event.getOption("channel");
if (channelOption == null) {
return;
}
TextChannel textChannel = channelOption.getAsChannel().asTextChannel();
profile.setChannel(textChannel);
event.replyEmbeds(EmbedUtils.successEmbed()
.setDescription("The welcomer channel has been set to %s".formatted(channel.getAsMention()))
.setDescription("The welcomer channel has been set to %s".formatted(textChannel.getAsMention()))
.build()).queue();
}
}