-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
87 lines (75 loc) · 3.46 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
const { Client, MessageEmbed } = require('discord.js');
const cron = require('node-cron');
const generateLogin = require('./xactClient')
const config = require('./config');
const commands = require('./help');
const fs = require("fs");
const userCron = require("./cron");
let bot = new Client({
fetchAllMembers: true, // Remove this if the bot is in large guilds.
presence: {
status: 'online',
activity: {
name: `${config.prefix}validate`,
type: 'LISTENING'
}
}
});
userCron.start(bot)
bot.on('ready', () => console.log(`Logged in as ${bot.user.tag}.`));
bot.on('message', async message => {
// Check for command
if (message.content.startsWith(config.prefix)) {
let args = message.content.slice(config.prefix.length).split(' ');
let command = args.shift().toLowerCase();
switch (command) {
case 'validate':
// Only allow #bouncer bot channel
if (message.channel.id !== '918265350276128768') {
message.author.send("Bzzzzz* Error: Please use #🤖┃bouncer-bot to post _validate and earn holder roles for the Punks you own")
.catch((error) => {console.log(error);});;
return
}
let msg = await message.author.send('Generating QR Code...')
.catch((error) => {console.log(error);});;
const qrCode = await generateLogin(message, bot);
let base64Image = qrCode.split(';base64,').pop();
fs.writeFile('./qrcodes/login_.jpg', base64Image, {encoding: 'base64'}, (err) => {
console.log('File created');
message.author.send("Scan with Xact Wallet.", { files: ["./qrcodes/login_.jpg"] })
.catch((error) => {console.log(error);});;
});
break;
/* Unless you know what you're doing, don't change this command. */
case 'help':
let embed = new MessageEmbed()
.setTitle('HELP MENU')
.setColor('GREEN')
.setFooter(`Requested by: ${message.member ? message.member.displayName : message.author.username}`, message.author.displayAvatarURL())
.setThumbnail(bot.user.displayAvatarURL());
if (!args[0])
embed
.setDescription(Object.keys(commands).map(command => `\`${command.padEnd(Object.keys(commands).reduce((a, b) => b.length > a.length ? b : a, '').length)}\` :: ${commands[command].description}`).join('\n'));
else {
if (Object.keys(commands).includes(args[0].toLowerCase()) || Object.keys(commands).map(c => commands[c].aliases || []).flat().includes(args[0].toLowerCase())) {
let command = Object.keys(commands).includes(args[0].toLowerCase())? args[0].toLowerCase() : Object.keys(commands).find(c => commands[c].aliases && commands[c].aliases.includes(args[0].toLowerCase()));
embed
.setTitle(`COMMAND - ${command}`)
if (commands[command].aliases)
embed.addField('Command aliases', `\`${commands[command].aliases.join('`, `')}\``);
embed
.addField('DESCRIPTION', commands[command].description)
.addField('FORMAT', `\`\`\`${config.prefix}${commands[command].format}\`\`\``);
} else {
embed
.setColor('RED')
.setDescription('This command does not exist. Please use the help command without specifying any commands to list them all.');
}
}
message.channel.send(embed);
break;
}
}
});
require('./server')();
bot.login(config.token);