diff --git a/src/app.module.ts b/src/app.module.ts index bdf93fc9..5b220455 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -5,6 +5,7 @@ import { AppService } from './app.service'; import { DiscordConfigService } from './environment/discord-config.service'; import { AlexModule } from './alexjs/alex.module'; import { VersionModule } from './version/version.module'; +import { CheckImageModule } from './check-image/check-image.module'; @Module({ imports: [ @@ -14,6 +15,7 @@ import { VersionModule } from './version/version.module'; isGlobal: true, }), VersionModule, + CheckImageModule, ], providers: [AppService, DiscordConfigService], }) diff --git a/src/check-image/check-image.handler.ts b/src/check-image/check-image.handler.ts new file mode 100644 index 00000000..eaaea070 --- /dev/null +++ b/src/check-image/check-image.handler.ts @@ -0,0 +1,17 @@ +import { Injectable } from '@nestjs/common'; +import { On } from 'discord-nestjs'; +import { Message } from 'discord.js'; +import { CheckImageService } from './check-image.service'; + +@Injectable() +export class CheckImageHandler { + constructor(private readonly checkImageService: CheckImageService) {} + @On({ event: 'message' }) + checkImage(message: Message) { + if (message.author.bot) { + return; + } + this.checkImageService.checkImage(message); + return; + } +} diff --git a/src/check-image/check-image.module.ts b/src/check-image/check-image.module.ts new file mode 100644 index 00000000..d096cb73 --- /dev/null +++ b/src/check-image/check-image.module.ts @@ -0,0 +1,9 @@ +import { Module } from '@nestjs/common'; +import { CheckImageHandler } from './check-image.handler'; +import { CheckImageService } from './check-image.service'; + +@Module({ + providers: [CheckImageHandler, CheckImageService], + exports: [CheckImageHandler], +}) +export class CheckImageModule {} diff --git a/src/check-image/check-image.service.ts b/src/check-image/check-image.service.ts new file mode 100644 index 00000000..3ba3c45e --- /dev/null +++ b/src/check-image/check-image.service.ts @@ -0,0 +1,25 @@ +import { Injectable } from '@nestjs/common'; +import { Message } from 'discord.js'; + +@Injectable() +export class CheckImageService { + private countsDictionary: { [key: string]: number } = {}; + + public checkImage(message: Message): void { + const authorId = message.author.id; + if (!message.author.avatar) { + if (this.countsDictionary[authorId]) { + this.countsDictionary[authorId]++; + } else { + this.countsDictionary[authorId] = 1; + } + + if (this.countsDictionary[authorId] > 3) { + message.author.send( + 'Please consider adding a profile picture, it is more friendly. It does not have to be you, but something unique, like a cartoon version of yourself or a pet.', + ); + this.countsDictionary[authorId] = 0; + } + } + } +}