UNPKG

kbotify

Version:

kaiheila bot framework

84 lines (83 loc) 2.74 kB
import { CardObject } from '../card'; import { KBotify } from '../kbotify'; import { BaseSession } from '../session'; import { BaseCommand, CommandTypes, ResultTypes } from '../types'; import { AppCommand } from './command.app'; /** * Class of menu command. * You should initialize with params: code, trigger, help, apps(array of AppCommand). * * @export * @class MenuCommand * @param code * @param trigger * @param help * @template T extends BaseData */ export declare abstract class MenuCommand implements BaseCommand { readonly type = CommandTypes.MENU; code: string; /** * 菜单触发文字 */ /** * 帮助文字。当发送`(菜单触发文字) 帮助`时返回的提示。 */ help: string; /** * 菜单文字。如果设置useCardMenu=true,此处应为json样式的字符串。 */ menu: string | CardObject[]; commandMap: Map<string, AppCommand>; /** * 此命令绑定的bot实例 */ client: KBotify | undefined; /** * 是否使用cardmessage作为菜单,默认为否。如果为是,则菜单文字内容必须为cardmessage。 */ useCardMenu: boolean; useTempMenu: boolean; abstract trigger: string; /** * Creates an instance of MenuCommand. * this will add trigger of the app to the menu. * * @param apps instances of AppCommand * @memberof MenuCommand */ constructor(...apps: AppCommand[]); init: (client: KBotify) => void; /** * Add alias for a certain app to this menu. * 与初始化菜单时添加App不同,不会添加App的触发文字到菜单内,只添加作为参数输入的Alias。 * Note that this **will NOT add trigger** to menu. * menu.addCommand(app, alias1, alias2, ...) * * @param app instance of AppCommand * @param alias alias of the app * @memberof MenuCommand */ addAlias(app: AppCommand, ...aliases: string[]): void; /** * 菜单的主体功能。 * - 如果参数为空,返回菜单。 * - 如果第一个参数为帮助,返回帮助。 * - 如果未找到对应命令,返回如何触发菜单的提示。 * - 如果找到对应命令,则调用。 * * @param {BaseSession} session * @return {*} {(Promise<ResultTypes | void>)} * @memberof MenuCommand */ func(session: BaseSession): Promise<ResultTypes | void>; /** * If you want to have something done before executing app command, please overwrite this. * 默认情况下直接调用菜单的func功能。 * * @param session * @return {*} * @memberof MenuCommand */ exec(session: BaseSession): Promise<ResultTypes | void>; }