diff --git a/docs/controller/bot-controller.yml b/docs/controller/bot-controller.yml new file mode 100644 index 000000000..4c81474d8 --- /dev/null +++ b/docs/controller/bot-controller.yml @@ -0,0 +1,22 @@ +metadata: + kind: bot-controller + name: default-bot +data: + filters: [] + transforms: + - metadata: + kind: template-transform + name: default-bot-template + data: + templates: + body: >- + {{#each data}} + {{key}}: {{noun}} + {{/each}} + - metadata: + kind: flatten-transform + name: default-bot-flatten + data: + deep: false + join: '' + keys: [$.data.body] \ No newline at end of file diff --git a/docs/isolex.yml b/docs/isolex.yml index 966850f51..f16f42e51 100644 --- a/docs/isolex.yml +++ b/docs/isolex.yml @@ -16,6 +16,7 @@ data: - isolex-test controllers: - !include ../docs/controller/account-controller.yml + - !include ../docs/controller/bot-controller.yml - !include ../docs/controller/completion-controller.yml - !include ../docs/controller/dice-controller.yml - !include ../docs/controller/github/pr-controller.yml diff --git a/src/controller/BotController.ts b/src/controller/BotController.ts new file mode 100644 index 000000000..7d1b189ba --- /dev/null +++ b/src/controller/BotController.ts @@ -0,0 +1,36 @@ +import { endsWith } from 'lodash'; + +import { CheckRBAC, Controller, ControllerData, Handler } from 'src/controller'; +import { BaseController, BaseControllerOptions } from 'src/controller/BaseController'; +import { Command, CommandVerb } from 'src/entity/Command'; +import { Context } from 'src/entity/Context'; + +export const NOUN_NOUN = 'bot-noun'; + +export type BotControllerData = ControllerData; + +export class BotController extends BaseController implements Controller { + constructor(options: BaseControllerOptions) { + super(options, 'isolex#/definitions/service-controller-bot', [NOUN_NOUN]); + } + + @Handler(NOUN_NOUN, CommandVerb.List) + @CheckRBAC() + public async getNouns(cmd: Command, ctx: Context): Promise { + const nouns = []; + for (const [key, svc] of this.services.listServices()) { + if (endsWith(svc.kind, '-controller')) { + const svcNouns = Reflect.get(svc, 'nouns'); + if (svcNouns instanceof Set) { + for (const noun of svcNouns) { + nouns.push({ + key, + noun, + }); + } + } + } + } + return this.transformJSON(cmd, nouns); + } +} diff --git a/src/module/ControllerModule.ts b/src/module/ControllerModule.ts index c2da7bf28..4b783e46f 100644 --- a/src/module/ControllerModule.ts +++ b/src/module/ControllerModule.ts @@ -1,6 +1,7 @@ import { ModuleOptions } from 'noicejs/Module'; import { AccountController } from 'src/controller/AccountController'; +import { BotController } from 'src/controller/BotController'; import { CompletionController } from 'src/controller/CompletionController'; import { CountController } from 'src/controller/CountController'; import { DiceController } from 'src/controller/DiceController'; @@ -28,6 +29,7 @@ export class ControllerModule extends BaseModule { // controllers this.bindService(AccountController); + this.bindService(BotController); this.bindService(CompletionController); this.bindService(CountController); this.bindService(DiceController); diff --git a/src/schema/schema.yml b/src/schema/schema.yml index 9f72e0c41..1b78dc699 100644 --- a/src/schema/schema.yml +++ b/src/schema/schema.yml @@ -279,6 +279,9 @@ definitions: secret: type: string + service-controller-bot: + $ref: "#/definitions/service-controller" + service-controller-completion: allOf: - $ref: "#/definitions/service-controller"