-
Notifications
You must be signed in to change notification settings - Fork 0
/
leeta.js
67 lines (60 loc) · 1.92 KB
/
leeta.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
const Discord = require("discord.js");
const client = new Discord.Client();
const config = require("./config.json");
// Drinks DB from https://github.com/lauriharpf/thecocktaildb-downloader
// Remember to change "export default drinks" to "module.exports = drinks"
const drinks = require("./drinks.js");
const didyoumean = require('didyoumean2').default;
// Create an index of the drink names for didyoumean2 to utilize.
// TODO: There's probably a more elegant way to do this.
// A list of drink name fields to search
let drinkNameFields = [
'strDrink',
'strDrinkAlternate',
'strDrinkES',
'strDrinkDE',
'strDrinkFR',
'strDrinkZH-HANS',
'strDrinkZH-HANT'
];
// Add each of the names and its corresponding ID to the object.
let drinkNameIndex = {};
drinks.forEach(function(d) {
drinkNameFields.forEach(
function(field) {
if (d[field] !== null)
drinkNameIndex[d[field].toString()] = d.idDrink.toString();
})
});
client.on("ready", () => {
console.log("I am ready!");
});
client.on("message", (message) => {
// No bots
if (message.author.bot) return;
// Search the list of prefixes
let prefix;
config.prefixes.some(
function(v) {
if (message.content.startsWith(v)) {
prefix = v;
return true;
}
return false;
}
);
if (!prefix) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (command === 'ping') {
message.reply("I'm still here, hon! What can I get you?");
}
if (command === 'make') {
let drinkName = args.join(' ');
// Do a fuzzy match with didyoumean to find the closest drink name and serve that
// TODO: Make the command a bit less Infocom RPG and more real language.
let fuzzyDrinkMatch = didyoumean(drinkName, Object.keys(drinkNameIndex));
message.reply(`one ${fuzzyDrinkMatch} coming right up!`);
}
});
client.login(config.token);