Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/publish-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
"@commandkit/analytics:packages/analytics"
"@commandkit/ai:packages/ai"
"@commandkit/queue:packages/queue"
"@commandkit/tasks:packages/tasks"
)

for entry in "${PACKAGES[@]}"; do
Expand All @@ -84,6 +85,7 @@ jobs:
"@commandkit/analytics"
"@commandkit/ai"
"@commandkit/queue"
"@commandkit/tasks"
)

for pkg in "${PACKAGES[@]}"; do
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
"@commandkit/devtools:packages/devtools"
"@commandkit/cache:packages/cache"
"@commandkit/queue:packages/queue"
"@commandkit/tasks:packages/tasks"
)

for entry in "${PACKAGES[@]}"; do
Expand Down
2 changes: 1 addition & 1 deletion apps/test-bot/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.env
.commandkit
compiled-commandkit.config.mjs
commandkit*.db*
*.db*
2 changes: 2 additions & 0 deletions apps/test-bot/commandkit.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { i18n } from '@commandkit/i18n';
import { devtools } from '@commandkit/devtools';
import { cache } from '@commandkit/cache';
import { ai } from '@commandkit/ai';
import { tasks } from '@commandkit/tasks';

export default defineConfig({
plugins: [
Expand All @@ -12,5 +13,6 @@ export default defineConfig({
devtools(),
cache(),
ai(),
tasks(),
],
});
3 changes: 3 additions & 0 deletions apps/test-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
"@commandkit/devtools": "workspace:*",
"@commandkit/i18n": "workspace:*",
"@commandkit/legacy": "workspace:*",
"@commandkit/tasks": "workspace:*",
"commandkit": "workspace:*",
"discord.js": "catalog:discordjs",
"dotenv": "^16.4.7",
"ms": "^2.1.3",
"zod": "^3.25.56"
},
"devDependencies": {
"@types/ms": "^2.1.0",
"tsx": "^4.7.0"
}
}
4 changes: 4 additions & 0 deletions apps/test-bot/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Client } from 'discord.js';
import { Logger, commandkit } from 'commandkit';
import { setDriver } from '@commandkit/tasks';
import { HyperCronDriver } from '@commandkit/tasks/hypercron';
import './ai.ts';

const client = new Client({
Expand All @@ -12,6 +14,8 @@ const client = new Client({
],
});

setDriver(new HyperCronDriver());

Logger.log('Application bootstrapped successfully!');

commandkit.setPrefixResolver((message) => {
Expand Down
72 changes: 72 additions & 0 deletions apps/test-bot/src/app/commands/remind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import type { CommandData, ChatInputCommand, MessageCommand } from 'commandkit';
import { ApplicationCommandOptionType } from 'discord.js';
import ms from 'ms';
import { createTask } from '@commandkit/tasks';
import { RemindTaskData } from '../tasks/remind';

export const command: CommandData = {
name: 'remind',
description: 'remind command',
options: [
{
name: 'time',
description: 'The time to remind after. Eg: 6h, 10m, 1d',
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: 'message',
description: 'The message to remind about.',
type: ApplicationCommandOptionType.String,
required: true,
},
],
};

export const chatInput: ChatInputCommand = async (ctx) => {
const time = ctx.options.getString('time', true);
const message = ctx.options.getString('message', true);
const timeMs = Date.now() + ms(time as `${number}`);

await createTask({
name: 'remind',
data: {
userId: ctx.interaction.user.id,
message,
channelId: ctx.interaction.channelId,
setAt: Date.now(),
} satisfies RemindTaskData,
schedule: {
type: 'date',
value: timeMs,
},
});

await ctx.interaction.reply(
`I will remind you <t:${Math.floor(timeMs / 1000)}:R> for \`${message}\``,
);
};

export const message: MessageCommand = async (ctx) => {
const [time, ...messageParts] = ctx.args();
const message = messageParts.join(' ');
const timeMs = Date.now() + ms(time as `${number}`);

await createTask({
name: 'remind',
data: {
userId: ctx.message.author.id,
message,
channelId: ctx.message.channelId,
setAt: Date.now(),
} satisfies RemindTaskData,
schedule: {
type: 'date',
value: timeMs,
},
});

await ctx.message.reply(
`I will remind you <t:${Math.floor(timeMs / 1000)}:R> for \`${message}\``,
);
};
31 changes: 31 additions & 0 deletions apps/test-bot/src/app/tasks/remind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { task } from '@commandkit/tasks';

export interface RemindTaskData {
userId: string;
message: string;
channelId: string;
setAt: number;
}

export default task<RemindTaskData>({
name: 'remind',
async execute(ctx) {
const { userId, message, channelId, setAt } = ctx.data;

const channel = await ctx.client.channels.fetch(channelId);

if (!channel?.isTextBased() || !channel.isSendable()) return;

await channel.send({
content: `<@${userId}>`,
embeds: [
{
title: `You asked me <t:${Math.floor(setAt / 1000)}:R> to remind you about:`,
description: message,
color: 0x0099ff,
timestamp: new Date(setAt).toISOString(),
},
],
});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## configureAI

<GenerationInfo sourceFile="packages/ai/src/configure.ts" sourceLine="183" packageName="@commandkit/ai" />
<GenerationInfo sourceFile="packages/ai/src/configure.ts" sourceLine="197" packageName="@commandkit/ai" />

Configures the AI plugin with the provided options.
This function allows you to set a message filter, select an AI model, and generate a system prompt.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## getAIConfig

<GenerationInfo sourceFile="packages/ai/src/configure.ts" sourceLine="174" packageName="@commandkit/ai" />
<GenerationInfo sourceFile="packages/ai/src/configure.ts" sourceLine="188" packageName="@commandkit/ai" />

Retrieves the current AI configuration.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## CommandKit

<GenerationInfo sourceFile="packages/commandkit/src/CommandKit.ts" sourceLine="94" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/commandkit.ts" sourceLine="94" packageName="commandkit" />

The commandkit class that serves as the main entry point for the CommandKit framework.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## onApplicationBootstrap

<GenerationInfo sourceFile="packages/commandkit/src/CommandKit.ts" sourceLine="85" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/commandkit.ts" sourceLine="85" packageName="commandkit" />

Registers a bootstrap hook that will be called when the CommandKit instance is created.
This is useful for plugins that need to run some code after the CommandKit instance is fully initialized.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## onBootstrap

<GenerationInfo sourceFile="packages/commandkit/src/CommandKit.ts" sourceLine="69" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/commandkit.ts" sourceLine="69" packageName="commandkit" />

Registers a bootstrap hook that will be called when the CommandKit instance is created.
This is useful for plugins that need to run some code after the CommandKit instance is fully initialized.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## CommandKitConfiguration

<GenerationInfo sourceFile="packages/commandkit/src/CommandKit.ts" sourceLine="30" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/commandkit.ts" sourceLine="30" packageName="commandkit" />

Configurations for the CommandKit instance.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## BootstrapFunction

<GenerationInfo sourceFile="packages/commandkit/src/CommandKit.ts" sourceLine="48" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/commandkit.ts" sourceLine="48" packageName="commandkit" />

Represents the function executed during the bootstrap phase of CommandKit.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## commandkit

<GenerationInfo sourceFile="packages/commandkit/src/CommandKit.ts" sourceLine="488" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/commandkit.ts" sourceLine="488" packageName="commandkit" />

The singleton instance of CommandKit.

Loading