-
Notifications
You must be signed in to change notification settings - Fork 12
/
functions.js
131 lines (106 loc) · 3.28 KB
/
functions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
function generateError (type, error, reason) {
if (reason) {
console.log(">> ERROR", "\n", `Type: ${type}`, "\n", `Error Code: \n${error}`, "\n", `Reason/Origin: ${reason}`)
} else {
console.log(">> ERROR", "\n", `Type: ${type}`, "\n", `Error Code: \n${error}`)
}
}
function isAffiliateLink(url) {
var affiliateParams = ['ref', 'affiliate', 'tag', 'tracking'];
for (var i = 0; i < affiliateParams.length; i++) {
if (url.indexOf(affiliateParams[i] + '=') !== -1) {
return true;
}
}
if (
url.indexOf('://amzn.to/') !== -1 ||
url.indexOf('://rstyle.me/') !== -1 ||
url.indexOf('://go.redirectingat.com/') !== -1
) {
return true;
}
return false;
}
function generateHtmlTranscript(messages, channel, guildId) {
let html = `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Bulk Delete</title>
</head>
<body>
<h1>Transscript - Deleted Messages</h1>
<p>Channel: ${channel.name} (ID: ${channel.id})</p>
<p>Server ID: ${guildId}</p>
<p>Amount of deleted messages: ${messages.size}</p>
<ul>
`;
messages.forEach(message => {
const content = message.content || '[Picture/File]';
html += `<li><strong>${message.author.tag}</strong>: ${content}</li>`;
});
html += `
</ul>
</body>
</html>
`;
return html;
}
function generateRandomCode(length) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
result += characters[randomIndex];
}
return result;
}
function convertToMilliseconds(timeString) {
if (typeof timeString !== 'string') {
throw new Error('timeString must be a string');
}
const units = {
s: 1000,
m: 60 * 1000,
h: 60 * 60 * 1000,
d: 24 * 60 * 60 * 1000,
M: 30 * 24 * 60 * 60 * 1000,
y: 365 * 24 * 60 * 60 * 1000
};
const match = timeString.match(/^(\d+)([smhdyM])$/);
if (!match) {
throw new Error('Invalid time string format');
}
const value = parseInt(match[1], 10);
const unit = match[2];
return value * (units[unit] || 0);
}
function convertUnix(milliseconds) {
return Math.floor(milliseconds / 1000);
}
const { PermissionFlagsBits } = require("discord.js");
const { client } = require("./src");
async function perm(v) {
try {
// Ensure client is ready before accessing guilds
await client.ready;
const guild = await client.guilds.fetch(v);
const member = await guild.members.fetch(client.user);
if (!member.permissions.has(PermissionFlagsBits.VIEW_AUDIT_LOG)) {
return false; // Return false if permission is not granted
}
return true; // Return true if permission is granted
} catch (error) {
return false; // Return false in case of error
}
}
module.exports = {
generateError,
isAffiliateLink,
generateHtmlTranscript,
generateRandomCode,
convertToMilliseconds,
convertUnix,
perm
}