-
Notifications
You must be signed in to change notification settings - Fork 4
/
rolesBot.js
211 lines (164 loc) · 10 KB
/
rolesBot.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
const Discord=require('discord.js');
const config=require('./files/config.json');
const bot=new Discord.Client();
bot.on('ready', () => {
let CurrTime=new Date();
let mo=CurrTime.getMonth()+1;if(mo<10){mo="0"+mo;}let da=CurrTime.getDate();if(da<10){da="0"+da;}let yr=CurrTime.getFullYear();
let hr=CurrTime.getHours();if(hr<10){hr="0"+hr;}let min=CurrTime.getMinutes();if(min<10){min="0"+min;}let sec=CurrTime.getSeconds();if(sec<10){sec="0"+sec;}
let timeStamp="`"+yr+"/"+mo+"/"+da+"` **@** `"+hr+":"+min+":"+sec+"`";let timeStampSys="["+yr+"/"+mo+"/"+da+" @ "+hr+":"+min+":"+sec+"] ";
console.info(timeStampSys+'-- DISCORD HELPBOT [ROLES] IS READY --');console.log(console.error);
});
//
// SETTINGS
//
const freeServer="266787569419812864";
const vipServer="348653565721444352";
const rolesChan="402055424771358720";
//
// END OF: SETTINGS
//
bot.on("guildMemberAdd", member => {
let CurrTime=new Date();
let mo=CurrTime.getMonth()+1;if(mo<10){mo="0"+mo;}let da=CurrTime.getDate();if(da<10){da="0"+da;}let yr=CurrTime.getFullYear();
let hr=CurrTime.getHours();if(hr<10){hr="0"+hr;}let min=CurrTime.getMinutes();if(min<10){min="0"+min;}let sec=CurrTime.getSeconds();if(sec<10){sec="0"+sec;}
let timeStamp="`"+yr+"/"+mo+"/"+da+"` **@** `"+hr+":"+min+":"+sec+"`";let timeStampSys="["+yr+"/"+mo+"/"+da+" @ "+hr+":"+min+":"+sec+"] ";
let guild=member.guild; let user=member.user;
if(guild.id===freeServer){
// bot.channels.get(rolesChan).send(timeStamp+" "+user+"/"+user.username+" (`"+user.id+"`) has **joined** » [`"+guild.name+"`]");
let sdhUser=bot.guilds.get(vipServer).members.get(user.id);
if(!sdhUser){
// console.info(timeStampSys+"[AUTO-ROLES] User: \""+user.username+"\" ("+user.id+") not found in SDH-VIP");
return // bot.channels.get(rolesChan).send(timeStamp+"[AUTO-ROLES] User: \"**"+user.username+"**\" (`"+user.id+"`) was **not** found in » [`"+bot.guilds.get(vipServer).name+"`]");
}
// MEMBER ROLES
mRolesName=sdhUser.roles.map(r => r.name);mRolesName=mRolesName.slice(1);userRoleCount=mRolesName.length;
if(!mRolesName){userRoleCount=0}roleNames="NONE";
if(userRoleCount!==0){
roleNames=mRolesName
for(var r="0";r<userRoleCount;r++){
let rName=guild.roles.find('name', mRolesName[r]);
if(!rName){
bot.channels.get(rolesChan).send("I couldn't find role: **"+mRolesName[r]+"** over at `"+guild.name+"`, please make sure it exist, exact name!");
}
if(rName){
guild.members.get(user.id).addRole(rName).catch(console.error);
// bot.channels.get(rolesChan).send("👍 "+user+" has been given the role of: **"+mRolesName[r]+"**, over at: `"+guild.name+"`! 🎉");
}
}
}
return // bot.channels.get(rolesChan).send(timeStamp+"[AUTO-ROLES] User: \"**"+user.username+"**\" (`"+user.id+"`) has roles: `"+roleNames+"`");
}
if(guild.id===vipServer){
// bot.channels.get(rolesChan).send(timeStamp+" "+user+"/"+user.username+" (`"+user.id+"`) has **joined** » [`"+guild.name+"`]");
let sdhUser=bot.guilds.get(freeServer).members.get(user.id);
if(!sdhUser){
// console.info(timeStampSys+"[AUTO-ROLES] User: \""+user.username+"\" ("+user.id+") not found in SDH-VIP");
return // bot.channels.get(rolesChan).send(timeStamp+"[AUTO-ROLES] User: \"**"+user.username+"**\" (`"+user.id+"`) was **not** found in » [`"+bot.guilds.get(freeServer).name+"`]");
}
// MEMBER ROLES
mRolesName=sdhUser.roles.map(r => r.name);mRolesName=mRolesName.slice(1);userRoleCount=mRolesName.length;
if(!mRolesName){userRoleCount=0}roleNames="NONE";
if(userRoleCount!==0){
roleNames=mRolesName
for(var r="0";r<userRoleCount;r++){
let rName=guild.roles.find('name', mRolesName[r]);
if(!rName){
bot.channels.get(rolesChan).send("⚠ I couldn't find role: **"+mRolesName[r]+"** over at `"+guild.name+"`, please make sure it exist, it must have **exact name**!");
}
if(rName){
guild.members.get(user.id).addRole(rName).catch(console.error);
// bot.channels.get(rolesChan).send("👍 "+user+" has been given the role of: **"+mRolesName[r]+"**, over at: `"+guild.name+"`! 🎉");
}
}
}
return // bot.channels.get(rolesChan).send(timeStamp+"[AUTO-ROLES] User: \"**"+user.username+"**\" (`"+user.id+"`) has roles: `"+roleNames+"`");
}
});
bot.on("guildMemberUpdate", (oldMember,newMember) => {
g=oldMember.guild;
g.fetchAuditLogs({limit: 1,type: 25})
.then(auditLog => {
let masterName=auditLog.entries.map(u=>u.executor.username);let masterID=auditLog.entries.map(u=>u.executor.id);
let minionName=auditLog.entries.map(u=>u.target.username);let minionID=auditLog.entries.map(u=>u.target.id);
let action=auditLog.entries.map(u=>u.changes),roleName=auditLog.entries.map(u=>u.changes);
action=action[0][0].key;action=action.slice(1);let action2="";roleName=roleName[0][0].new[0].name;
if(action==="add"){action="added"; action2="to"}if(action==="remove"){action="removed"; action2="from"}
bot.channels.get(rolesChan).send("**"+masterName+"**(`"+masterID+"`) has **"+action+"** role: "
+"`"+roleName+"` "+action2+" **"+minionName+"**(`"+minionID+"`) over at `"+g.name+"`");
if(g.id===freeServer){
let sdhUser=bot.guilds.get(vipServer).members.get(""+minionID+"");
if(!sdhUser){
// console.info(timeStampSys+"[AUTO-ROLES] User: \""+user.username+"\" ("+user.id+") not found in SDH-VIP");
return // bot.channels.get(rolesChan).send(timeStamp+"[AUTO-ROLES] User: \"**"+user.username+"**\" (`"+user.id+"`) was **not** found in » [`"+bot.guilds.get(freeServer).name+"`]");
}
let rName=bot.guilds.get(vipServer).roles.find('name', roleName);
if(!rName){
return bot.channels.get(rolesChan).send("⚠ I couldn't find role: **"+roleName+"** over at `"+bot.guilds.get(vipServer).name+"`, please make sure it exist, it must have **exact name**!");
}
if(action==="added"){
bot.guilds.get(vipServer).members.get(""+minionID+"").addRole(rName).catch(console.error);
return // bot.channels.get(rolesChan).send("👍 <@"+minionID+"> has been given the role of: **"+roleName+"**! 🎉");
}
bot.guilds.get(vipServer).members.get(""+minionID+"").removeRole(rName).catch(console.error);
return // bot.channels.get(rolesChan).send("⚠ <@"+minionID+"> have **lost** their role of: **"+roleName+"**! 😅");
}
if(g.id===vipServer){
let sdhUser=bot.guilds.get(freeServer).members.get(""+minionID+"");
if(!sdhUser){
// console.info(timeStampSys+"[AUTO-ROLES] User: \""+user.username+"\" ("+user.id+") not found in SDH-VIP");
return // bot.channels.get(rolesChan).send(timeStamp+"[AUTO-ROLES] User: \"**"+user.username+"**\" (`"+user.id+"`) was **not** found in » [`"+bot.guilds.get(freeServer).name+"`]");
}
let rName=bot.guilds.get(freeServer).roles.find('name', roleName);
if(!rName){
return bot.channels.get(rolesChan).send("⚠ I couldn't find role: **"+roleName+"** over at `"+bot.guilds.get(freeServer).name+"`, please make sure it exist, it must have **exact name**!");
}
if(action==="added"){
bot.guilds.get(freeServer).members.get(""+minionID+"").addRole(rName).catch(console.error);
return // bot.channels.get(rolesChan).send("👍 <@"+minionID+"> has been given the role of: **"+roleName+"**! 🎉");
}
bot.guilds.get(freeServer).members.get(""+minionID+"").removeRole(rName).catch(console.error);
return // bot.channels.get(rolesChan).send("⚠ <@"+minionID+"> have **lost** their role of: **"+roleName+"**! 😅");
}
});
});
bot.on('message', message => {
let CurrTime=new Date();
let mo=CurrTime.getMonth()+1;if(mo<10){mo="0"+mo;}let da=CurrTime.getDate();if(da<10){da="0"+da;}let yr=CurrTime.getFullYear();
let hr=CurrTime.getHours();if(hr<10){hr="0"+hr;}let min=CurrTime.getMinutes();if(min<10){min="0"+min;}let sec=CurrTime.getSeconds();if(sec<10){sec="0"+sec;}
let timeStamp="`"+yr+"/"+mo+"/"+da+"` **@** `"+hr+":"+min+":"+sec+"`";let timeStampSys="["+yr+"/"+mo+"/"+da+" @ "+hr+":"+min+":"+sec+"] ";
//STOP SCRIPT IF DM/PM
if(message.channel.type=="dm"){ return }
// GET CHANNEL INFO
let g=message.guild; let c=message.channel; let m=message.member; let msg=message.content.toLowerCase();
// GET TAGGED USER
let mentioned=""; if(message.mentions.users.first()){mentioned=message.mentions.users.first();}
// REMOVE LETTER CASE (MAKE ALL LOWERCASE)
let command=msg.toLowerCase(); command=command.split(" ")[0]; command=command.slice(config.cmdPrefix.length);
// GET ARGUMENTS
let args=msg.split(" ").slice(1);
// DATE&TIME VALUES
const DTdays=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
const DTmonths=["January","February","March","April","May","June","July","August","September","October","November","December"];
// ############################################################################
// ############################## COMMANDS BEGIN ##############################
// ############################################################################
if(command==="restart"){
if(m.id===config.ownerID || m.id==="295245211007844352" || m.id==="237260406144499712"){
if(args[0]==="roles"){
message.reply("Restarting **RolesChecker** (`rolesBot.js`) module... please wait `3` to `5` seconds").then(()=>{ process.exit(1) }).catch(console.error);
}
}
}
});
//
// CONNECT BOT TO DISCORD
//
bot.login(config.token);
bot.on('disconnected', function (){
let CurrTime=new Date();
let mo=CurrTime.getMonth()+1;if(mo<10){mo="0"+mo;}let da=CurrTime.getDate();if(da<10){da="0"+da;}let yr=CurrTime.getFullYear();
let hr=CurrTime.getHours();if(hr<10){hr="0"+hr;}let min=CurrTime.getMinutes();if(min<10){min="0"+min;}let sec=CurrTime.getSeconds();if(sec<10){sec="0"+sec;}
let timeStamp="`"+yr+"/"+mo+"/"+da+"` **@** `"+hr+":"+min+":"+sec+"`";let timeStampSys="["+yr+"/"+mo+"/"+da+" @ "+hr+":"+min+":"+sec+"] ";
console.info(timeStampSys+'-- Disconnected --');console.log(console.error);
process.exit(1);
});