-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: event-based trainings overview (#599)
- Loading branch information
Showing
16 changed files
with
203 additions
and
92 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
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 +1,4 @@ | ||
export { default as RankChangePacketHandler } from './rank-change' | ||
export { default as TrainingCancelPacketHandler } from './training-cancel' | ||
export { default as TrainingCreatePacketHandler } from './training-create' | ||
export { default as TrainingUpdatePacketHandler } from './training-update' |
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,40 @@ | ||
import { inject, injectable, named } from 'inversify' | ||
import { AnnounceTrainingsJob } from '../../../jobs' | ||
import type { BaseHandler } from '../..' | ||
import { GuildContextManager } from '../../../managers' | ||
import type { Training } from '../../../services' | ||
import { constants } from '../../../utils' | ||
import cron from 'node-schedule' | ||
|
||
const { TYPES } = constants | ||
|
||
interface TraniningCancelPacket { | ||
groupId: number | ||
training: Training | ||
} | ||
|
||
@injectable() | ||
export default class TrainingCancelPacketHandler implements BaseHandler { | ||
@inject(TYPES.Job) | ||
@named('announceTrainings') | ||
private readonly announceTrainingsJob!: AnnounceTrainingsJob | ||
|
||
@inject(TYPES.Manager) | ||
@named('GuildContextManager') | ||
private readonly guildContexts!: GuildContextManager | ||
|
||
public async handle ({ data }: { data: TraniningCancelPacket }): Promise<void> { | ||
const { groupId, training } = data | ||
for (const context of this.guildContexts.cache.values()) { | ||
if (context.robloxGroupId === groupId) { | ||
const jobName = `training_${training.id}` | ||
const job = cron.scheduledJobs[jobName] | ||
if (typeof job !== 'undefined') { | ||
job.cancel() | ||
} | ||
|
||
await this.announceTrainingsJob.run(context) | ||
} | ||
} | ||
} | ||
} |
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,33 @@ | ||
import { inject, injectable, named } from 'inversify' | ||
import { AnnounceTrainingsJob } from '../../../jobs' | ||
import type { BaseHandler } from '../..' | ||
import { GuildContextManager } from '../../../managers' | ||
import type { Training } from '../../../services' | ||
import { constants } from '../../../utils' | ||
|
||
const { TYPES } = constants | ||
|
||
interface TraniningCreatePacket { | ||
groupId: number | ||
training: Training | ||
} | ||
|
||
@injectable() | ||
export default class TrainingCreatePacketHandler implements BaseHandler { | ||
@inject(TYPES.Job) | ||
@named('announceTrainings') | ||
private readonly announceTrainingsJob!: AnnounceTrainingsJob | ||
|
||
@inject(TYPES.Manager) | ||
@named('GuildContextManager') | ||
private readonly guildContexts!: GuildContextManager | ||
|
||
public async handle ({ data }: { data: TraniningCreatePacket }): Promise<void> { | ||
const { groupId } = data | ||
for (const context of this.guildContexts.cache.values()) { | ||
if (context.robloxGroupId === groupId) { | ||
await this.announceTrainingsJob.run(context) | ||
} | ||
} | ||
} | ||
} |
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,40 @@ | ||
import { inject, injectable, named } from 'inversify' | ||
import { AnnounceTrainingsJob } from '../../../jobs' | ||
import type { BaseHandler } from '../..' | ||
import { GuildContextManager } from '../../../managers' | ||
import type { Training } from '../../../services' | ||
import { constants } from '../../../utils' | ||
import cron from 'node-schedule' | ||
|
||
const { TYPES } = constants | ||
|
||
interface TraniningUpdatePacket { | ||
groupId: number | ||
training: Training | ||
} | ||
|
||
@injectable() | ||
export default class TrainingUpdatePacketHandler implements BaseHandler { | ||
@inject(TYPES.Job) | ||
@named('announceTrainings') | ||
private readonly announceTrainingsJob!: AnnounceTrainingsJob | ||
|
||
@inject(TYPES.Manager) | ||
@named('GuildContextManager') | ||
private readonly guildContexts!: GuildContextManager | ||
|
||
public async handle ({ data }: { data: TraniningUpdatePacket }): Promise<void> { | ||
const { groupId, training } = data | ||
for (const context of this.guildContexts.cache.values()) { | ||
if (context.robloxGroupId === groupId) { | ||
const jobName = `training_${training.id}` | ||
const job = cron.scheduledJobs[jobName] | ||
if (typeof job !== 'undefined') { | ||
job.cancel() | ||
} | ||
|
||
await this.announceTrainingsJob.run(context) | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.