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