18 |
|
|
19 |
export default class SnippetManager extends Service { |
export default class SnippetManager extends Service { |
20 |
snippets: SnippetContainer = {}; |
snippets: SnippetContainer = {}; |
21 |
|
filePath: string; |
22 |
|
|
23 |
constructor(client: DiscordClient) { |
constructor(client: DiscordClient) { |
24 |
super(client); |
super(client); |
25 |
|
this.filePath = path.resolve(process.env.SUDO_PREFIX ?? path.join(__dirname, '../..'), 'config/snippets.json'); |
26 |
this.load(); |
this.load(); |
27 |
} |
} |
28 |
|
|
29 |
load() { |
load() { |
30 |
readFile(path.resolve(__dirname, '../..', 'config/snippets.json'), (err, data) => { |
readFile(this.filePath, (err, data) => { |
31 |
if (err) { |
if (err) { |
32 |
console.log(err); |
console.log(err); |
33 |
} |
} |
37 |
} |
} |
38 |
|
|
39 |
write() { |
write() { |
40 |
writeFile(path.resolve(__dirname, '../..', 'config/snippets.json'), JSON.stringify(this.snippets), () => null); |
writeFile(this.filePath, JSON.stringify(this.snippets), () => null); |
41 |
} |
} |
42 |
|
|
43 |
set(guildID: string, name: string, content: string, files: string[] = []): void { |
set(guildID: string, name: string, content: string, files: string[] = []): void { |
94 |
if (this.snippets[guildID][i].name === name) { |
if (this.snippets[guildID][i].name === name) { |
95 |
for await (const file of this.snippets[guildID][i].files) { |
for await (const file of this.snippets[guildID][i].files) { |
96 |
try { |
try { |
97 |
await deleteFile(path.resolve(__dirname, '../../storage', file)); |
await deleteFile(path.resolve(process.env.SUDO_PREFIX ?? path.join(__dirname, '../..'), 'storage', file)); |
98 |
} |
} |
99 |
catch (e) { |
catch (e) { |
100 |
console.log(e); |
console.log(e); |