-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathslashcommands.ts
72 lines (53 loc) · 2.66 KB
/
slashcommands.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { ISlashCommand, SlashCommandContext } from '@rocket.chat/apps-engine/definition/slashcommands';
import { IHttp, IHttpRequest, IMessageBuilder, IModify, IPersistence, IRead } from '@rocket.chat/apps-engine/definition/accessors';
import { App } from '@rocket.chat/apps-engine/definition/App';
import { startNewMessageWithDefaultSenderConfig } from './helpers';
import { sdk } from './sdk';
export class CloudflareSlashCommand implements ISlashCommand {
public command = 'cloudflare';
public i18nParamsExample = 'slashcommand_params';
public i18nDescription = 'command_description';
public providesPreview = false;
constructor(private readonly app: App) { }
public async executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp, persis: IPersistence): Promise<void> {
const [command] = context.getArguments();
if (!command) {
return this.processHelpCommand(context, read, modify);
}
switch (command) {
case 'ssldetails':
this.processSSLDetails(context, read, modify, http, persis);
break;
default:
return this.processHelpCommand(context, read, modify);
}
}
private async processHelpCommand(context: SlashCommandContext, read: IRead, modify: IModify): Promise<void> {
const sender = await read.getUserReader().getById('rocket.cat');
const room = context.getRoom();
const msg = await startNewMessageWithDefaultSenderConfig(modify, read, sender, room);
const text =
`These are the commands I can understand:
\`/cloudflare ssldetails\` show details of...
\`/cloudflare help\` Shows this message`;
msg.setText(text);
modify.getNotifier().notifyUser(context.getSender(), msg.getMessage());
}
private async processSSLDetails(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp, persis: IPersistence): Promise<void> {
const sender = await read.getUserReader().getById('rocket.cat');
const room = context.getRoom();
const msg = await startNewMessageWithDefaultSenderConfig(modify, read, sender, room);
if (!await sdk.hasAuthInfo(read)) {
msg.setText('Configure os dados de autenticação na area administrativa');
modify.getCreator().finish(msg);
return;
}
const data = await sdk.getSslVerification(http, read);
if (data.result[0].certificate_status) {
msg.setText('Certificado ativo');
} else {
msg.setText('Certificado inativo');
}
modify.getCreator().finish(msg);
}
}