Skip to content

Commit

Permalink
Check greetings are enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ttbowen committed Oct 1, 2023
1 parent 069e2e6 commit 1b11bed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions packages/mrwhale-discord/src/client/discord-bot-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ export class DiscordBotClient extends BotClient<DiscordCommand> {

@on(Events.GuildMemberAdd)
private async onGuildMemberAdd(guildMember: GuildMember) {
const isGreetingsEnabled = await this.isGreetingsEnabled(
guildMember.guild.id
);

if (!isGreetingsEnabled) {
return;
}

const greeting = await new Greeting()
.setGuild(guildMember.guild.name)
.setAvatarUrl(
Expand Down Expand Up @@ -245,4 +253,14 @@ export class DiscordBotClient extends BotClient<DiscordCommand> {
c.permissionsFor(guild.members.me).has(["SendMessages", "AttachFiles"])
);
}

private async isGreetingsEnabled(guildId: string): Promise<boolean> {
if (!this.guildSettings.has(guildId)) {
return false;
}

const settings = this.guildSettings.get(guildId);

return await settings.get("greetings", false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ export default class extends DiscordCommand {

slashCommandAction(
interaction: ChatInputCommandInteraction<CacheType>
): Promise<unknown> {
): Promise<Message<boolean> | InteractionResponse<boolean>> {
const channel = interaction.options.getChannel("channel");

if (channel.type !== ChannelType.GuildText) {
return interaction.reply("You must pass a text based channel.");
}

this.setGreetingChannel(interaction, channel);
return this.setGreetingChannel(interaction, channel);
}

private async setGreetingChannel(
Expand Down

0 comments on commit 1b11bed

Please sign in to comment.