-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.ts
37 lines (31 loc) · 1008 Bytes
/
utils.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
import { Command } from "https://raw.githubusercontent.com/brettkolodny/slash-server/main/mod.ts";
export function mdToCommands(mdString: string): Command[] {
const lines = mdString.split("\n");
const commands: Command[] = [];
let command = new Command();
let response: string[] = [];
lines.forEach((line) => {
line = line.trim();
if (line.startsWith("###")) {
command.description = line.slice(3).trim();
if (command.description.length > 100) {
console.error(`Command: ${command.name} description too long`);
}
} else if (line.startsWith("##")) {
if (command.name) {
command.response = response.join("\n");
commands.push(command);
command = new Command();
response = [];
}
command.name = line.slice(2).trim();
} else if (line.startsWith("#")) {
return;
} else {
response.push(line);
}
});
command.response = response.join("\n");
commands.push(command);
return commands;
}