Skip to content

Commit

Permalink
refactor(Koto): Change header message & add timings to schedule function
Browse files Browse the repository at this point in the history
  • Loading branch information
jurienhamaker committed Apr 9, 2024
1 parent c612baa commit 394a1c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions apps/koto/src/modules/game/services/message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Injectable, Logger } from '@nestjs/common';
import { Game, GameStatus, Guess } from '@prisma/koto';
import { PrismaService } from '@yugen/prisma/koto';
import { getEmbedFooter, getTimestamp } from '@yugen/util';
import { startOfHour } from 'date-fns';
import { Channel, ChannelType, Client, EmbedBuilder } from 'discord.js';
import { GameTypeEmojiColorMap, getEmoji } from '../../../util/get-emoji';
import { asciiNumbers } from '../../../util/numbers';
Expand Down Expand Up @@ -87,10 +86,17 @@ export class GameMessageService {
game: Game & { guesses: Guess[]; meta: GameMeta },
) {
const footer = await getEmbedFooter(this._client);
const gamesCount = await this._prisma.game.count({
where: {
guildId: game.guildId,
id: {
not: game.id,
},
},
});

return new EmbedBuilder()
.setTitle(
`Koto for <t:${getTimestamp(startOfHour(game.createdAt))}:f>`,
)
.setTitle(`Koto #${gamesCount + 1}`)
.setColor(this._getEmbedColor(game.status))
.setDescription(
`${this._getMessageRows(game.guesses, game.status)}
Expand Down
2 changes: 2 additions & 0 deletions apps/koto/src/modules/game/services/schedule.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class GameScheduleService {

@Cron(`0 * * * * *`)
async check() {
console.time('scheduler');
const stats = {
outOfTimeGames: 0,
checkedGuilds: 0,
Expand Down Expand Up @@ -79,6 +80,7 @@ export class GameScheduleService {
this._logger.log(
`Ended ${stats.outOfTimeGames} games. Checked ${stats.checkedGuilds} guilds. Started ${stats.startedGames} games.`,
);
console.timeEnd('scheduler');
}

private async _endGame(id: number, guildId: string) {
Expand Down

0 comments on commit 394a1c6

Please sign in to comment.