Skip to content

Commit a937405

Browse files
committed
feat: add with-workflow example
1 parent ce82cd4 commit a937405

File tree

20 files changed

+2913
-167
lines changed

20 files changed

+2913
-167
lines changed

apps/test-bot/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.env
22
.commandkit
33
compiled-commandkit.config.mjs
4-
*.db*
4+
*.db*
5+
.workflow-data/
6+
.swc/

apps/test-bot/commandkit.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { cache } from '@commandkit/cache';
55
import { ai } from '@commandkit/ai';
66
import { tasks, setDriver } from '@commandkit/tasks';
77
import { BullMQDriver } from '@commandkit/tasks/bullmq';
8+
import { workflowRollupPlugin } from 'workflow/rollup';
89

910
noBuildOnly(() => {
1011
setDriver(
@@ -15,6 +16,7 @@ noBuildOnly(() => {
1516
})();
1617

1718
export default defineConfig({
19+
rolldownPlugins: [workflowRollupPlugin()],
1820
plugins: [
1921
i18n(),
2022
devtools(),

apps/test-bot/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"discord.js": "catalog:discordjs",
2323
"dotenv": "^16.4.7",
2424
"ms": "^2.1.3",
25+
"workflow": "4.0.1-beta.11",
2526
"zod": "^4.1.1"
2627
},
2728
"devDependencies": {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { greetUserWorkflow } from '@/workflows/greet/greet.workflow';
2+
import type { CommandData, ChatInputCommand, MessageCommand } from 'commandkit';
3+
import { start } from 'workflow/api';
4+
5+
export const command: CommandData = {
6+
name: 'greet',
7+
description: 'greet command',
8+
};
9+
10+
export const chatInput: ChatInputCommand = async (ctx) => {
11+
await ctx.interaction.reply(`I'm gonna greet you :wink:`);
12+
13+
await start(greetUserWorkflow, [ctx.interaction.user.id]);
14+
};
15+
16+
export const message: MessageCommand = async (ctx) => {
17+
await ctx.message.reply(`I'm gonna greet you :wink:`);
18+
19+
await start(greetUserWorkflow, [ctx.message.author.id]);
20+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { sleep } from 'workflow';
2+
import { greetUser } from './steps/greet.step';
3+
4+
export async function greetUserWorkflow(userId: string) {
5+
'use workflow';
6+
7+
await greetUser(userId);
8+
9+
await sleep('5 seconds');
10+
11+
await greetUser(userId, true);
12+
13+
return { success: true };
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Logger } from 'commandkit';
2+
import { useClient } from 'commandkit/hooks';
3+
4+
export async function greetUser(userId: string, again = false) {
5+
'use step';
6+
7+
const client = useClient<true>();
8+
9+
const user = await client.users.fetch(userId);
10+
11+
const message = again ? 'Hello again!' : 'Hello!';
12+
13+
await user.send(message);
14+
}

examples/with-workflow/.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# dependencies
2+
node_modules
3+
4+
# build output
5+
build
6+
out
7+
dist
8+
9+
# commandkit
10+
.commandkit
11+
dist
12+
compiled-commandkit.config.mjs
13+
14+
# env
15+
**/*.env*
16+
!**/*.env.example*
17+
18+
# logging
19+
logs
20+
*.log
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
lerna-debug.log*
25+
.pnpm-debug.log*
26+
27+
# yarn v2+
28+
.yarn/cache
29+
.yarn/unplugged
30+
.yarn/build-state.yml
31+
.yarn/install-state.gz
32+
.pnp.*
33+
34+
# other
35+
**/*.DS_Store
36+
.temp-example
37+
.workflow-data/
38+
.swc/

examples/with-workflow/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Welcome to CommandKit + TypeScript
2+
3+
> This project was generated by [create-commandkit](https://npmjs.com/package/create-commandkit).
4+
5+
Thanks for choosing CommandKit to build your Discord bot!
6+
7+
## To run this project
8+
9+
```
10+
npx commandkit dev
11+
```
12+
13+
## Useful links
14+
15+
- [Documentation](https://commandkit.dev)
16+
- [Discord](https://ctrl.lol/discord)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference path="node_modules/commandkit-types/index.d.ts" />
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineConfig } from 'commandkit/config';
2+
import { workflowRollupPlugin } from 'workflow/rollup';
3+
4+
export default defineConfig({
5+
rolldownPlugins: [workflowRollupPlugin()],
6+
});

0 commit comments

Comments
 (0)