Skip to content

Commit

Permalink
feat: add bot ctrl, handle noun list (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jan 12, 2019
1 parent e4f16b1 commit f779e60
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/controller/bot-controller.yml
Original file line number Diff line number Diff line change
@@ -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]
1 change: 1 addition & 0 deletions docs/isolex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions src/controller/BotController.ts
Original file line number Diff line number Diff line change
@@ -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<BotControllerData> implements Controller {
constructor(options: BaseControllerOptions<BotControllerData>) {
super(options, 'isolex#/definitions/service-controller-bot', [NOUN_NOUN]);
}

@Handler(NOUN_NOUN, CommandVerb.List)
@CheckRBAC()
public async getNouns(cmd: Command, ctx: Context): Promise<void> {
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);
}
}
2 changes: 2 additions & 0 deletions src/module/ControllerModule.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/schema/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ definitions:
secret:
type: string

service-controller-bot:
$ref: "#/definitions/service-controller"

service-controller-completion:
allOf:
- $ref: "#/definitions/service-controller"
Expand Down

0 comments on commit f779e60

Please sign in to comment.