-
Notifications
You must be signed in to change notification settings - Fork 12
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
12 changed files
with
146 additions
and
52 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { CommandKit } from '..'; | ||
|
||
export const getCommandKit = () => { | ||
const instance = CommandKit.instance; | ||
if (!instance) { | ||
throw new Error('CommandKit is not initialized.'); | ||
} | ||
|
||
return instance; | ||
}; | ||
|
||
export const getCommandHandler = () => { | ||
const ckit = getCommandKit(); | ||
const handler = ckit.getCommandHandler(); | ||
|
||
if (!handler) { | ||
throw new Error('CommandHandler is not initialized.'); | ||
} | ||
|
||
return handler; | ||
}; |
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,2 @@ | ||
export * from './useGuild'; | ||
export * from './useInteraction'; |
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,5 @@ | ||
import { getCommandKit } from './common'; | ||
|
||
export function useClient() { | ||
return getCommandKit().getClient(); | ||
} |
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,13 @@ | ||
import { getCommandHandler } from './common'; | ||
|
||
export function useGuild() { | ||
const { context } = getCommandHandler(); | ||
|
||
const data = context.getStore(); | ||
|
||
if (!data) { | ||
throw new Error('Cannot invoke "useGuild" outside of a command.'); | ||
} | ||
|
||
return data.interaction.guild; | ||
} |
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,13 @@ | ||
import { Interaction } from 'discord.js'; | ||
import { getCommandHandler } from './common'; | ||
|
||
export function useInteraction<T>(): T { | ||
const { context } = getCommandHandler(); | ||
|
||
const data = context.getStore(); | ||
if (!data) { | ||
throw new Error('Cannot invoke "useInteraction" outside of a command.'); | ||
} | ||
|
||
return data.interaction as T; | ||
} |
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,5 +1,6 @@ | ||
export * from './CommandKit'; | ||
export * from './components'; | ||
export * from './hooks'; | ||
export * from './config'; | ||
export * from './utils/signal'; | ||
export type * from './types'; |
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,5 @@ | ||
import { AsyncLocalStorage } from 'node:async_hooks'; | ||
|
||
export const createStore = <T = unknown>() => { | ||
return new AsyncLocalStorage<T>(); | ||
}; |
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