|
import { APIEmbed } from "discord-api-types/v9"; |
|
|
import { MessageEmbedOptions } from "discord.js"; |
|
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"; |
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; |
67 |
return null; |
return null; |
68 |
} |
} |
69 |
|
|
70 |
snippet.embeds = this.parseEmbeds(snippet).embeds; |
return this.parseEmbeds(snippet) ?? snippet; |
|
|
|
|
return snippet; |
|
71 |
} |
} |
72 |
|
|
73 |
parseEmbeds(snippet: Snippet) {; |
parseEmbeds(snippet: Snippet) { |
74 |
const embedExpressions = snippet.content.matchAll(/embed\:(\{[^\n]+\})/g); |
try { |
75 |
snippet.content = snippet.content.replace(/embed\:(\{[^\n]+\})/g, ''); |
const { embeds, content } = parseEmbedsInString(snippet.content); |
|
let embeds: typeof snippet.embeds = []; |
|
76 |
|
|
77 |
for (const expr of [...embedExpressions]) { |
console.log(content); |
|
const parsed = JSON.parse(expr[1]); |
|
78 |
|
|
79 |
try { |
return <Snippet> { |
80 |
embeds.push(new MessageEmbed(parsed).setColor(parsed.color)); |
...snippet, |
81 |
} |
content, |
82 |
catch (e) { |
embeds, |
83 |
console.log(e); |
}; |
84 |
} |
} |
85 |
|
catch (e) { |
86 |
|
console.log(e); |
87 |
} |
} |
|
|
|
|
snippet.embeds = embeds; |
|
|
|
|
|
return snippet; |
|
88 |
} |
} |
89 |
|
|
90 |
async delete(guildID: string, name: string): Promise<void> { |
async delete(guildID: string, name: string): Promise<void> { |
114 |
} |
} |
115 |
} |
} |
116 |
} |
} |
|
} |
|
117 |
|
} |