mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
feat: add plugins settings i18n + typing
This commit is contained in:
@@ -22,17 +22,22 @@ import {
|
||||
} from './types';
|
||||
|
||||
@Injectable()
|
||||
export abstract class BaseBlockPlugin extends BasePlugin {
|
||||
export abstract class BaseBlockPlugin<
|
||||
T extends PluginSetting[],
|
||||
> extends BasePlugin {
|
||||
public readonly type: PluginType = PluginType.block;
|
||||
|
||||
constructor(id: string, pluginService: PluginService<BasePlugin>) {
|
||||
public readonly settings: T;
|
||||
|
||||
constructor(
|
||||
id: string,
|
||||
settings: T,
|
||||
pluginService: PluginService<BasePlugin>,
|
||||
) {
|
||||
super(id, pluginService);
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
title: string;
|
||||
|
||||
settings: PluginSetting[];
|
||||
|
||||
template: PluginBlockTemplate;
|
||||
|
||||
effects?: PluginEffects;
|
||||
@@ -42,4 +47,11 @@ export abstract class BaseBlockPlugin extends BasePlugin {
|
||||
context: Context,
|
||||
convId?: string,
|
||||
): Promise<StdOutgoingEnvelope>;
|
||||
|
||||
protected getArguments(block: Block) {
|
||||
if ('args' in block.message) {
|
||||
return block.message.args as SettingObject<T>;
|
||||
}
|
||||
throw new Error(`Block "${block.name}" does not have any arguments.`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import { ContentModel } from '@/cms/schemas/content.schema';
|
||||
|
||||
import { PluginService } from './plugins.service';
|
||||
|
||||
@InjectDynamicProviders('dist/**/*.plugin.js')
|
||||
@InjectDynamicProviders('dist/extensions/**/*.plugin.js')
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
import { Test } from '@nestjs/testing';
|
||||
|
||||
import { DummyPlugin } from '@/extensions/plugins/dummy.plugin';
|
||||
import { LoggerModule } from '@/logger/logger.module';
|
||||
import { DummyPlugin } from '@/utils/test/dummy/dummy.plugin';
|
||||
|
||||
import { BaseBlockPlugin } from './base-block-plugin';
|
||||
import { PluginService } from './plugins.service';
|
||||
|
||||
@@ -22,7 +22,7 @@ export interface CustomBlocks {}
|
||||
type ChannelEvent = any;
|
||||
type BlockAttrs = Partial<BlockCreateDto> & { name: string };
|
||||
|
||||
export type PluginSetting = SettingCreateDto;
|
||||
export type PluginSetting = Omit<SettingCreateDto, 'weight'>;
|
||||
|
||||
export type PluginBlockTemplate = Omit<
|
||||
BlockAttrs,
|
||||
|
||||
Reference in New Issue
Block a user