This repository has been archived by the owner on Oct 10, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
5163922
commit 20f2e5d
Showing
4 changed files
with
53 additions
and
0 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
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; | ||
} | ||
} |
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,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 {} |
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,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; | ||
} | ||
} | ||
} | ||
} |