1 |
|
/** |
2 |
|
* This file is part of SudoBot. |
3 |
|
* |
4 |
|
* Copyright (C) 2021-2022 OSN Inc. |
5 |
|
* |
6 |
|
* SudoBot is free software; you can redistribute it and/or modify it |
7 |
|
* under the terms of the GNU Affero General Public License as published by |
8 |
|
* the Free Software Foundation, either version 3 of the License, or |
9 |
|
* (at your option) any later version. |
10 |
|
* |
11 |
|
* SudoBot is distributed in the hope that it will be useful, but |
12 |
|
* WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
* GNU Affero General Public License for more details. |
15 |
|
* |
16 |
|
* You should have received a copy of the GNU Affero General Public License |
17 |
|
* along with SudoBot. If not, see <https://www.gnu.org/licenses/>. |
18 |
|
*/ |
19 |
|
|
20 |
import fs from 'fs'; |
import fs from 'fs'; |
21 |
import DiscordClient from '../client/Client'; |
import DiscordClient from '../client/Client'; |
22 |
import { GuildMember, Message, CommandInteraction, MessageEmbed, ContextMenuInteraction, Interaction } from 'discord.js'; |
import { GuildMember, Message, CommandInteraction, MessageEmbed, ContextMenuInteraction, Interaction } from 'discord.js'; |
23 |
import Axios, { AxiosRequestHeaders, HeadersDefaults } from 'axios'; |
import Axios, { AxiosRequestHeaders } from 'axios'; |
24 |
import { formatDistanceToNowStrict } from 'date-fns'; |
import { formatDistanceToNowStrict, formatDuration, intervalToDuration } from 'date-fns'; |
|
import { Snippet } from '../services/SnippetManager'; |
|
25 |
|
|
26 |
export function parseEmbedsInString(content: string) { |
export function parseEmbedsInString(content: string) { |
27 |
const embedExpressions = content.matchAll(/embed\:(\{[^\n]+\})/g); |
const embedExpressions = content.matchAll(/embed\:(\{[^\n]+\})/g); |
80 |
|
|
81 |
const role = client.config.props[member.guild.id].admin; |
const role = client.config.props[member.guild.id].admin; |
82 |
|
|
83 |
return member.roles.cache.has(role); |
return role && role.trim() !== '' && member.roles.cache.has(role); |
84 |
} |
} |
85 |
|
|
86 |
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") { |
90 |
m = msg.member! as GuildMember; |
m = msg.member! as GuildMember; |
91 |
} |
} |
92 |
|
|
93 |
if (member.id !== m.id && member.roles.highest?.position >= m.roles.highest?.position) { |
if (member.id === m.id || member.roles.highest?.position >= m.roles.highest?.position) { |
94 |
if (msg instanceof Interaction && msg.deferred) { |
if (msg instanceof Interaction && msg.deferred) { |
95 |
await msg.editReply({ |
await msg.editReply({ |
96 |
embeds: [ |
embeds: [ |
118 |
} |
} |
119 |
|
|
120 |
export function timeProcess(seconds: number) { |
export function timeProcess(seconds: number) { |
121 |
return formatDistanceToNowStrict(new Date(seconds)); |
return formatDuration(intervalToDuration({ start: 0, end: seconds * 1000 })); |
122 |
} |
} |
123 |
|
|
124 |
|
|