Full ID matcher

This commit is contained in:
Evert Prants 2020-11-29 21:23:43 +02:00
parent 88467fcee4
commit d3c649f684
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
10 changed files with 79 additions and 33 deletions

View File

@ -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;
}

View File

@ -1,3 +1,4 @@
export * from './http';
export * from './time';
export * from './sanitize';
export * from './full-matcher';

View File

@ -1,4 +1,7 @@
/**
* Automatically execute method on plugin initialization
*/
export function Auto(): (...args: any[]) => void {
return (
target: any,

View File

@ -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;

View File

@ -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,

View File

@ -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,

View File

@ -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;

View File

@ -45,6 +45,7 @@ export interface IPluginManifest {
fullPath: string;
main: string;
name: string;
tags?: string[];
version: string;
description: string;
dependencies: string[];

View File

@ -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;
}

View File

@ -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"
]
}
}
}