1 |
import fs from 'fs'; |
import fs from 'fs'; |
2 |
|
import DiscordClient from '../client/Client'; |
3 |
|
import { GuildMember, Message, CommandInteraction, MessageEmbed, ContextMenuInteraction, Interaction } from 'discord.js'; |
4 |
import Axios, { AxiosRequestHeaders, HeadersDefaults } from 'axios'; |
import Axios, { AxiosRequestHeaders, HeadersDefaults } from 'axios'; |
5 |
|
|
6 |
|
export function splitMessage(message: string, limit: number = 1000, maxIterationCount: number = 100) { |
7 |
|
const splitted: string[] = []; |
8 |
|
let content = message; |
9 |
|
let { length } = content; |
10 |
|
|
11 |
|
if (length >= limit) { |
12 |
|
let i = 0; |
13 |
|
|
14 |
|
while (length !== 0 && content !== '') { |
15 |
|
splitted.push(content.substring(0, limit)); |
16 |
|
content = content.substring(limit); |
17 |
|
length = content.length; |
18 |
|
i++; |
19 |
|
|
20 |
|
if (i >= maxIterationCount) { |
21 |
|
console.log('Break loop'); |
22 |
|
break; |
23 |
|
} |
24 |
|
} |
25 |
|
} |
26 |
|
else { |
27 |
|
splitted.push(message); |
28 |
|
} |
29 |
|
|
30 |
|
return splitted; |
31 |
|
} |
32 |
|
|
33 |
|
export function getHomeGuild(client: DiscordClient) { |
34 |
|
return client.guilds.cache.get(client.config.props.global.id); |
35 |
|
} |
36 |
|
|
37 |
|
export function shouldNotModerate(client: DiscordClient, member: GuildMember) { |
38 |
|
if (!client.config.props[member.guild.id].admin) { |
39 |
|
return false; |
40 |
|
} |
41 |
|
|
42 |
|
const role = client.config.props[member.guild.id].admin; |
43 |
|
|
44 |
|
return member.roles.cache.has(role); |
45 |
|
} |
46 |
|
|
47 |
|
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") { |
48 |
|
let m = mod; |
49 |
|
|
50 |
|
if (!m) { |
51 |
|
m = msg.member! as GuildMember; |
52 |
|
} |
53 |
|
|
54 |
|
if (member.id !== m.id && member.roles.highest?.position >= m.roles.highest?.position) { |
55 |
|
if (msg instanceof Interaction && msg.deferred) { |
56 |
|
await msg.editReply({ |
57 |
|
embeds: [ |
58 |
|
new MessageEmbed() |
59 |
|
.setColor('#f14a60') |
60 |
|
.setDescription(`:x: ${error}`) |
61 |
|
] |
62 |
|
}); |
63 |
|
|
64 |
|
return false; |
65 |
|
} |
66 |
|
|
67 |
|
await msg.reply({ |
68 |
|
embeds: [ |
69 |
|
new MessageEmbed() |
70 |
|
.setColor('#f14a60') |
71 |
|
.setDescription(`:x: ${error}`) |
72 |
|
] |
73 |
|
}); |
74 |
|
|
75 |
|
return false; |
76 |
|
} |
77 |
|
|
78 |
|
return true; |
79 |
|
} |
80 |
|
|
81 |
export function timeProcess(seconds: number) { |
export function timeProcess(seconds: number) { |
82 |
let interval = seconds / (60 * 60 * 24 * 30 * 365); |
let interval = seconds / (60 * 60 * 24 * 30 * 365); |
83 |
|
|