-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
408 lines (390 loc) · 14.4 KB
/
index.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
require('dotenv').config()
const Discord = require("discord.js")
const mongo = require('./mongo')
const profileSchema = require('./schemas/profile.js')
const client = new Discord.Client(
{
intents: [
"GUILDS",
"GUILD_MESSAGES",
"DIRECT_MESSAGES"
], partials: [
"CHANNEL"
]
});
const { MessageEmbed } = require('discord.js');
const cache = {} // id: [result array]
const GNU=`https://cdn.discordapp.com/icons/887577819381653515/19ff87484841f631638ddc2d9366df22.webp?size=128`;
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`)
});
client.on("messageCreate", async message => {
if(message.content.startsWith(`!sync`) && (message.author.id==="428902961847205899"
|| message.member.roles.cache.find(r => r.name === "Club Secretary")
|| message.member.roles.cache.find(r => r.name === "Moderators"))){
var data ;
console.log('FETCHING FROM DATABASE')
await mongo().then(async (mongoose) => {
try {
data = await profileSchema.find()
}
finally {
mongoose.connection.close()
data.forEach(element => {
cache[element.id]=element
});
message.channel.send(`Current count of profiles = ${data.length} \nTime taken to fetch data : ${Date.now() - message.createdTimestamp}ms`)
}
})
}
const filter = m => m.author.id === message.author.id;
if(message.content.startsWith(`!git `)){
let text = message.content.slice(5);
await mongo().then(async (mongoose) => {
try {
await profileSchema.findOneAndUpdate({
_id: message.author.id
}, {
_id: message.author.id,
git: text,
}, {
upsert: true
})
}
catch(err) {
console.error(err)
}
finally {
mongoose.connection.close()
}
})
}
if(message.content.startsWith(`!df `)){
let text = message.content.slice(4);
await mongo().then(async (mongoose) => {
try {
await profileSchema.findOneAndUpdate({
_id: message.author.id
}, {
_id: message.author.id,
df: text,
}, {
upsert: true
})
}
catch(err) {
console.error(err)
}
finally {
mongoose.connection.close()
}
})
}
if(message.content.startsWith(`!img `)){
let text = message.content.slice(5);
await mongo().then(async (mongoose) => {
try {
await profileSchema.findOneAndUpdate({
_id: message.author.id
}, {
_id: message.author.id,
img: text,
}, {
upsert: true
})
}
catch(err) {
console.error(err)
}
finally {
mongoose.connection.close()
}
})
}
if(message.content.startsWith(`!fetch`)){
const myProfile = new MessageEmbed()
var fetchedUserPFP
var fetchedUser
if(message.content===`!fetch`){
fetchedUser = message.author;
fetchedUserPFP = fetchedUser.displayAvatarURL({size: 1024, dynamic: true})
}
else if(message.mentions.users.first()){
fetchedUser = message.mentions.users.first()
fetchedUserPFP = fetchedUser.displayAvatarURL({size: 1024, dynamic: true})
const UserPFP = message.member.user.avatarURL();
myProfile.setFooter(`Info requested by ${message.author.tag}`, UserPFP)
}
else if(message.content.split(' ').length === 2){
const split = message.content.split(' ')
split.shift()
text = split.join(' ')
await client.users.fetch(text)
.then((user) => {
fetchedUser = user
fetchedUserPFP = fetchedUser.displayAvatarURL({size: 1024, dynamic: true})
})
.catch(err => {
console.log(`unable to fetch user through ID : ${text}`)
// return
})
}
else{
message.channel.send("Kindly mention someone.")
return;
}
if(!fetchedUser){
message.channel.send("Kindly mention someone.")
return;
}
var result = cache[fetchedUser.id]
if(!result){
await mongo().then(async (mongoose) => {
try {
result = await profileSchema.findOne({ _id: fetchedUser.id })
var lameHead="My profile"
if(!result){
myProfile.setColor('RANDOM')
.setTimestamp()
.setDescription("This user is too busy.")
message.channel.send({ embeds: [myProfile] })
return;
}
if(result.IIITB==="1"){
lameHead="IIIT Bhopal Student"
}
if(result.git) lameGit=result.git
myProfile.setColor('RANDOM')
.setTitle(lameHead)
.setThumbnail(GNU)
.setTimestamp()
.setAuthor(result.SName,fetchedUserPFP,"https://discord.gg/M9KMPzBj")
.addFields(
{ name: 'Scholar No.', value: result.SNo, inline: true },
{ name: 'Branch', value: result.Branch, inline: true },
{ name: 'Year of Graduation', value: result.Year, inline: true },
{ name: '\u200B', value: '\u200B' },
{ name: 'Distro', value: result.Distro, inline: true },
{ name: 'Editor', value: result.Editor, inline: true },
{ name: 'Shell', value: result.Shell, inline: true },
{ name: '\u200B', value: '\u200B' },
{ name: 'CPU', value: result.CPU, inline: true },
{ name: 'GPU', value: result.GPU, inline: true },
{ name: 'Memory', value: result.Memory, inline: true },
{ name: '\u200B', value: '\u200B' },
)
if(result.git) myProfile.setDescription(result.git)
else myProfile.setDescription('\u200B')
if(result.img) myProfile.setImage(result.img)
else myProfile.setImage(`https://images-ext-2.discordapp.net/external/TFqqarchefYbJdnbWCxresJG3HA2G1SGpYE3O3_7qDw/https/i.imgur.com/98CUqwqh.jpg`)
if(result.df) myProfile.addFields({ name: 'Dotfiles', value: result.df,})
message.channel.send({ embeds: [myProfile] })
} catch(err) {
console.error(err)
} finally {
mongoose.connection.close()
}
})
}
else{
var lameHead="My profile"
if(result.IIITB==="1"){
lameHead="IIIT Bhopal Student"
}
if(result.git) lameGit=result.git
myProfile.setColor('RANDOM')
.setTitle(lameHead)
.setThumbnail(GNU)
.setTimestamp()
.setAuthor(result.SName,fetchedUserPFP,"https://discord.gg/M9KMPzBj")
.addFields(
{ name: 'Scholar No.', value: result.SNo, inline: true },
{ name: 'Branch', value: result.Branch, inline: true },
{ name: 'Year of Graduation', value: result.Year, inline: true },
{ name: '\u200B', value: '\u200B' },
{ name: 'Distro', value: result.Distro, inline: true },
{ name: 'Editor', value: result.Editor, inline: true },
{ name: 'Shell', value: result.Shell, inline: true },
{ name: '\u200B', value: '\u200B' },
{ name: 'CPU', value: result.CPU, inline: true },
{ name: 'GPU', value: result.GPU, inline: true },
{ name: 'Memory', value: result.Memory, inline: true },
{ name: '\u200B', value: '\u200B' },
)
if(result.git) myProfile.setDescription(result.git)
else myProfile.setDescription('\u200B')
if(result.img) myProfile.setImage(result.img)
else myProfile.setImage(`https://images-ext-2.discordapp.net/external/TFqqarchefYbJdnbWCxresJG3HA2G1SGpYE3O3_7qDw/https/i.imgur.com/98CUqwqh.jpg`)
if(result.df) myProfile.addFields({ name: 'Dotfiles', value: result.df,})
message.channel.send({ embeds: [myProfile] })
}
}// if(message.content.startsWith(`!setfet`)){
if(message.content.startsWith(`!setfet`) && (message.channel.type === "DM")){
if(!message.content.includes("Distro")) return;
if(!message.content.includes("GPU")) return;
if(!message.content.includes("CPU")) return;
message.channel.send("If you are from IIIT Bhopal\nReply with *Y*. and if not, reply with *N*")
const collectorIIITB = message.channel.createMessageCollector({ filter, max:1, time: 20000 });
collectorIIITB.on('collect', mIB => {
var IIITB=false;
if(mIB.content.toUpperCase()===`Y`){IIITB=true}
else{
message.channel.send("Currently we are serving for IIIT Bhopal only")
return;
}
const UserPFP = message.author.avatarURL();
let text=message.content
const split = text.split('\n')
split.shift()
var i=0
var arr=[];
for(i=0;i<14;i++){
if(split[i]){
if (split[i].indexOf(':') !== -1) {
if(split[i].split(':')[1])
arr[i] = split[i].split(':')[1]
else{
arr[i]="NULL"
}
}
}
}
if(arr[13]){
var space = arr[13].match(/\d/g);
space=space.join("")
space=(space/1048576).toString().substring(0,4);
space=space+" GB";
}else{
arr[13]="NULL"
}
const myProfile = new MessageEmbed()
var yearG="0";
var branch="0";
var schn="0";
var sName="xyz";
var k=0;
message.channel.send("Please provide your scholar number.")
const collectorSchNo = message.channel.createMessageCollector({ filter, max:1, time: 20000 });
collectorSchNo.on('collect', m => {
schn=m.content.toUpperCase();
if(schn.includes("U")){
let temp=m.content.toUpperCase().split(`U`)
if(temp[0].startsWith("17")) {yearG="2021"; k++;}
else if(temp[0].startsWith("18")) {yearG="2022"; k++;}
else if(temp[0].startsWith("19")) {yearG="2023"; k++;}
else if(temp[0].startsWith("20")) {yearG="2024"; k++;}
else{
message.channel.send("Please provide a valid scholar number.")
return;
}
if(temp[1].startsWith("01")) {branch="ECE"; k++;}
else if(temp[1].startsWith("02")) {branch="CSE"; k++;}
else if(temp[1].startsWith("03")) {branch="IT"; k++;}
else{
message.channel.send("Please provide a valid scholar number.")
return;
}
}
else{
message.channel.send("Please provide a valid scholar number.")
return;
}
});
collectorSchNo.on('end', async collected => {
if(k===2){
message.channel.send("Please provide your name.")
.catch(err => console.error(err));
const collectorName = message.channel.createMessageCollector({ filter, max:1, time: 30000 });
collectorName.on('collect', mN => {
sName = mN.content.toLowerCase().split(' ');
for (var i = 0; i < sName.length; i++) {
sName[i] = sName[i].charAt(0).toUpperCase() +
sName[i].substring(1);
}
sName=sName.join(" ");
myProfile.setColor('RANDOM')
.setTitle('My profile')
.addFields(
{ name: 'Scholar No.', value: schn, inline: true },
{ name: 'Branch', value: branch, inline: true },
{ name: 'Year of Graduation', value: yearG, inline: true },
{ name: '\u200B', value: '\u200B' },
{ name: 'Distro', value: (arr[0])?arr[0]:"NULL", inline: true },
{ name: 'Editor', value: (arr[3])?arr[3]:"NULL", inline: true },
{ name: 'Shell', value: (arr[4])?arr[4]:"NULL", inline: true },
{ name: '\u200B', value: '\u200B' },
{ name: 'CPU', value: (arr[11])?arr[11]:"NULL", inline: true },
{ name: 'GPU', value: (arr[12])?arr[12]:"NULL", inline: true },
{ name: 'Memory', value: (space)?space:"NULL", inline: true },
{ name: '\u200B', value: '\u200B' },
)
.setTimestamp()
.setThumbnail(GNU)
.setFooter(`We welcome you to our club!`, GNU)
.setAuthor(sName,UserPFP,"https://discord.gg/M9KMPzBj")
.setDescription("\u200B")
message.channel.send({ embeds: [myProfile] })
.then(
message.channel.send("If the above information is correct\nReply with **Y**.")
)
});
collectorName.on('end', async collected => {
const collectorY = message.channel.createMessageCollector({ filter, max:1, time: 20000 });
collectorY.on('collect',async mY => {
if(mY.content.toUpperCase()==="Y"){
message.channel.send("Congratz.")
await mongo().then(async (mongoose) => {
try {
await profileSchema.findOneAndUpdate({
_id: message.author.id
}, {
_id: message.author.id,
dTag: message.author.tag,
SName: sName,
SNo: schn,
Branch: branch,
Year: yearG,
Distro: arr[0],
Kernel: arr[1],
Terminal: arr[2],
Editor: arr[3],
Shell: arr[4],
WM: arr[5],
Bar: arr[6],
Resolution: arr[7],
Display: arr[8],
GTK3Theme: arr[9],
GTKIconTheme: arr[10],
CPU: arr[11],
GPU: arr[12],
Memory: space,
IIITB: "1",
}, {
upsert: true
})
}
catch(err) {
console.error(err)
}
finally {
client.channels.cache.get('840304064477528107')
.send(`Succesfully completed by ${sName} - ${message.author.tag} - ${message.author.id}`)
mongoose.connection.close()
}
})
}
else{
message.channel.send("We cant figure out your response. Please start all over again.\nContact moderators for support\nDont DM Club Secretaries. ;) ")
}
});
})
}
else{
message.channel.send("Please provide a valid scholar number.")
return;
}
});
}
)};
})
client.login(process.env.token)