-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (55 loc) · 2.08 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
const Discord = require('discord.js');
const bot = new Discord.Client
const fs = require('fs');
const util = require('util');
const config = require('./config.json')
bot.on('ready', ready => {
console.log(`logged in`)
})
const Pokedex = require('./pokedexhelper.js');
const convert = require('convert-units');
const formatHeight = (height) => {
const meters = height / 10;
const feet = convert(meters).from('m').to('ft-us');
const parts = feet.toString().split('.');
const characteristic = parts[0];
const mantissa = `.${parts[1]}`;
const inches = convert(mantissa).from('ft').to('in').toFixed();
return `${characteristic}' ${inches}"`
}
const formatWeight = (weight) => {
const grams = weight * 100;
const lb = convert(grams).from('g').to('lb').toFixed(1);
return `${lb} lbs`;
}
const formatName = (name) => name.charAt(0).toUpperCase() + name.slice(1);
bot.on('message', async message => {
const POKEDEX_CMD = '$pokedex';
if(message.content.startsWith(POKEDEX_CMD))
var array = message.content.split(' ');
array.shift()
let Pokemon = array.join(' ');
if (Pokemon) {
try {
const result = await Pokedex.search(Pokemon)
const DexEmbed = new Discord.MessageEmbed()
.setAuthor(`${Pokemon}`, result.sprites.front_shiny)
.setTitle(formatName(result.name))
.setThumbnail(result.sprites.front_default)
.setDescription(`**No. ${result.id}** \n **Type - ${result.types[0].type.name}**`)
.addField("Weight", formatWeight(result.weight))
.addField("Height", formatHeight(result.height))
.setColor("GREEN")
.addField("Description", result.description)
.setFooter(`Requested By ${message.author.username}`,message.author.avatarURL())
.setTimestamp();
message.channel.send(DexEmbed);
} catch(err) {
console.log(err);
message.channel.send('NO DATA')
}
} else {
message.channel.send(`You didn\'t provide which pokemon to search for <@!${message.author.id}>`);
}
});
bot.login(config.Token)