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 Service from "../utils/structures/Service"; |
5 |
import { deleteFile } from "../utils/util"; |
import { deleteFile } from "../utils/util"; |
6 |
|
|
7 |
export type Snippet = { |
export type Snippet = { |
14 |
[guildID: string]: Snippet[]; |
[guildID: string]: Snippet[]; |
15 |
}; |
}; |
16 |
|
|
17 |
export default class SnippetManager { |
export default class SnippetManager extends Service { |
18 |
snippets: SnippetContainer = {}; |
snippets: SnippetContainer = {}; |
|
client: DiscordClient; |
|
19 |
|
|
20 |
constructor(client: DiscordClient) { |
constructor(client: DiscordClient) { |
21 |
this.client = client; |
super(client); |
22 |
this.load(); |
this.load(); |
23 |
} |
} |
24 |
|
|
45 |
} |
} |
46 |
|
|
47 |
get(guildID: string, name: string): Snippet | null { |
get(guildID: string, name: string): Snippet | null { |
48 |
|
if (!this.snippets[guildID]) { |
49 |
|
return null; |
50 |
|
} |
51 |
|
|
52 |
for (const s of this.snippets[guildID]) { |
for (const s of this.snippets[guildID]) { |
53 |
if (s.name === name) { |
if (s.name === name) { |
54 |
return s; |
return s; |