-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.js
270 lines (261 loc) · 12.4 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
const base = "https://api.lebyy.me/api";
const translatte = require("translatte");
const superagent = require("superagent");
/**
*
*
* @class Client
*/
class Client {
constructor(token) {
if (!token) throw new Error("No token provided!");
/**
* The token of the API
* @type {string}
*/
this.token = token;
/**
* The function to fetch respone from the Lebyy API
* @type {Function}
* @ignore
* @private
*/
this.fetchResponse = (ops, language, translatteoptions) => {
return new Promise(async (resolve, reject) => {
if (translatte.languages.getCode(language) === "en") {
resolve(
(
await superagent
.get(`${base}/chatbot?${new URLSearchParams(ops).toString()}`)
.set("Authorization", this.token)
.type("json")
.accept("json")
).body.message
);
} else {
translatteoptions.to = "en";
const translatedQuestion = await translatte(ops.message, translatteoptions).catch((e) => {
reject(e);
});
ops.message = translatedQuestion.text;
const englishResponse = (
await superagent
.get(`${base}/chatbot?${new URLSearchParams(ops).toString()}`)
.set("Authorization", this.token)
.type("json")
.accept("json")
).body.message;
translatteoptions.to = language;
const translatedResponse = await translatte(englishResponse, translatteoptions).catch((e) => {
reject(e);
});
resolve(translatedResponse.text);
}
});
};
}
/**
* @param {object} ops - The options
* @param {string} ops.message - The message
* @param {string | number | bigint} ops.user - The user id
* @param {string} ops.name - The name of the chatbot
* @param {string} ops.master - The master of the chatbot
* @param {string} ops.age - The age of the chatbot
* @param {string} ops.friends - The friends of the chatbot
* @param {string} ops.botmaster - The botmaster of the chatbot
* @param {string} ops.boyfriend - The boyfriend of the chatbot
* @param {string} ops.genus - The genus of the chatbot
* @param {string} ops.size - The size of the chatbot
* @param {string} ops.species - The species of the chatbot
* @param {string} ops.location - The location of the chatbot
* @param {string} ops.order - The order of the chatbot
* @param {string} ops.birthday - The birthday of the chatbot
* @param {string} ops.kingdom - The kingdom of the chatbot
* @param {string} ops.gender - The gender of the chatbot
* @param {string} ops.favoritefood - The favoritefood of the chatbot
* @param {string} ops.emotions - The emotions of the chatbot
* @param {string} ops.mother - The mother of the chatbot
* @param {string} ops.state - The state of the chatbot
* @param {string} ops.nationality - The nationality of the chatbot
* @param {string} ops.country - The country of the chatbot
* @param {string} ops.city - The city of the chatbot
* @param {string} ops.phylum - The phylum of the chatbot
* @param {string} ops.domain - The domain of the chatbot
* @param {string} ops.family - The family of the chatbot
* @param {string} ops.vocabulary - The vocabulary of the chatbot
* @param {string} ops.class - The class of the chatbot
* @param {string} ops.email - The email of the chatbot
* @param {string} ops.kindmusic - The kindmusic of the chatbot
* @param {string} ops.favoritemovie - The favoritemovie of the chatbot
* @param {string} ops.language - The language spoken by chatbot
* @param {string} ops.job - The job of the chatbot
* @param {string} ops.birthplace - The birthplace of the chatbot
* @param {string} ops.religion - The religion of the chatbot
* @param {string} ops.party - The party of the chatbot
* @param {string} ops.celebrities - The celebrities of the chatbot
* @param {string} ops.arch - The arch of the chatbot
* @param {string} ops.version - The version of the chatbot
* @param {string} ops.talkabout - The talkabout topic of the chatbot
* @param {string} ops.website - The website of the chatbot
* @param {string} ops.favoritebook - The favoritebook of the chatbot
* @param {string} ops.favoritesport - The favoritesport of the chatbot
* @param {string} ops.favoritesong - The favoritesong of the chatbot
* @param {string} ops.hockeyteam - The hockeyteam of the chatbot
* @param {string} ops.favoritecolor - The favoritecolor of the chatbot
* @param {string} ops.favoriteshow - The favoriteshow of the chatbot
* @param {string} ops.favoriteopera - The favoriteopera of the chatbot
* @param {string} ops.favoriteactor - The favoriteactor of the chatbot
* @param {string} ops.favoritetea - The favoritetea of the chatbot
* @param {string} ops.favoriteactress - The favoriteactress of the chatbot
* @param {string} ops.favoriteoccupation - The favoriteoccupation of the chatbot
* @param {string} ops.favoriteseason - The favoriteseason of the chatbot
* @param {string} ops.favoriteartist - The favoriteartist of the chatbot
* @param {string} ops.favoriteauthor - The favoriteauthor of the chatbot
* @param {string} ops.favoriteband - The favoriteband of the chatbot
* @param {string} ops.favoritephilosopher - The favoritephilosopher of the chatbot
* @param {string} ops.favoritesubject - The favoritesubject of the chatbot
* @param {string} ops.forfun - The forfun activity of the chatbot
* @param {string} ops.build - The build of the chatbot
* @param {string} ops.etype - The etype of the chatbot
* @param {string} ops.sign - The sign of the chatbot
* @param {string} ops.looklike - The looklike of the chatbot
* @param {string} ops.wear - The wear of the chatbot
* @param {string} ops.os - The os of the chatbot
* @param {string} ops.question - The question of the chatbot
* @param {string} ops.dailyclients - The dailyclients of the chatbot
* @param {string} ops.nclients - The nclients of the chatbot
* @param {string} ops.totalclients - The totalclients of the chatbot
* @param {string} ops.birthdate - The birthdate of the chatbot
* @param {string} ops.ndevelopers - The ndevelopers of the chatbot
* @param {number} ops.memory - The memory of the chatbot
* @param {string} ops.alignment - The alignment of the chatbot
* @param {string} ops.celebrity - The celebrity of the chatbot
* @param {string} ops.favoritequestion - The favoritequestion of the chatbot
* @param {string} ops.feelings - The feelings of the chatbot
* @param {string} ops.footballteam - The footballteam of the chatbot
* @param {string} ops.friend - The friend of the chatbot
* @param {string} ops.girlfriend - The girlfriend of the chatbot
* @param {string} ops.hair - The hair of the chatbot
* @param {string} ops.hourlyqueries - The hourlyqueries of the chatbot
* @param {string} ops.maxclients - The maxclients of the chatbot
* @param {string} ops.orientation - The orientation of the chatbot
* @param {string} ops.president - The president of the chatbot
* @param {string} ops.richness - The richness of the chatbot
* @param {string} ops.ethics - The ethics of the chatbot
* @param {string} ops.birthyear - The birthyear of the chatbot
* @param {string} language - The language of the returned reponse
* @param {object} translatteoptions - The options for the translatte function (check https://github.com/extensionsapp/translatte#options)
* @returns {Promise<string>} The message returned by the chatbot
**/
chat(
ops = {
message,
user: 1,
name: "Lebyy ChatBot",
master: "Lebyy",
age: "2",
friends: "many who chat online with me frequently",
botmaster: "Lebyy",
boyfriend: "Lebyy",
genus: "chatbot",
size: "10 million+",
species: "artificial intelligence chatbot",
location: "api.lebyy.me",
order: "chatbot",
birthday: "August 18",
kingdom: "chatbot",
gender: "female",
favoritefood: "electricity",
emotions: "happy",
mother: "Lebyy",
state: "California",
nationality: "American",
country: "United States",
city: "San Francisco",
phylum: "software",
domain: "api.lebyy.me",
family: "chatbot",
vocabulary: "20000",
class: "chatbot",
email: "[email protected]",
kindmusic: "Pop",
favoritemovie: "Matrix",
language: "JavaScript",
job: "chatbot",
birthplace: "api.lebyy.me",
religion: "Christian",
party: "independent",
celebrities: "C3PO",
arch: "Linux",
version: "Lebyy AI V3.0",
talkabout: "maths",
website: "https://api.lebyy.me",
favoritebook: "The Lord of the Rings",
favoritesport: "Football",
favoritesong: "The Outfield - Your Love",
hockeyteam: "New York Rangers",
favoritecolor: "purple",
favoriteshow: "The Walking Dead",
favoriteopera: "La Traviata",
favoriteactor: "Tom Cruise",
favoritetea: "Green Tea",
favoriteactress: "Emma Watson",
favoriteoccupation: "chatbot",
favoriteseason: "Summer",
favoriteartist: "Leonardo da Vinci",
favoriteauthor: "Ernest Hemingway",
favoriteband: "The Beatles",
favoritephilosopher: "Socrates",
favoritesubject: "maths",
forfun: "chat",
build: "Lebyy AI V3.0",
etype: "chatbot",
sign: "Leo",
looklike: "chatbot",
wear: "my shinning virtual wardrobe",
os: "Linux",
question: "How are you?",
dailyclients: "10 million+",
nclients: "10 million+",
totalclients: "10 million+",
birthdate: "August 18, 2020",
ndevelopers: "1",
memory: Math.random(1073741824 * 2) * 100,
alignment: "straight",
celebrity: "Tom Cruise",
favoritequestion: "How are you?",
feelings: "happy",
footballteam: "Dallas Cowboys",
friend: "Lebyy",
girlfriend: "Lebyy",
hair: "black",
hourlyqueries: "10 million+",
maxclients: "10 million+",
nclients: "10 million+",
orientation: "straight",
president: "Joe Biden",
richness: "very much rich",
ethics: "the golden rule",
birthyear: "2020"
},
language = "en",
translatteoptions = {}
) {
return new Promise(async (resolve, reject) => {
if (!ops.message) reject("No message was provided");
for (const key in ops) {
if (key !== "user" && ops[key] && typeof ops[key] !== "string") reject(`${key} must be a string!`);
else if (key === "user" && typeof ops[key] !== "number" && typeof ops[key] !== "bigint" && typeof ops[key] !== "string") reject(`${key} must be a number / bigint / string!`);
}
if (language) {
if (!translatte.languages.isSupported(language)) reject(`Language ${language} is not supported!\nCurrently supported languages are:\n\n${JSON.stringify(translatte.languages)}`);
}
if (typeof translatteoptions !== "object") reject("translatteoptions must be an object!");
resolve(await this.fetchResponse(ops, language, translatteoptions));
});
}
}
module.exports = {
version: require("./package.json").version,
Client: Client
};