-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new configure command to configure a textchannel for all cron t…
…asks
- Loading branch information
Showing
10 changed files
with
257 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { | ||
CacheType, | ||
CommandInteraction, | ||
EmbedBuilder, | ||
SlashCommandBuilder, | ||
} from 'discord.js'; | ||
import { ACommand } from '../command.abstract'; | ||
import { Inject } from '@nestjs/common'; | ||
import { ServerConfigService } from '../../models/config/service/server-config.service'; | ||
import { CreateOrUpdateServerConfigDto } from '../../models/config/dto/create-or-update-server-config.dto'; | ||
|
||
export default class ConfigureServerChannelCommand extends ACommand { | ||
constructor( | ||
@Inject(ServerConfigService) | ||
private readonly configService: ServerConfigService, | ||
) { | ||
super(); | ||
} | ||
data = new SlashCommandBuilder() | ||
.setName('configure') | ||
.setDescription( | ||
'set the channel id where the bot will send all scheduled messages', | ||
) | ||
.addStringOption((option) => | ||
option.setName('channelid').setDescription('the Id of the text-channel'), | ||
); | ||
|
||
// @Role(CommandAccessLevel.member) | ||
async execute(arg: CommandInteraction<CacheType>): Promise<boolean> { | ||
const channelId = arg.options.get('channelid'); | ||
if (!channelId) { | ||
await arg.reply({ | ||
content: 'you need to provide a valid channel Id! 🤓', | ||
ephemeral: true, | ||
}); | ||
return false; | ||
} | ||
await arg.deferReply(); | ||
const channelIdValue = channelId.value as unknown as string; | ||
const instance: CreateOrUpdateServerConfigDto = { | ||
channelId: channelIdValue, | ||
serverId: arg.guildId, | ||
}; | ||
const created = | ||
await this.configService.createOrUpdateServerConfig(instance); | ||
const quoteEmbed = new EmbedBuilder() | ||
.setTitle('Your scheduled messages textchannel was configured! 🤓') | ||
.setDescription('🤓') | ||
.setFooter({ | ||
text: 'scheduled messages activated', | ||
}) | ||
.setTimestamp(new Date()); | ||
await arg.editReply({ embeds: [quoteEmbed] }); | ||
return true; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,46 @@ | ||
import { EmbedBuilder, TextChannel } from 'discord.js' | ||
import { ITask } from './interfaces/task.interface' | ||
import { BirthdayEntryService } from '../../models/birthday/service/birthday-entry.service' | ||
import { EmbedBuilder, TextChannel } from 'discord.js'; | ||
import { ITask } from './interfaces/task.interface'; | ||
import { BirthdayEntryService } from '../../models/birthday/service/birthday-entry.service'; | ||
|
||
export default class BirthdayShoutoutTask implements ITask { | ||
private channel: TextChannel | ||
private channel: TextChannel; | ||
|
||
constructor(channel: TextChannel, private readonly birthdayService: BirthdayEntryService) { | ||
this.channel = channel | ||
} | ||
|
||
async execute(): Promise<void> { | ||
const birthDayEntries = await this.birthdayService.getEntryForToday() | ||
constructor( | ||
channel: TextChannel, | ||
private readonly birthdayService: BirthdayEntryService, | ||
) { | ||
this.channel = channel; | ||
} | ||
|
||
if (!birthDayEntries || birthDayEntries.length < 1) { | ||
return | ||
} | ||
async execute(): Promise<void> { | ||
const birthDayEntries = await this.birthdayService.getEntryForToday(); | ||
|
||
birthDayEntries.forEach((entry) => { | ||
const creator = this.channel.members.find((member) => member.user.username === entry.username || member.user.displayName === entry.secName) | ||
if (!birthDayEntries || birthDayEntries.length < 1) { | ||
return; | ||
} | ||
|
||
const embed = new EmbedBuilder() | ||
.setTitle(`🚨 Birthday Alert!! 🚨`) | ||
.setColor('Random') | ||
.setDescription(`${entry.username ?? entry.secName} is turning **${new Date().getFullYear() - entry.birthDate.getFullYear()}** years old today! 🎉🎂🎈`) | ||
.setFooter({ | ||
text: creator?.user.username ?? 'bingus', | ||
iconURL: creator?.displayAvatarURL() ?? undefined, | ||
}) | ||
.setTimestamp(new Date()) | ||
birthDayEntries.forEach((entry) => { | ||
const creator = this.channel.members.find( | ||
(member) => | ||
member.user.username === entry.username || | ||
member.user.displayName === entry.secName, | ||
); | ||
|
||
this.channel.send({ embeds: [embed] }) | ||
const embed = new EmbedBuilder() | ||
.setTitle(`🚨 Birthday Alert!! 🚨`) | ||
.setColor('Random') | ||
.setDescription( | ||
`${entry.username ?? entry.secName} is turning **${ | ||
new Date().getFullYear() - entry.birthDate.getFullYear() | ||
}** years old today! 🎉🎂🎈`, | ||
) | ||
.setFooter({ | ||
text: creator?.user.username ?? 'bingus', | ||
iconURL: creator?.displayAvatarURL() ?? undefined, | ||
}) | ||
} | ||
} | ||
.setTimestamp(new Date()); | ||
|
||
this.channel.send({ embeds: [embed] }); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/modules/models/config/dto/create-or-update-server-config.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsNotEmpty } from 'class-validator'; | ||
|
||
export class CreateOrUpdateServerConfigDto { | ||
@ApiProperty({ | ||
example: '239123321', | ||
description: 'The discord serverId', | ||
type: String, | ||
}) | ||
@IsNotEmpty() | ||
serverId: string; | ||
|
||
@ApiProperty({ | ||
example: '321123312123', | ||
description: 'The discord channelId for cron tasks', | ||
type: String, | ||
}) | ||
@IsNotEmpty() | ||
channelId: string; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
import { ServerConfigService } from '../service/server-config.service'; | ||
import { | ||
ServerConfig, | ||
ServerConfigSchema, | ||
} from '../../../../schemas/server-config.schema'; | ||
|
||
@Module({ | ||
imports: [ | ||
MongooseModule.forFeature([ | ||
{ | ||
name: ServerConfig.name, | ||
schema: ServerConfigSchema, | ||
}, | ||
]), | ||
], | ||
controllers: [], | ||
providers: [ServerConfigService], | ||
exports: [ServerConfigService], | ||
}) | ||
export class ServerConfigModule {} |
Oops, something went wrong.