-
Notifications
You must be signed in to change notification settings - Fork 1
/
BadWordsFilterApp.ts
52 lines (46 loc) · 2.26 KB
/
BadWordsFilterApp.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
import {
IAppAccessors,
IConfigurationExtend,
IConfigurationModify,
IEnvironmentRead,
IHttp,
ILogger,
IMessageBuilder,
IPersistence,
IRead,
} from '@rocket.chat/apps-engine/definition/accessors';
import { App } from '@rocket.chat/apps-engine/definition/App';
import { IMessage, IPreMessageSentModify } from '@rocket.chat/apps-engine/definition/messages';
import { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata';
import { ISetting } from '@rocket.chat/apps-engine/definition/settings';
import { AppSetting, settings } from './config/Settings';
import { OnSettingUpdatedHandler } from './handlers/OnSettingUpdatedHandler';
import { PreMessageSentHandler } from './handlers/PreMessageSentHandler';
export class BadWordsFilterApp extends App implements IPreMessageSentModify {
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
super(info, logger, accessors);
}
public blackListedWords:Array<string>
public async onEnable(environment: IEnvironmentRead, configurationModify: IConfigurationModify):Promise<boolean>{
this.blackListedWords = ((await environment.getSettings().getById(AppSetting.ListOfBlacklistedWords)).value).split(',').map(word => word.trim());
this.getLogger().debug("FROM Enable", this.blackListedWords)
return true;
}
async executePreMessageSentModify(
message: IMessage,
builder: IMessageBuilder,
read: IRead,
http: IHttp,
persist : IPersistence
):Promise<IMessage> {
const preMessageHandler = new PreMessageSentHandler(this, message, builder, read, http, persist, this.blackListedWords)
return preMessageHandler.run();
}
public async onSettingUpdated(setting: ISetting, configurationModify: IConfigurationModify, read: IRead, http: IHttp): Promise<void> {
const onSettingUpdatedHandler: OnSettingUpdatedHandler = new OnSettingUpdatedHandler(this, read, http);
this.blackListedWords = await onSettingUpdatedHandler.run();
}
protected async extendConfiguration(configuration: IConfigurationExtend, environmentRead: IEnvironmentRead): Promise<void> {
await Promise.all(settings.map((setting) => configuration.settings.provideSetting(setting)));
}
}