diff --git a/src/common/full-matcher.ts b/src/common/full-matcher.ts new file mode 100644 index 0000000..ab03966 --- /dev/null +++ b/src/common/full-matcher.ts @@ -0,0 +1,47 @@ +import { IMessage } from '../types'; + +/** + * Compare full IDs of rooms or users. + * @param compare ID to compare + * @param id ID to compare against + */ +export function fullIDMatcher(compare: string, id: string): boolean { + if (!compare) { + return false; + } + + const splitter = compare.split('/'); + + if (id === '*') { + return true; + } + + const spl = id.split('/'); + if (spl[0] !== splitter[0] || (spl[1] !== splitter[1] && spl[1] !== '*')) { + return false; + } + + // Match server cases, things like Discord need this + if (spl.length > 3 && spl[2].indexOf('s:') === 0 && splitter.length > 3) { + if (spl[2] !== splitter[3] && spl[2] !== '*') { + return false; + } + + if (spl[3] !== splitter[2] && spl[3] !== '*') { + return false; + } + + return true; + // Match regular cases + } else if (spl.length === 3 && splitter.length >= 3) { + if (spl[2] !== splitter[2] && spl[2] !== '*') { + return false; + } + return true; + // Match wildcard instance + } else if (spl.length === 2 && spl[1] === '*') { + return true; + } + + return false; +} diff --git a/src/common/index.ts b/src/common/index.ts index a1c6b2a..2ba051b 100644 --- a/src/common/index.ts +++ b/src/common/index.ts @@ -1,3 +1,4 @@ export * from './http'; export * from './time'; export * from './sanitize'; +export * from './full-matcher'; diff --git a/src/plugin/decorators/auto.ts b/src/plugin/decorators/auto.ts index 67b6c0d..2196aa9 100644 --- a/src/plugin/decorators/auto.ts +++ b/src/plugin/decorators/auto.ts @@ -1,4 +1,7 @@ +/** + * Automatically execute method on plugin initialization + */ export function Auto(): (...args: any[]) => void { return ( target: any, diff --git a/src/plugin/decorators/configurable.ts b/src/plugin/decorators/configurable.ts index f2d58d8..def241b 100644 --- a/src/plugin/decorators/configurable.ts +++ b/src/plugin/decorators/configurable.ts @@ -1,4 +1,8 @@ +/** + * Declare this plugin as one that the user can configure. + * @param defconf Default configuration + */ export function Configurable(defconf: any): Function { return (constructor: Function): void => { constructor.prototype.__defconf = defconf; diff --git a/src/plugin/decorators/dependency.ts b/src/plugin/decorators/dependency.ts index f3518b1..16e3aac 100644 --- a/src/plugin/decorators/dependency.ts +++ b/src/plugin/decorators/dependency.ts @@ -1,4 +1,8 @@ +/** + * Fire the following method automatically when a dependency is (re)loaded. + * @param dep Name of the dependency + */ export function DependencyLoad(dep: string): (...args: any[]) => void { return ( target: any, @@ -25,6 +29,10 @@ export function DependencyLoad(dep: string): (...args: any[]) => void { }; } +/** + * Fire the following method automatically when a dependency is unloaded. + * @param dep Name of the dependency + */ export function DependencyUnload(dep: string): (...args: any[]) => void { return ( target: any, diff --git a/src/plugin/decorators/eventlistener.ts b/src/plugin/decorators/eventlistener.ts index ef0ccb7..9c65659 100644 --- a/src/plugin/decorators/eventlistener.ts +++ b/src/plugin/decorators/eventlistener.ts @@ -1,4 +1,8 @@ +/** + * Listen for an event targeted towards this plugin. + * @param event Event name + */ export function EventListener(event: string): (...args: any[]) => void { return ( target: any, diff --git a/src/plugin/decorators/service.ts b/src/plugin/decorators/service.ts index 77fc174..7abd0d9 100644 --- a/src/plugin/decorators/service.ts +++ b/src/plugin/decorators/service.ts @@ -1,4 +1,8 @@ +/** + * Declare this plugin as one that utilises services. + * @param servtype Service class, usually a Protocol + */ export function InjectService(servtype: any): Function { return (constructor: Function): void => { constructor.prototype.__service = servtype; diff --git a/src/plugin/plugin.ts b/src/plugin/plugin.ts index b91452a..682fa15 100644 --- a/src/plugin/plugin.ts +++ b/src/plugin/plugin.ts @@ -45,6 +45,7 @@ export interface IPluginManifest { fullPath: string; main: string; name: string; + tags?: string[]; version: string; description: string; dependencies: string[]; diff --git a/src/types/message.ts b/src/types/message.ts index ba76b13..5ceac50 100644 --- a/src/types/message.ts +++ b/src/types/message.ts @@ -15,16 +15,21 @@ export enum EMessageType { export interface IMessageTarget { id: string; name: string; + server?: string; } export interface IMessage { + id?: any; type: EMessageType; data: any; - source: IPlugin | Protocol; + source: Protocol; guest?: boolean; target?: IMessageTarget; sender?: IMessageTarget; + fullSenderID?: string; + fullRoomID?: string; time: Date; + direct?: boolean; resolved: boolean; resolve(...args: any[]): void; } diff --git a/tslint.json b/tslint.json index 1c2e31f..9f05d30 100644 --- a/tslint.json +++ b/tslint.json @@ -14,10 +14,6 @@ "severity": "warning" }, "eofline": true, - "import-blacklist": [ - true, - "rxjs/Rx" - ], "import-spacing": true, "indent": { "options": [ @@ -121,33 +117,6 @@ "check-type", "check-typecast" ] - }, - "component-class-suffix": true, - "contextual-lifecycle": true, - "directive-class-suffix": true, - "no-conflicting-lifecycle": true, - "no-host-metadata-property": true, - "no-input-rename": true, - "no-inputs-metadata-property": true, - "no-output-native": true, - "no-output-on-prefix": true, - "no-output-rename": true, - "no-outputs-metadata-property": true, - "template-banana-in-box": true, - "template-no-negated-async": true, - "use-lifecycle-interface": true, - "use-pipe-transform-interface": true, - "directive-selector": [ - true, - "attribute", - "app", - "camelCase" - ], - "component-selector": [ - true, - "element", - "app", - "kebab-case" - ] + } } }