-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: discord notifications refactor (#425)
* add DiscordService, refactor PlayerBansService * PlayersService refactor * PlayerSubstitutionService refactor * PlayerSkillService refactor * QueueNotificationsService refactor * get rid of DiscordNotificationsService
- Loading branch information
1 parent
c095022
commit acc4d1c
Showing
31 changed files
with
879 additions
and
1,019 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 |
---|---|---|
@@ -1,19 +1,12 @@ | ||
import { Module, forwardRef } from '@nestjs/common'; | ||
import { DiscordNotificationsService } from './services/discord-notifications.service'; | ||
import { PlayersModule } from '@/players/players.module'; | ||
import { MessageEmbedFactoryService } from './services/message-embed-factory.service'; | ||
import { Module } from '@nestjs/common'; | ||
import { DiscordService } from './services/discord.service'; | ||
|
||
@Module({ | ||
imports: [ | ||
forwardRef(() => PlayersModule), | ||
], | ||
providers: [ | ||
DiscordNotificationsService, | ||
MessageEmbedFactoryService, | ||
DiscordService, | ||
], | ||
exports: [ | ||
DiscordNotificationsService, | ||
MessageEmbedFactoryService, | ||
DiscordService, | ||
], | ||
}) | ||
export class DiscordModule { } |
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,8 @@ | ||
export enum Colors { | ||
PlayerBanAdded = '#dc3545', | ||
PlayerBanRevoked = '#9838dc', | ||
NewPlayer = '#33dc7f', | ||
PlayerNameChanged = '#5230dc', | ||
SubstituteRequest = '#ff557f', | ||
SkillChanged = '#ff953e', | ||
} |
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,6 @@ | ||
export { playerBanAdded } from './player-ban-added'; | ||
export { playerBanRevoked } from './player-ban-revoked'; | ||
export { newPlayer } from './new-player'; | ||
export { playerNameChanged } from './player-name-changed'; | ||
export { substituteRequest } from './substitute-request'; | ||
export { skillChanged } from './skill-changed'; |
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 { MessageEmbedOptions } from 'discord.js'; | ||
import { Colors } from './colors'; | ||
|
||
interface NewPlayerFields { | ||
name: string; | ||
profileUrl: string; | ||
} | ||
|
||
export function newPlayer(fields: NewPlayerFields): MessageEmbedOptions { | ||
return { | ||
color: Colors.NewPlayer, | ||
title: 'New player', | ||
fields: [ | ||
{ | ||
name: 'Name', | ||
value: fields.name, | ||
}, | ||
], | ||
url: fields.profileUrl, | ||
timestamp: new Date(), | ||
}; | ||
} |
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,39 @@ | ||
import { MessageEmbedOptions } from 'discord.js'; | ||
import { Colors } from './colors'; | ||
import moment = require('moment'); | ||
|
||
interface PlayerBanAddedFields { | ||
admin: string; | ||
player: string; | ||
reason: string; | ||
ends: Date; | ||
playerProfileUrl: string; | ||
} | ||
|
||
export function playerBanAdded(fields: PlayerBanAddedFields): MessageEmbedOptions { | ||
const endsText = moment(fields.ends).fromNow(); | ||
|
||
return { | ||
color: Colors.PlayerBanAdded, | ||
title: 'Ban added', | ||
fields: [ | ||
{ | ||
name: 'Admin', | ||
value: fields.admin, | ||
}, | ||
{ | ||
name: 'Player', | ||
value: `[${fields.player}](${fields.playerProfileUrl})`, | ||
}, | ||
{ | ||
name: 'Reason', | ||
value: fields.reason, | ||
}, | ||
{ | ||
name: 'Ends', | ||
value: endsText, | ||
}, | ||
], | ||
timestamp: new Date(), | ||
}; | ||
} |
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,26 @@ | ||
import { MessageEmbedOptions } from 'discord.js'; | ||
import { Colors } from './colors'; | ||
|
||
interface PlayerBanRevokedFields { | ||
player: string; | ||
reason: string; | ||
playerProfileUrl: string; | ||
} | ||
|
||
export function playerBanRevoked(fields: PlayerBanRevokedFields): MessageEmbedOptions { | ||
return { | ||
color: Colors.PlayerBanRevoked, | ||
title: 'Ban revoked', | ||
fields: [ | ||
{ | ||
name: 'Player', | ||
value: `[${fields.player}](${fields.playerProfileUrl})`, | ||
}, | ||
{ | ||
name: 'Reason', | ||
value: fields.reason, | ||
}, | ||
], | ||
timestamp: new Date(), | ||
}; | ||
} |
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,27 @@ | ||
import { MessageEmbedOptions } from 'discord.js'; | ||
import { Colors } from './colors'; | ||
|
||
interface PlayerNameChangedFields { | ||
oldName: string; | ||
newName: string; | ||
profileUrl: string; | ||
} | ||
|
||
export function playerNameChanged(fields: PlayerNameChangedFields): MessageEmbedOptions { | ||
return { | ||
color: Colors.PlayerNameChanged, | ||
title: 'Player name changed', | ||
fields: [ | ||
{ | ||
name: 'Old name', | ||
value: fields.oldName, | ||
}, | ||
{ | ||
name: 'New name', | ||
value: fields.newName, | ||
}, | ||
], | ||
url: fields.profileUrl, | ||
timestamp: new Date(), | ||
}; | ||
} |
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,34 @@ | ||
import { MessageEmbedOptions } from 'discord.js'; | ||
import { Colors } from './colors'; | ||
|
||
interface SkillChangedFields { | ||
playerName: string; | ||
oldSkill: Map<string, number>; | ||
newSkill: Map<string, number>; | ||
playerProfileUrl: string; | ||
} | ||
|
||
export function skillChanged(fields: SkillChangedFields): MessageEmbedOptions { | ||
const embed: MessageEmbedOptions = { | ||
color: Colors.SkillChanged, | ||
title: 'Player\s skill has been updated', | ||
fields: [ | ||
{ | ||
name: 'Player name', | ||
value: `[${fields.playerName}](${fields.playerProfileUrl})`, | ||
}, | ||
], | ||
timestamp: new Date(), | ||
}; | ||
|
||
for (const key of fields.newSkill.keys()) { | ||
const newSkillValue = fields.newSkill.get(key); | ||
const oldSkillValue = fields.oldSkill.get(key) || 1; | ||
|
||
if (newSkillValue !== oldSkillValue) { | ||
embed.fields.push({ name: key, value: `${oldSkillValue} => ${newSkillValue}` }); | ||
} | ||
} | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { MessageEmbedOptions } from 'discord.js'; | ||
import { Colors } from './colors'; | ||
|
||
interface SubstituteRequestFields { | ||
gameNumber: number; | ||
gameClass: string; | ||
team: string; | ||
gameUrl: string; | ||
} | ||
|
||
export function substituteRequest(fields: SubstituteRequestFields): MessageEmbedOptions { | ||
return { | ||
color: Colors.SubstituteRequest, | ||
title: 'A substitute is needed', | ||
fields: [ | ||
{ | ||
name: 'Game no.', | ||
value: `#${fields.gameNumber}`, | ||
}, | ||
{ | ||
name: 'Class', | ||
value: fields.gameClass, | ||
}, | ||
{ | ||
name: 'Team', | ||
value: fields.team, | ||
}, | ||
], | ||
url: fields.gameUrl, | ||
timestamp: new Date(), | ||
}; | ||
} |
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,26 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class DiscordService { | ||
|
||
playersChannel = { | ||
send: () => Promise.resolve(), | ||
}; | ||
|
||
adminsChannel = { | ||
send: () => Promise.resolve(), | ||
}; | ||
|
||
getPlayersChannel() { | ||
return this.playersChannel; | ||
} | ||
|
||
getAdminsChannel() { | ||
return this.adminsChannel; | ||
} | ||
|
||
findRole(role: string) { | ||
return `&<${role}>`; | ||
} | ||
|
||
} |
Oops, something went wrong.