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 { formatDistance } from 'date-fns'; |
import { formatDistanceToNowStrict, formatDuration, intervalToDuration } from 'date-fns'; |
|
import { Snippet } from '../services/SnippetManager'; |
|
6 |
|
|
7 |
export function parseEmbedsInString(content: string) { |
export function parseEmbedsInString(content: string) { |
8 |
const embedExpressions = content.matchAll(/embed\:(\{[^\n]+\})/g); |
const embedExpressions = content.matchAll(/embed\:(\{[^\n]+\})/g); |
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") { |
99 |
} |
} |
100 |
|
|
101 |
export function timeProcess(seconds: number) { |
export function timeProcess(seconds: number) { |
102 |
return formatDistance(new Date(), new Date(seconds)); |
return formatDuration(intervalToDuration({ start: 0, end: seconds * 1000 })); |
103 |
} |
} |
104 |
|
|
105 |
|
|
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 formatDistance(new Date(), new Date(date), { addSuffix: true }); |
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) { |