Skip to content

Commit

Permalink
feat(plugins): add plugin system (#5137)
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed May 12, 2022
1 parent 2673dbd commit 6e22b02
Show file tree
Hide file tree
Showing 28 changed files with 879 additions and 259 deletions.
16 changes: 15 additions & 1 deletion d.ts/src/helpers/socket.d.ts
Expand Up @@ -30,9 +30,12 @@ import type {
} from '@entity/user';
import type { VariableInterface, VariableWatchInterface } from '@entity/variable';
import { HelixVideo } from '@twurple/api/lib';
import { ValidationError } from 'class-validator';
import { Socket } from 'socket.io';
import { FindConditions } from 'typeorm';

import { Plugin } from '~/database/entity/plugins';

type Configuration = {
[x:string]: Configuration | string;
};
Expand Down Expand Up @@ -69,11 +72,22 @@ type GenericEvents = {
type generic<T extends Record<string, any>> = {
getAll: (cb: (error: Error | string | null, items: Readonly<Required<T>>[]) => void) => void,
getOne: (id: Required<T['id']>, cb: (error: Error | string | null, item?: Readonly<Required<T>>) => void) => void,
setById: (opts: { id: Required<T['id']>, item: Partial<T> }, cb: (error: Error | string | null, item?: Readonly<Required<T>> | null) => void) => void,
setById: (opts: { id: Required<T['id']>, item: Partial<T> }, cb: (error: ValidationError[] | Error | string | null, item?: Readonly<Required<T>> | null) => void) => void,
save: (item: Partial<T>, cb: (error: ValidationError[] | Error | string | null, item?: Readonly<Required<T>> | null) => void) => void,
deleteById: (id: Required<T['id']>, cb: (error: Error | string | null) => void) => void;
validate: (item: Partial<T>, cb: (error: ValidationError[] | Error | string | null) => void) => void,
};

export type ClientToServerEventsWithNamespace = {
'/core/plugins': GenericEvents & {
'listeners': (cb: (listeners: Record<string, any>) => void) => void,
'generic::getOne': generic<Plugin>['getOne'],
'generic::getAll': generic<Plugin>['getAll'],
'generic::save': generic<Plugin>['save'],
'generic::deleteById': generic<Plugin>['deleteById'],
'generic::validate': generic<Plugin>['validate'],

},
'/core/emotes': GenericEvents & {
'testExplosion': (cb: (err: Error | string | null, data: null ) => void) => void,
'testFireworks': (cb: (err: Error | string | null, data: null ) => void) => void,
Expand Down
15 changes: 15 additions & 0 deletions d.ts/src/plugins.d.ts
@@ -0,0 +1,15 @@
export type Node<T = string> = {
id: number,
name: string,
data: { value: T, data: string },
class: string,
html: string,
inputs: { input_1: { connections: {
node: string,
}[] }} | Record<string, never>,
outputs: { output_1: { connections: {
node: string,
}[] }, output_2: { connections: {
node: string,
}[] }},
};
3 changes: 2 additions & 1 deletion locales/en/ui.menu.json
Expand Up @@ -97,5 +97,6 @@
"obswebsocket": "OBS Websocket",
"api-explorer": "API Explorer",
"emotescombo": "Emotes Combo",
"notifications": "Notifications"
"notifications": "Notifications",
"plugins": "Plugins"
}
3 changes: 3 additions & 0 deletions locales/en/ui/errors.json
@@ -0,0 +1,3 @@
{
"isNotEmpty": "This field is required."
}
2 changes: 1 addition & 1 deletion locales/en/ui/registry/alerts.json
Expand Up @@ -65,7 +65,7 @@
"name": "Variant occurence"
},
"filter": {
"name": "Occurence filter",
"name": "Filter",
"operator": "Operator",
"rule": "Rule",
"addRule": "Add rule",
Expand Down
41 changes: 41 additions & 0 deletions locales/en/ui/registry/plugins.json
@@ -0,0 +1,41 @@
{
"common-errors": {
"missing-sender-attributes": "This node needs to be linked with listeners with sender attributes"
},
"filter": {
"permission": {
"name": "Permission filter"
}
},
"listener": {
"name": "Event listener",
"type": {
"twitchChatMessage": "Twitch chat message",
"twitchCommand": "Twitch command"
},
"command": {
"add-parameter": "Add parameter",
"parameters": "Parameters",
"order-is-important": "order is important"
}
},
"others": {
"idle": {
"name": "Idle"
}
},
"output": {
"log": {
"name": "Log message"
},
"timeout-user": {
"name": "Timeout user"
},
"ban-user": {
"name": "Ban user"
},
"send-twitch-message": {
"name": "Send Twitch Message"
}
}
}

0 comments on commit 6e22b02

Please sign in to comment.