forked from LeaPhant/flowabot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfantasynamegen.js
64 lines (49 loc) · 2.16 KB
/
fantasynamegen.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
const axios = require('axios');
const helper = require('./helper.js');
const fantasyNameGen = axios.create({
baseURL: 'https://www.fantasynamegen.com',
responseType: 'document'
})
const fantasy_types = ["human", "elf", "dwarf", "hobbit", "barbarian", "orc", "evil", "asian", "arabic",
"surname", "sci-fi", "lovecraft", "reptilian", "aztec", "ratman", "demon", "dragon", "wizard", "mixed",
"english", "place", "title", "military", "hero/villain", "rockband"];
const fantasy_types_raw = {"surname": "surnames", "sci-fi": "sf", "english": "enames", "place": "places",
"title": "titles", "military": "operation", "hero/villain": "super"};
const fantasy_length = ["short", "medium", "long"];
module.exports = {
fantasyTypes: fantasy_types,
fantasyLengths: fantasy_length,
getFantasyName: (type, length, author) => {
return new Promise((resolve, reject) => {
if(!fantasy_types.includes(type)){
reject('Unknown type');
return false;
}
if(!fantasy_length.includes(length)){
reject('Unknown length');
return false;
}
if(type in fantasy_types_raw)
type = fantasy_types_raw[type];
fantasyNameGen.get(`/${type}/${length}/`).then(response => {
try{
let names = response.data.split("<ul>").pop().split("</ul>")[0].split("\n");
names.splice(0, 1);
names.splice(names.length - 1, 1);
let name = names[Math.floor(Math.random() * names.length)].split("<li>").pop().split("</li>")[0];
if(name.includes("<name> "))
name = name.replace("<name> ", author);
if(type == 'surnames')
name = author + " " + name;
resolve(name);
}catch(err){
helper.error(err);
reject("Error parsing site");
}
}).catch(err => {
helper.error(err);
reject("Couldn't proccess request");
});
});
}
}