Skip to content

Commit

Permalink
chore: add storedserver as context
Browse files Browse the repository at this point in the history
  • Loading branch information
zaida04 committed Jun 28, 2024
1 parent 6933660 commit 424486e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/gil/lib/listeners/CommandMessageListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ export default class CommandMessageListener extends Listener {

const context = this.gil.options?.contexts?.command
? await this.gil.options.contexts.command({
server: params.server,
message: params.message,
})
server: params.server,
message: params.message,
})
: {};

this.gil.emitter.emit("commandRan", {
Expand All @@ -100,6 +100,7 @@ export default class CommandMessageListener extends Listener {
await command.execute({
message: params.message,
args: attemptConvertArguments.arguments,
server: params.server,
...context,
});
} catch (e) {
Expand Down
5 changes: 3 additions & 2 deletions packages/gil/lib/structures/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Collection } from "@discordjs/collection";
import glob from "fast-glob";
import { Message } from "guilded.js";
import { GilClient } from "../GilClient";
import { StoredRoleType } from "../adapters/db/DatabaseAdapter";
import { StoredRoleType, StoredServer } from "../adapters/db/DatabaseAdapter";
import { CommandArgument, CommandArgumentType } from "../arguments/ArgumentParser";
import { CommandMessageParams } from "../events";
import { Manager } from "./Manager";
Expand Down Expand Up @@ -43,14 +43,15 @@ export abstract class Command {
public constructor(
public readonly gil: GilClient,
public readonly options: CommandOptions,
) {}
) { }

public abstract execute(commandContext: CommandContext<unknown, unknown>): unknown | Promise<unknown>;
}

export interface CommandExecuteContext<Args = Record<string, CommandArgument>> {
message: Message;
args: Args;
server: StoredServer;
}

export type CommandContext<T, Args = Record<string, CommandArgument>> = T & CommandExecuteContext<Args>;
Expand Down
2 changes: 1 addition & 1 deletion packages/gil/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@guildedjs/gil",
"version": "0.6.2",
"version": "0.6.3",
"description": "Framework for guilded.js that allows you to build bots with ease.",
"author": "Zaid \"Nico\" <contact@nico.engineer>",
"license": "MIT",
Expand Down

0 comments on commit 424486e

Please sign in to comment.