5 |
import DiscordClient from "../client/Client"; |
import DiscordClient from "../client/Client"; |
6 |
import MessageEmbed from "../client/MessageEmbed"; |
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; |
41 |
} |
} |
42 |
|
|
43 |
set(guildID: string, name: string, content: string, files: string[] = []): void { |
set(guildID: string, name: string, content: string, files: string[] = []): void { |
44 |
|
if (!this.snippets[guildID]) { |
45 |
|
this.snippets[guildID] = []; |
46 |
|
} |
47 |
|
|
48 |
this.snippets[guildID].push({ |
this.snippets[guildID].push({ |
49 |
name, |
name, |
50 |
content, |
content, |
73 |
return null; |
return null; |
74 |
} |
} |
75 |
|
|
76 |
snippet.embeds = this.parseEmbeds(snippet).embeds; |
return this.parseEmbeds(snippet) ?? snippet; |
|
|
|
|
return snippet; |
|
77 |
} |
} |
78 |
|
|
79 |
parseEmbeds(snippet: Snippet) {; |
parseEmbeds(snippet: Snippet) { |
80 |
const embedExpressions = snippet.content.matchAll(/embed\:(\{[^\n]+\})/g); |
try { |
81 |
snippet.content = snippet.content.replace(/embed\:(\{[^\n]+\})/g, ''); |
const { embeds, content } = parseEmbedsInString(snippet.content); |
|
let embeds: typeof snippet.embeds = []; |
|
82 |
|
|
83 |
for (const expr of [...embedExpressions]) { |
console.log(content); |
|
const parsed = JSON.parse(expr[1]); |
|
84 |
|
|
85 |
try { |
return <Snippet> { |
86 |
embeds.push(new MessageEmbed(parsed).setColor(parsed.color)); |
...snippet, |
87 |
} |
content, |
88 |
catch (e) { |
embeds, |
89 |
console.log(e); |
}; |
90 |
} |
} |
91 |
|
catch (e) { |
92 |
|
console.log(e); |
93 |
} |
} |
|
|
|
|
snippet.embeds = embeds; |
|
|
|
|
|
return snippet; |
|
94 |
} |
} |
95 |
|
|
96 |
async delete(guildID: string, name: string): Promise<void> { |
async delete(guildID: string, name: string): Promise<void> { |