1 |
import { readFile, writeFile } from "fs"; |
import { readFile, writeFile } from "fs"; |
2 |
import path from "path"; |
import path from "path"; |
3 |
import DiscordClient from "../client/Client"; |
import DiscordClient from "../client/Client"; |
4 |
|
import MessageEmbed from "../client/MessageEmbed"; |
5 |
import Service from "../utils/structures/Service"; |
import Service from "../utils/structures/Service"; |
6 |
import { deleteFile } from "../utils/util"; |
import { deleteFile, parseEmbedsInString } from "../utils/util"; |
7 |
|
|
8 |
export type Snippet = { |
export type Snippet = { |
9 |
name: string; |
name: string; |
10 |
content: string; |
content: string; |
11 |
files: string[] |
files: string[], |
12 |
|
embeds?: MessageEmbed[] |
13 |
}; |
}; |
14 |
|
|
15 |
export type SnippetContainer = { |
export type SnippetContainer = { |
59 |
|
|
60 |
return null; |
return null; |
61 |
} |
} |
62 |
|
|
63 |
|
getParsed(guildID: string, name: string): Snippet | null { |
64 |
|
const snippet = this.get(guildID, name); |
65 |
|
|
66 |
|
if (!snippet) { |
67 |
|
return null; |
68 |
|
} |
69 |
|
|
70 |
|
return this.parseEmbeds(snippet) ?? snippet; |
71 |
|
} |
72 |
|
|
73 |
|
parseEmbeds(snippet: Snippet) { |
74 |
|
try { |
75 |
|
const { embeds, content } = parseEmbedsInString(snippet.content); |
76 |
|
|
77 |
|
console.log(content); |
78 |
|
|
79 |
|
return <Snippet> { |
80 |
|
...snippet, |
81 |
|
content, |
82 |
|
embeds, |
83 |
|
}; |
84 |
|
} |
85 |
|
catch (e) { |
86 |
|
console.log(e); |
87 |
|
} |
88 |
|
} |
89 |
|
|
90 |
async delete(guildID: string, name: string): Promise<void> { |
async delete(guildID: string, name: string): Promise<void> { |
91 |
for (const i in this.snippets[guildID]) { |
for (const i in this.snippets[guildID]) { |
114 |
} |
} |
115 |
} |
} |
116 |
} |
} |
|
} |
|
117 |
|
} |