-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
427 lines (410 loc) · 15.8 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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
const Discord = require("discord.js")
const fs = require("fs")
const fetch = require("node-fetch")
const keepAlive = require("./server")
const Database = require("@replit/database")
const db = new Database()
const client = new Discord.Client()
const config = require('./config.json')
const querystring = require('querystring')
const prefix = "."
const devkey = ["x.", "nodex."]
const auth = 'https://discord.com/api/oauth2/authorize?client_id=902092315827515432&permissions=536837353207&scope=bot'
const dmsg = require("./direct-msg")
function md(string) {
this.code = function() {
return `\`${string}\``
}
}
function code(string) {
return `\`${string}\``
}
function filter(value) {
if (/^[-+]?(\d+|Infinity)$/.test(value)) {
return Number(value)
} else {
return NaN
}
}
function randint(min, max) {
return Math.floor(Math.random() * max - min) + min
}
function addUser(id, items) {
db.get("users").then(users => {
people = users
people.push(id)
db.set("users", people)
})
db.get("inv").then(inv => {
coins = inv
coins.push(100)
db.set("inv", coins)
})
return people
}
function earn(amt, person) {
db.get("users").then(users => {
people = users
})
db.get("inv").then(inv => {
coins = inv
coins[people.indexOf(`${person}`)] = filter(coins[people.indexOf(`${person}`)]) + amt
db.set("inv", coins)
})
return coins
}
function getUsers() {
db.get("users").then(users => {
people = users
});
return people
}
function money(person) {
db.get("inv").then(inv => {
coins = inv
console.log(coins)
})
return coins[people.indexOf(`${person}`)]
}
function reset() {
db.set("users", [])
db.set("inv", [])
people = []
coins = []
}
function sync() {
db.get("users").then(users => {
people = users
});
}
var people = []
var coins = []
db.get("users").then(users => {
if (!users || users.length < 1) {
db.set("users", people)
}
people = users
});
db.get("inv").then(inv => {
if (!inv || inv.length < 1) {
db.set("inv", coins)
}
coins = inv
});
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`)
client.user.setActivity(".help")
dmsg(client, "ping", "pong")
dmsg(client, "hello", "Hello! I am Nodex Bot!")
dmsg(client, "?", "Nani?")
})
client.on("message", async msg => {
sync()
if (msg.author.bot) {
return
}
if (msg.content.startsWith(prefix)) {
const params = msg.content.slice(prefix.length).trim().split(/ +/)
const command = params.shift().toLowerCase()
console.log(command)
console.log(params)
if (command === "help") {
if (!params[0]) {
const embed = new Discord.MessageEmbed()
.setColor("#0064ff")
.setTitle(`Help Page`)
.setDescription(`Here are a few pages to get you started!`)
.addField(`General`, code(`${prefix}help general`), false)
.addField(`Scratch`, code(`${prefix}help scratch`), true)
.addField(`GitHub`,code(`${prefix}help github`), true)
.setAuthor(`Nodex Ninja`, `https://cdn2.scratch.mit.edu/get_image/user/79397968_60x60.png`,`https://scratch.mit.edu/users/nodexninja`)
msg.reply(embed)
}
if (params[0] === "scratch") {
const embed = new Discord.MessageEmbed()
.setColor("#FDB826")
.setTitle(`Scratch Commands`)
.addField(`${prefix}s p \`username\``,`Fetch a user\'s profile data!`, true)
.addField(`${prefix}s s \`key words\``,`Search for scratch projects!`, true)
.addField(`${prefix}s q \`key words\``,`Project quick search!`, true)
.setAuthor(`Nodex Ninja`, `https://cdn2.scratch.mit.edu/get_image/user/79397968_60x60.png`,`https://scratch.mit.edu/users/nodexninja`)
msg.reply(embed)
}
if (params[0] === "github") {
const embed = new Discord.MessageEmbed()
.setColor("#000000")
.setTitle(`GitHub Commands`)
.addField(`${prefix}g u \`username\``,`Fetch a user\'s profile data!`, true)
.setAuthor(`Nodex Ninja`, `https://cdn2.scratch.mit.edu/get_image/user/79397968_60x60.png`,`https://scratch.mit.edu/users/nodexninja`)
msg.reply(embed)
}
if (params[0] === "general") {
const embed = new Discord.MessageEmbed()
.setColor("#0064ff")
.setTitle(`Nodex`)
.addField(`${prefix}dm \`username\` \`message\``,`Direct message a mentioned user with the bot!`, true)
.addField(`${prefix}beg`,`Beg for coins :thinking:.`, true)
.addField(`${prefix}balance`,`See how much money you have.`, true)
.setAuthor(`Nodex Ninja`, `https://cdn2.scratch.mit.edu/get_image/user/79397968_60x60.png`,`https://scratch.mit.edu/users/nodexninja`)
msg.reply(embed)
}
}
if (command === "s") {
if (params[0] === "p") {
fetch('https://api.scratch.mit.edu/users/' + params[1])
.then(res => res.text())
.then(text => {
const data = JSON.parse(text)
const embed = new Discord.MessageEmbed()
.setColor("#0064ff")
.setTitle(`${data.username}`)
.addField(`Bio`,`${data.profile.bio}`)
.addField(`Work`, `${data.profile.status}`)
.addField(`Country`, `${data.profile.country}`)
.setImage(`https://cdn2.scratch.mit.edu/get_image/user/${data.id}_90x90.png`)
.setAuthor(`Nodex Ninja`, `https://cdn2.scratch.mit.edu/get_image/user/79397968_60x60.png`,`https://scratch.mit.edu/users/nodexninja`)
fetch('https://scratchdb.lefty.one/v3/user/info/' + params[1])
.then(res => res.text())
.then(text => {
const sub = JSON.parse(text)
embed.addField(`Stats`, `:bust_in_silhouette: ${sub.statistics.followers}\n:eye: ${sub.statistics.views}\n:heart: ${sub.statistics.loves}\n:star: ${sub.statistics.favorites}\n:speech_left: ${sub.statistics.comments}`, true)
embed.addField(`Global Ranks`, `:bust_in_silhouette: #${sub.statistics.ranks.followers}\n:eye: #${sub.statistics.ranks.views}\n:heart: #${sub.statistics.ranks.loves}\n:star: #${sub.statistics.ranks.favorites}\n:speech_left: #${sub.statistics.ranks.comments}`, true)
embed.addField(`Country Ranks`, `:bust_in_silhouette: #${sub.statistics.ranks.country.followers}\n:eye: #${sub.statistics.ranks.country.views}\n:heart: #${sub.statistics.ranks.country.loves}\n:star: #${sub.statistics.ranks.country.favorites}\n:speech_left: #${sub.statistics.ranks.country.comments}`, true)
embed.addField(`Links`, `[Visit Profile](https://scratch.mit.edu/users/${data.username})`)
msg.reply(embed)
})
})
}
if (params[0] === "q") {
var search = []
for (i=1;i<params.length;i++) {
search.push(params[i])
}
console.log(search)
var string = search.join("%20")
fetch('https://api.scratch.mit.edu/search/projects?q=' + string)
.then(res => res.text())
.then(text => {
const data = JSON.parse(text)
console.log(data[0])
const desc = data[0].description
if(desc.length > 1024) {
const desc = desc.substring(0, 1024)
}
const embed = new Discord.MessageEmbed()
.setColor("#0064ff")
.setTitle(`${data[0].title}`)
.addField(`Notes`,`${desc}`)
.setAuthor(`Nodex Ninja`, `https://cdn2.scratch.mit.edu/get_image/user/79397968_90x90.png`,`https://scratch.mit.edu/users/nodexninja`)
msg.reply(embed)
})
}
if (params[0] === "s") {
var search = []
for (i=1;i<params.length;i++) {
search.push(params[i])
}
console.log(search)
var string = search.join("%20")
fetch('https://api.scratch.mit.edu/search/projects?q=' + string)
.then(res => res.text())
.then(text => {
const data = JSON.parse(text)
console.log(data[0])
const embed = new Discord.MessageEmbed()
.setColor("#0064ff")
.setTitle(`Popular Projects`)
.setAuthor(`Nodex Ninja`, `https://cdn2.scratch.mit.edu/get_image/user/79397968_90x90.png`,`https://scratch.mit.edu/users/nodexninja`)
for (i=0;i<data.length;i++) {
embed.addField(`${data[i].title}`,`by [@${data[i].author.username}](https://scratch.mit.edu/users/${data[i].author.username})\n[View on Scratch](https://scratch.mit.edu/projects/${data[i].id})\nID: ${data[i].id}\n${data[i].stats.views} :eye:, ${data[i].stats.loves} :heart:, ${data[i].stats.favorites} :star:, ${data[i].stats.remixes} :low_brightness:`, true)
}
msg.reply(embed)
})
}
if (params[0] === "proj") {
fetch(`https://scratchdb.lefty.one/v3/project/info/${params[1]}`)
.then(res => res.text())
.then(text => {
const data = JSON.parse(text)
console.log(data)
const embed = new Discord.MessageEmbed()
.setColor("#0064ff")
.setTitle(`${data.title}`)
.addField(`Instructions`,`${data.instructions}`)
.addField(`Project ID`,`${data.id}`)
.setAuthor(`Nodex Ninja`, `https://cdn2.scratch.mit.edu/get_image/user/79397968_90x90.png`,`https://scratch.mit.edu/users/nodexninja`)
.setFooter(`Project by ${data.username}`)
msg.reply(embed)
})
}
if (params[0] === "fav") {
fetch(`https://api.scratch.mit.edu/users/${params[1]}/favorites`)
.then(res => res.text())
.then(text => {
const data = JSON.parse(text)
console.log(data)
const embed = new Discord.MessageEmbed()
.setColor("#0064ff")
.setTitle(`${params[1]}\'s Favourites`)
.setAuthor(`Nodex Ninja`, `https://cdn2.scratch.mit.edu/get_image/user/79397968_90x90.png`,`https://scratch.mit.edu/users/nodexninja`)
for (i=0;i<data.length;i++) {
embed.addField(`${data[i].title}`,`${data[i].id}`, true)
}
msg.reply(embed)
})
}
if (params[0] === "t") {
var search = []
for (i=1;i<params.length;i++) {
search.push(params[i])
}
console.log(search)
var string = search.join("%20")
fetch('https://api.scratch.mit.edu/search/projects?mode=trending&q=' + string)
.then(res => res.text())
.then(text => {
const data = JSON.parse(text)
console.log(data[0])
const embed = new Discord.MessageEmbed()
.setColor("#0064ff")
.setTitle(`Trending Projects`)
.setAuthor(`Nodex Ninja`, `https://cdn2.scratch.mit.edu/get_image/user/79397968_90x90.png`,`https://scratch.mit.edu/users/nodexninja`)
for (i=0;i<data.length;i++) {
embed.addField(`${data[i].title}`,`by [@${data[i].author.username}](https://scratch.mit.edu/users/${data[i].author.username})\n[View on Scratch](https://scratch.mit.edu/projects/${data[i].id})\nID: ${data[i].id}\n${data[i].stats.views} :eye:, ${data[i].stats.loves} :heart:, ${data[i].stats.favorites} :star:, ${data[i].stats.remixes} :low_brightness:`, true)
}
msg.reply(embed)
})
}
}
if (command === "dm") {
const u = msg.mentions.users.first().id
if (msg.mentions.users.first()) {
} else {
msg.reply(`No users were mentioned!`)
u = msg.author.id
return
}
var txt = []
for (i=1;i<params.length;i++) {
txt.push(params[i])
}
txt = txt.join(" ")
const embed = new Discord.MessageEmbed()
.setColor("#0064ff")
.setTitle(`New Message!`)
.setDescription(`${txt}`)
.setAuthor(`${msg.author.tag}`)
client.users.fetch(u).then((user) => {user.send(embed)})
}
if (command === "beg") {
console.log(getUsers())
if (!people.includes(msg.author.id)) {
addUser(msg.author.id)
const embed = new Discord.MessageEmbed()
embed
.setColor("#0064ff")
.setTitle("Beg Command")
.setDescription(`You need to register your account with \`${prefix}play\``)
msg.reply(embed)
} else {
const embed = new Discord.MessageEmbed()
const luck = randint(0,10)
if (luck === 0) {
embed
.setColor("#ff0032")
.setTitle(`Imagine Begging!`)
.setDescription(`You got no coins lol.`)
} else {
const beg = randint(0,100)
embed
.setColor("#00b428")
.setTitle(`Impossible!`)
.setDescription(`You received **$${beg}** after begging!`)
.addField(`Account`, `:moneybag: You now have **$${coins[people.indexOf(msg.author.id)] + beg}** in your account!`)
earn(beg, msg.author.id)
}
msg.reply(embed)
}
}
if (command === "money") {
money()
}
if (command === "users") {
console.log(getUsers())
}
if (command === "reset" && msg.author.id === "896643867749810188") {
reset()
}
if (command === "invite") {
msg.reply(`Invite me to your server with: https://discord.com/api/oauth2/authorize?client_id=902092315827515432&permissions=536837353207&scope=bot`)
}
if (command === "play") {
console.log(people)
if (!people.includes(msg.author.id)) {
addUser(msg.author.id)
const embed = new Discord.MessageEmbed()
.setTitle(`Great!`)
.setDescription(`Your account has been registered!`)
.setColor(`#00b428`)
msg.reply(embed)
} else {
const embed = new Discord.MessageEmbed()
.setTitle(`Calm Down`)
.setDescription(`You have already registered an account.`)
.addField(`Errors`, `The server could have been reset by the admins a while ago. Try ${prefix}play again!`)
.setColor(`#ff0032`)
msg.reply(embed)
}
}
if (command === "bal" || command === "balance") {
const embed = new Discord.MessageEmbed()
.setTitle(`${msg.author.tag}\'s Balance`)
.setDescription(`:moneybag: You have **$${coins[people.indexOf(msg.author.id)]}**. Amazing!`)
.setColor(`#0064ff`)
msg.reply(embed)
}
if (command === "code") {
const text = new md(params[0]).code()
msg.reply(text)
}
if (command === "g") {
if (params[0] === "u") {
fetch('https://api.github.com/users/' + params[1])
.then(res => res.text())
.then(text => {
const data = JSON.parse(text)
const embed = new Discord.MessageEmbed()
.setAuthor(`${data.login}`, `${data.avatar_url}`, `https://github.com/${data.login}`)
.setColor(`#0064ff`)
.setTitle(`${data.name}`)
.setDescription(`${data.bio}`)
.addField(`Followers`, `${data.followers}`, true)
.addField(`Following`, `${data.following}`, true)
.addField(`Website`, `[${data.blog}](${data.blog})`)
if (data.company) {
embed.addField(`Other`, `:earth_americas: ${data.location}\n:office: [${data.company}](https://github.com/${data.company.slice(1)})`)
}
msg.reply(embed)
})
}
}
} else if (msg.content.startsWith(devkey[0]) || msg.content.startsWith(devkey[1])) {
/*
This area will include complicated evaluated string commands to help programmers use this bot to its maximum capacity...
*/
var params = msg.content.slice(devkey[0].length).trim().split(/[,]+/)
if (msg.content.startsWith(devkey[0])) {
params = msg.content.slice(devkey[0].length).trim().split(/[,]+/)
} else {
params = msg.content.slice(devkey[1].length).trim().split(/[,]+/)
}
const command = params.shift().toLowerCase()
console.log(command)
console.log(params)
if (command === "help") {
msg.reply(`You are using special nodex dev syntax.`)
}
}
})
keepAlive()
client.login(process.env.TOKEN)