2 |
import DiscordClient from '../client/Client'; |
import DiscordClient from '../client/Client'; |
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 { formatDistanceToNowStrict } 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[] = []; |
62 |
|
|
63 |
const role = client.config.props[member.guild.id].admin; |
const role = client.config.props[member.guild.id].admin; |
64 |
|
|
65 |
return member.roles.cache.has(role); |
return role && role.trim() !== '' && member.roles.cache.has(role); |
66 |
} |
} |
67 |
|
|
68 |
export async function hasPermission(client: DiscordClient, member: GuildMember, msg: Message | CommandInteraction | ContextMenuInteraction, mod: GuildMember | null, error: string = "You don't have permission to moderate this user") { |
export async function hasPermission(client: DiscordClient, member: GuildMember, msg: Message | CommandInteraction | ContextMenuInteraction, mod: GuildMember | null, error: string = "You don't have permission to moderate this user") { |
100 |
} |
} |
101 |
|
|
102 |
export function timeProcess(seconds: number) { |
export function timeProcess(seconds: number) { |
103 |
return formatDistance(new Date(), new Date(seconds)); |
return formatDistanceToNowStrict(new Date(seconds)); |
104 |
} |
} |
105 |
|
|
106 |
|
|
150 |
export function timeSince(date: number) { |
export function timeSince(date: number) { |
151 |
// const seconds = Math.floor((Date.now() - date) / 1000); |
// const seconds = Math.floor((Date.now() - date) / 1000); |
152 |
// return timeProcess(seconds) + ' ago'; |
// return timeProcess(seconds) + ' ago'; |
153 |
return formatDistance(new Date(), new Date(date), { addSuffix: true }); |
return formatDistanceToNowStrict(new Date(date), { addSuffix: true }); |
154 |
} |
} |
155 |
|
|
156 |
export async function download(url: string, path: string, headers?: AxiosRequestHeaders) { |
export async function download(url: string, path: string, headers?: AxiosRequestHeaders) { |