/[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 255 by rakin, Mon Jul 29 17:29:14 2024 UTC revision 283 by rakin, Mon Jul 29 17:29:21 2024 UTC
# Line 5  import path from "path"; Line 5  import path from "path";
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;
# Line 69  export default class SnippetManager exte Line 69  export default class SnippetManager exte
69              return null;              return null;
70          }          }
71    
72          snippet.embeds = this.parseEmbeds(snippet).embeds;          return this.parseEmbeds(snippet) ?? snippet;
   
         return snippet;  
73      }      }
74    
75      parseEmbeds(snippet: Snippet) {;      parseEmbeds(snippet: Snippet) {        
76          const embedExpressions = snippet.content.matchAll(/embed\:(\{[^\n]+\})/g);          try {
77          snippet.content = snippet.content.replace(/embed\:(\{[^\n]+\})/g, '');              const { embeds, content } = parseEmbedsInString(snippet.content);
         let embeds: typeof snippet.embeds = [];  
78    
79          for (const expr of [...embedExpressions]) {              console.log(content);            
             const parsed = JSON.parse(expr[1]);  
80    
81              try {              return <Snippet> {
82                  embeds.push(new MessageEmbed(parsed).setColor(parsed.color));                  ...snippet,
83              }                  content,
84              catch (e) {                  embeds,
85                  console.log(e);              };
86              }          }
87            catch (e) {
88                console.log(e);
89          }          }
   
         snippet.embeds = embeds;  
   
         return snippet;  
90      }      }
91    
92      async delete(guildID: string, name: string): Promise<void> {      async delete(guildID: string, name: string): Promise<void> {
# Line 122  export default class SnippetManager exte Line 116  export default class SnippetManager exte
116              }              }
117          }          }
118      }      }
 }  
119    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26