Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
feat: profile image check (#300)
Browse files Browse the repository at this point in the history
* feat: check profile-image

* feat: dont send message immediately

* style: remove logs

* chore: add dot at end of sentence

* fix: correct if condition

* refactor: update message
  • Loading branch information
Cahllagerfeld authored Jul 4, 2021
1 parent 5163922 commit 20f2e5d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -14,6 +15,7 @@ import { VersionModule } from './version/version.module';
isGlobal: true,
}),
VersionModule,
CheckImageModule,
],
providers: [AppService, DiscordConfigService],
})
Expand Down
17 changes: 17 additions & 0 deletions src/check-image/check-image.handler.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
9 changes: 9 additions & 0 deletions src/check-image/check-image.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
25 changes: 25 additions & 0 deletions src/check-image/check-image.service.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}

0 comments on commit 20f2e5d

Please sign in to comment.