Commit e24e480b authored by nanahira's avatar nanahira

add CommandBefore and CommandAction

parent 916a4a74
...@@ -169,6 +169,12 @@ export const CommandUserFields = (fields: FieldCollector<'user'>) => ...@@ -169,6 +169,12 @@ export const CommandUserFields = (fields: FieldCollector<'user'>) =>
export const CommandChannelFields = (fields: FieldCollector<'channel'>) => export const CommandChannelFields = (fields: FieldCollector<'channel'>) =>
CommandDef((cmd) => cmd.channelFields(fields)); CommandDef((cmd) => cmd.channelFields(fields));
export const CommandBefore = (callback: Command.Action, append = false) =>
CommandDef((cmd) => cmd.before(callback, append));
export const CommandAction = (callback: Command.Action, prepend = false) =>
CommandDef((cmd) => cmd.action(callback, prepend));
// Command put config // Command put config
function PutCommandParam<T extends keyof CommandPutConfigMap>( function PutCommandParam<T extends keyof CommandPutConfigMap>(
...@@ -190,6 +196,7 @@ export const PutSession = (field?: keyof Session) => ...@@ -190,6 +196,7 @@ export const PutSession = (field?: keyof Session) =>
? PutCommandParam('sessionField', field) ? PutCommandParam('sessionField', field)
: PutCommandParam('argvField', 'session'); : PutCommandParam('argvField', 'session');
export const PutArg = (i: number) => PutCommandParam('arg', i); export const PutArg = (i: number) => PutCommandParam('arg', i);
export const PutArgs = () => PutCommandParam('args');
export const PutOption = ( export const PutOption = (
name: string, name: string,
desc: string, desc: string,
......
...@@ -152,6 +152,8 @@ export function DefinePlugin<T = any>( ...@@ -152,6 +152,8 @@ export function DefinePlugin<T = any>(
return; return;
} }
switch (config.type) { switch (config.type) {
case 'args':
return args;
case 'arg': case 'arg':
const { data: argIndex } = config as CommandPutConfig<'arg'>; const { data: argIndex } = config as CommandPutConfig<'arg'>;
return args[argIndex]; return args[argIndex];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment