/[sudobot]/trunk/src/services/SnippetManager.ts
ViewVC logotype

Diff of /trunk/src/services/SnippetManager.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 244 by rakin, Mon Jul 29 17:29:11 2024 UTC revision 283 by rakin, Mon Jul 29 17:29:21 2024 UTC
# Line 1  Line 1 
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 = {
# Line 57  export default class SnippetManager exte Line 61  export default class SnippetManager exte
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]) {
# Line 85  export default class SnippetManager exte Line 116  export default class SnippetManager exte
116              }              }
117          }          }
118      }      }
 }  
119    }

Legend:
Removed from v.244  
changed lines
  Added in v.283

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26