This repository was archived by the owner on Apr 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.js
More file actions
127 lines (110 loc) · 3.72 KB
/
Copy pathhelper.js
File metadata and controls
127 lines (110 loc) · 3.72 KB
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
/******************************
Variables & Libs
*******************************/
const moment = require("moment");
const config = require('./config').production;
const pool = config.getPool();
/******************************
Helper Functions
*******************************/
module.exports = {
refreshAllServers: async function(client, raid_event) {
// Refresh events in all servers on start-up
for( var guild of client.guilds.cache.values() ) {
if( guild.available ) {
pool.query("SELECT * FROM event_channel WHERE server_id = ?", [guild.id]).then(async function(results){
if( results.length > 0 ) {
for( var i = 0; i<results.length; i++ ) {
let channel = await client.channels.cache.get(results[i].channel_id);
if( channel ) {
await raid_event.getEvents(channel);
}
}
}
});
}
}
},
updateGuildChannels: async function(client, raid_event) {
console.log("-- Begin reorder check --");
if( client.guilds.cache.size > 0 ) {
for( var guild of client.guilds.cache.values() ) {
if( guild.available ) {
await pool.query("SELECT * FROM event_channel WHERE server_id = ?", [guild.id]).then(async function(results){
if( results.length > 0 ) {
for( var i = 0; i<results.length; i++ ) {
let channel = await client.channels.cache.get(results[i].channel_id);
if( channel && channel.guild.id == guild.id ) {
await raid_event.reorder(channel);
}
}
}
});
}
}
}
console.log("-- End reorder check --");
return;
},
// Print to console with timestamp prefix
isAdmin: function(member) {
if ( member.hasPermission('ADMINISTRATOR') ||
member.hasPermission('MANAGE_CHANNELS') ||
// member.roles.cache.find(roles => roles.name === "Admin") ||
Object.keys(config.adminIDs).includes(member.id) )
return true;
else
return false;
},
// Print to console with timestamp prefix
printStatus: function(text) {
console.log( "[" + moment().format() + "] " + text );
},
// Purge channel
clearChannel: async function(channel) {
try {
await channel.messages.fetch().then(async function(messages){
mids = messages.map(m => m.id);
if( mids.length > 0 ) {
for( var mid of mids ) {
await channel.messages.fetch(mid).then(async function(m){
if( m ) {
try {
await m.delete();
}
catch(e) {
console.log("DELETE MESSAGE ERROR", e);
if( e.message && e.message === 'Missing Permissions' ) {
channel.send("Error encountered: I require permission to delete messages in this channel");
}
}
}
});
}
}
});
}
catch(e) {
console.log("CLEAR CHANNEL ERROR", channel, e);
return;
}
},
// Check if channel belongs to server and is initialized
isChannelValid: async function(server_id, channel_id) {
return await pool.query("SELECT * FROM event_channel WHERE server_id = ? AND channel_id = ?", [server_id, channel_id]).then(function(result){
if( result.length > 0 )
return true
else
return false;
});
},
// Get channel id from DB
getChannel: async function(server_id) {
return await pool.query("SELECT channel_id FROM event_channel WHERE server_id = ?", [server_id]).then(function(result){
if( result.length > 0 )
return result[0].channel_id;
else
return null;
});
},
}