-
Notifications
You must be signed in to change notification settings - Fork 0
/
modules.ts
58 lines (46 loc) · 1.5 KB
/
modules.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { NCSEmit } from './';
import { config } from './config';
import { NCSModuleType } from './types';
export abstract class NCSModule
{
/**
* shoude be named like creator.modulename
*/
abstract readonly ModuleName: string;
abstract readonly ModuleType: NCSModuleType;
abstract readonly RequiesReboot: boolean;
readonly config = config;
protected log(message: string = '', type: 'info' | 'warn' | 'error' | 'debug' = 'info')
{
console.log(`${type == 'info' ? '✅' : type == 'warn' ? '🔥' : type == 'debug' ? '🚧' : '🚨'} [${this.ModuleName.split('.')[ 1 ]}] ${message}`);
}
public PreInitiation(): Promise<void>
{
return new Promise((done) => done());
};
public Initiation(): Promise<void>
{
return new Promise((done) => done());
};
protected abstract UpdateIfAvailable(): Promise<boolean>;
/**
* Communicate with other Modules
* @param type The Suffix of youre module name
*/
protected createListener(type: string = 'default', action: Function)
{
NCSEmit.on(`${this.ModuleName}.${type}`, () => action());
}
protected createListenerWide(type: string = 'default', action: (...args: any[]) => void)
{
NCSEmit.on(`${type}`, action);
}
protected sendListener(listener: string, args: string | object | boolean)
{
NCSEmit.emit(listener, args);
}
public StartModule()
{
this.log('Module Loaded... (Remove This)', 'debug');
}
}