-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect.js
93 lines (66 loc) · 2.46 KB
/
collect.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
const { Client, Intents, Permissions } = require('discord.js');
const CronJob = require('cron').CronJob;
const { clientId, guildId, token, user, password, host, database, port, adminRole, supportChannelID, roles, userTable, membershipTable, botID } = require('./config.json');
const mysql = require('mysql');
const { RequestManager } = require('@discordjs/rest');
const client = new Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MEMBERS", "DIRECT_MESSAGES"], partials: ["CHANNEL"], fetchAllMembers: true });
function createQuery(query, callback){
var result;
var con = mysql.createConnection({
host: host,
user: user,
password: password,
database : database,
port : port
});
con.connect(function(err){
if(err) throw err;
console.log('Connected!');
console.log(query);
con.query(query, function(error, rows, fields){
if(!!error){
console.log(error);
con.end();
return callback('error');
}else{
con.end();
return callback(rows);
}
})
});
}
function init(){
const list = client.guilds.cache.get(guildId);
var con = mysql.createConnection({
host: host,
user: user,
password: password,
database : database,
port : port
});
con.connect(function(err){
if(err) throw err;
console.log('Connected!');
list.members.fetch({cache:false}).then(async members => {
for (let [key, value] of members) {
await sleep(100);
if(members.get(key).user.id != botID){
console.log(`UPDATE ${userTable} SET discord="${members.get(key).user.id}" WHERE discord="${members.get(key).user.username}#${members.get(key).user.discriminator}"`);
con.query(`UPDATE ${userTable} SET discord="${members.get(key).user.username}#${members.get(key).user.discriminator}" WHERE user_login="${members.get(key).user.username}"`, function(error, rows, fields){
})
}
}
con.end();
});
});
}
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
client.once('ready', () => {
console.log('Ready!');
init();
});
client.login(token);