/[sudobot]/trunk/src/utils/util.ts
ViewVC logotype

Diff of /trunk/src/utils/util.ts

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

revision 239 by rakin, Mon Jul 29 17:29:09 2024 UTC revision 256 by rakin, Mon Jul 29 17:29:14 2024 UTC
# Line 3  import DiscordClient from '../client/Cli Line 3  import DiscordClient from '../client/Cli
3  import { GuildMember, Message, CommandInteraction, MessageEmbed, ContextMenuInteraction, Interaction } from 'discord.js';  import { GuildMember, Message, CommandInteraction, MessageEmbed, ContextMenuInteraction, Interaction } from 'discord.js';
4  import Axios, { AxiosRequestHeaders, HeadersDefaults } from 'axios';  import Axios, { AxiosRequestHeaders, HeadersDefaults } from 'axios';
5  import { formatDistance } from 'date-fns';  import { formatDistance } from 'date-fns';
6    import { Snippet } from '../services/SnippetManager';
7    
8    export function parseEmbedsInString(content: string) {
9        const embedExpressions = content.matchAll(/embed\:(\{[^\n]+\})/g);
10        const newContent = content.replace(/embed\:(\{[^\n]+\})/g, '');
11        let embeds: MessageEmbed[] = [];
12    
13        for (const expr of [...embedExpressions]) {
14            const parsed = JSON.parse(expr[1]);
15    
16            try {
17                embeds.push(new MessageEmbed(parsed).setColor(parsed.color));    
18            }
19            catch (e) {
20                console.log(e);
21            }
22        }
23    
24        return { embeds, content: newContent };
25    }
26    
27  export function splitMessage(message: string, limit: number = 1000, maxIterationCount: number = 100) {  export function splitMessage(message: string, limit: number = 1000, maxIterationCount: number = 100) {
28      const splitted: string[] = [];      const splitted: string[] = [];

Legend:
Removed from v.239  
changed lines
  Added in v.256

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26