Commit e24e480b authored by nanahira's avatar nanahira

add CommandBefore and CommandAction

parent 916a4a74
......@@ -169,6 +169,12 @@ export const CommandUserFields = (fields: FieldCollector<'user'>) =>
export const CommandChannelFields = (fields: FieldCollector<'channel'>) =>
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
function PutCommandParam<T extends keyof CommandPutConfigMap>(
......@@ -190,6 +196,7 @@ export const PutSession = (field?: keyof Session) =>
? PutCommandParam('sessionField', field)
: PutCommandParam('argvField', 'session');
export const PutArg = (i: number) => PutCommandParam('arg', i);
export const PutArgs = () => PutCommandParam('args');
export const PutOption = (
name: string,
desc: string,
......
......@@ -152,6 +152,8 @@ export function DefinePlugin<T = any>(
return;
}
switch (config.type) {
case 'args':
return args;
case 'arg':
const { data: argIndex } = config as CommandPutConfig<'arg'>;
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