generated from didinele/typescript-docker-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
189 additions
and
50 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
14 changes: 12 additions & 2 deletions
14
.../core/src/applicationData/IDataManager.ts → ...core/src/application-data/IDataManager.ts
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,12 +1,22 @@ | ||
import type { Selectable } from 'kysely'; | ||
import type { Experiment, ExperimentOverride, Incident } from '../db.js'; | ||
import type { Experiment, ExperimentOverride, Incident, ModCase, ModCaseKind } from '../db.js'; | ||
|
||
export type ExperimentWithOverrides = Selectable<Experiment> & { overrides: Selectable<ExperimentOverride>[] }; | ||
|
||
export interface CreateModCaseData { | ||
guildId: string; | ||
kind: ModCaseKind; | ||
modId: string; | ||
reason: string; | ||
userId: string; | ||
} | ||
|
||
/** | ||
* Abstraction over all database interactions (things like Redis included) | ||
* Abstraction over all database interactions | ||
*/ | ||
export abstract class IDataManager { | ||
public abstract getExperiments(): Promise<ExperimentWithOverrides[]>; | ||
public abstract createIncident(error: Error, guildId?: string): Promise<Selectable<Incident>>; | ||
|
||
public abstract createModCase(data: CreateModCaseData): Promise<Selectable<ModCase>>; | ||
} |
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { ModCaseKind, type HandlerModule, type ICommandHandler, type IDataManager } from '@automoderator/core'; | ||
import { | ||
ApplicationCommandOptionType, | ||
InteractionContextType, | ||
MessageFlags, | ||
PermissionFlagsBits, | ||
type APIInteraction, | ||
} from '@discordjs/core'; | ||
import type { InteractionOptionResolver } from '@sapphire/discord-utilities'; | ||
import { ActionKind, type InteractionHandler as CoralInteractionHandler } from 'coral-command'; | ||
import { injectable } from 'inversify'; | ||
|
||
@injectable() | ||
export default class DevHandler implements HandlerModule<CoralInteractionHandler> { | ||
public constructor(private readonly dataManager: IDataManager) {} | ||
|
||
public register(handler: ICommandHandler<CoralInteractionHandler>) { | ||
handler.register({ | ||
interactions: [ | ||
{ | ||
name: 'warn', | ||
description: 'Warn a user', | ||
options: [ | ||
{ | ||
name: 'target', | ||
description: 'The user to warn', | ||
type: ApplicationCommandOptionType.User, | ||
required: true, | ||
}, | ||
{ | ||
name: 'reason', | ||
description: 'The reason for the warning', | ||
type: ApplicationCommandOptionType.String, | ||
required: true, | ||
}, | ||
], | ||
contexts: [InteractionContextType.Guild], | ||
default_member_permissions: String(PermissionFlagsBits.ModerateMembers), | ||
}, | ||
], | ||
applicationCommands: [['warn:none:none', this.hanadleWarn.bind(this)]], | ||
}); | ||
} | ||
|
||
public async *hanadleWarn(interaction: APIInteraction, options: InteractionOptionResolver): CoralInteractionHandler { | ||
if (!interaction.guild_id) { | ||
throw new Error('This command can only be used in a guild'); | ||
} | ||
|
||
yield { | ||
action: ActionKind.EnsureDefer, | ||
data: { | ||
flags: MessageFlags.Ephemeral, | ||
}, | ||
}; | ||
|
||
const target = options.getUser('target', true); | ||
const reason = options.getString('reason', true); | ||
|
||
const modCase = await this.dataManager.createModCase({ | ||
guildId: interaction.guild_id, | ||
userId: target.id, | ||
modId: interaction.member!.user.id, | ||
reason, | ||
kind: ModCaseKind.Warn, | ||
}); | ||
|
||
yield { | ||
action: ActionKind.Respond, | ||
data: { | ||
content: 'Successfully warned the user. DM sent: ', | ||
}, | ||
}; | ||
} | ||
} |
Oops, something went wrong.