/[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 344 by rakin, Mon Jul 29 17:29:40 2024 UTC
# Line 1  Line 1 
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";
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;
10      content: string;      content: string;
11      files: string[]      files: string[],
12        embeds?: MessageEmbed[]
13  };  };
14    
15  export type SnippetContainer = {  export type SnippetContainer = {
# Line 57  export default class SnippetManager exte Line 59  export default class SnippetManager exte
59    
60          return null;          return null;
61      }      }
62        
63        getParsed(guildID: string, name: string): Snippet | null {
64            const snippet = this.get(guildID, name);
65    
66            if (!snippet) {
67                return null;
68            }
69    
70            return this.parseEmbeds(snippet) ?? snippet;
71        }
72    
73        parseEmbeds(snippet: Snippet) {        
74            try {
75                const { embeds, content } = parseEmbedsInString(snippet.content);
76    
77                console.log(content);            
78    
79                return <Snippet> {
80                    ...snippet,
81                    content,
82                    embeds,
83                };
84            }
85            catch (e) {
86                console.log(e);
87            }
88        }
89    
90      async delete(guildID: string, name: string): Promise<void> {      async delete(guildID: string, name: string): Promise<void> {
91          for (const i in this.snippets[guildID]) {          for (const i in this.snippets[guildID]) {
# Line 85  export default class SnippetManager exte Line 114  export default class SnippetManager exte
114              }              }
115          }          }
116      }      }
 }  
117    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26