1 |
import fs from 'fs'; |
import fs from 'fs'; |
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 } from 'axios'; |
5 |
|
import { formatDistanceToNowStrict, formatDuration, intervalToDuration } from 'date-fns'; |
6 |
|
|
7 |
|
export function parseEmbedsInString(content: string) { |
8 |
|
const embedExpressions = content.matchAll(/embed\:(\{[^\n]+\})/g); |
9 |
|
const newContent = content.replace(/embed\:(\{[^\n]+\})/g, ''); |
10 |
|
let embeds: MessageEmbed[] = []; |
11 |
|
|
12 |
|
for (const expr of [...embedExpressions]) { |
13 |
|
const parsed = JSON.parse(expr[1]); |
14 |
|
|
15 |
|
try { |
16 |
|
embeds.push(new MessageEmbed(parsed).setColor(parsed.color)); |
17 |
|
} |
18 |
|
catch (e) { |
19 |
|
console.log(e); |
20 |
|
} |
21 |
|
} |
22 |
|
|
23 |
|
return { embeds, content: newContent }; |
24 |
|
} |
25 |
|
|
26 |
export function splitMessage(message: string, limit: number = 1000, maxIterationCount: number = 100) { |
export function splitMessage(message: string, limit: number = 1000, maxIterationCount: number = 100) { |
27 |
const splitted: string[] = []; |
const splitted: string[] = []; |
61 |
|
|
62 |
const role = client.config.props[member.guild.id].admin; |
const role = client.config.props[member.guild.id].admin; |
63 |
|
|
64 |
return member.roles.cache.has(role); |
return role && role.trim() !== '' && member.roles.cache.has(role); |
65 |
} |
} |
66 |
|
|
67 |
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") { |
98 |
return true; |
return true; |
99 |
} |
} |
100 |
|
|
101 |
export function timeProcess(seconds: number) { |
export function timeProcess(seconds: number) { |
102 |
|
return formatDuration(intervalToDuration({ start: 0, end: seconds * 1000 })); |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
/** |
107 |
|
* @deprecated |
108 |
|
*/ |
109 |
|
export function timeProcessOld(seconds: number) { |
110 |
let interval = seconds / (60 * 60 * 24 * 30 * 365); |
let interval = seconds / (60 * 60 * 24 * 30 * 365); |
111 |
|
|
112 |
if (interval >= 1) { |
if (interval >= 1) { |
147 |
} |
} |
148 |
|
|
149 |
export function timeSince(date: number) { |
export function timeSince(date: number) { |
150 |
const seconds = Math.floor((Date.now() - date) / 1000); |
// const seconds = Math.floor((Date.now() - date) / 1000); |
151 |
return timeProcess(seconds) + ' ago'; |
// return timeProcess(seconds) + ' ago'; |
152 |
|
return formatDistanceToNowStrict(new Date(date), { addSuffix: true }); |
153 |
} |
} |
154 |
|
|
155 |
export async function download(url: string, path: string, headers?: AxiosRequestHeaders) { |
export async function download(url: string, path: string, headers?: AxiosRequestHeaders) { |