-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscord.js
50 lines (41 loc) · 1.5 KB
/
discord.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
require('dotenv').config();
const Discord = require('discord.js');
const FileSync = require('lowdb/adapters/FileSync');
const Seraph = require('./services/seraph.js');
const Fate = require('./services/fate.js');
const Sheba = require('./services/sheba.js');
const client = new Discord.Client();
const seraph = new Seraph(new FileSync('docs/json/akasha.json'));
const fate = new Fate(seraph);
const sheba = new Sheba('docs/img/');
// Helpers
const embed = svt => new Discord.RichEmbed()
.attachFile(sheba.getImgPath(svt.id))
.setAuthor(svt.name)
.setDescription(`*${svt.avail} ${svt.rarity}:sparkles: ${svt.className}*`)
.setImage(`attachment://${sheba.getImgName(svt.id)}`)
.addField('Cards', `${svt.deck} **|** ${svt.np}`)
.addField('Skills', svt.actives.length === 0 ? 'N/A' : svt.actives.join('\n'))
.setFooter(`LV${svt.lv} | ${svt.hps[1]}HP | ${svt.atks[1]}ATK`);
// Configure Discord
client.on('ready', () => client.user.setPresence({
game: {
type: 'LISTENING',
name: `@${client.user.username}`
},
status: 'online'
}));
client.on('message', async msg => {
if (!msg.isMentioned(client.user)) {
return;
}
const query = msg.content.trim().split(/ +/).filter(q => !q.startsWith('<@'));
const svt = query.length > 0 ? seraph.query(query) : fate.summon();
if (!svt || !svt.id) {
return msg.react('🤔');
}
const color = await sheba.computeColor(svt.id);
return msg.reply({embed: embed(svt).setColor(color)});
});
client.login(process.env.TOKEN);
module.exports = client;