This repository has been archived by the owner on May 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
77 lines (72 loc) · 2.31 KB
/
mod.ts
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
/**
* @enum {string} Endpoints
*/
export enum RandomName {
CAT = "/api/v2/cat",
EIGHT_BALL = "/api/v2/8ball",
FACT = "/api/v2/fact",
NAME = "/api/v2/name",
OWOIFY = "/api/v2/owoify",
WHY = "/api/v2/why",
AVATAR = "/api/v2/img/avatar",
CUDDLE = "/api/v2/img/cuddle",
FEED = "/api/v2/img/feed",
FOX_GIRL = "/api/v2/img/fox_girl",
GASM = "/api/v2/img/gasm",
GECG = "/api/v2/img/gecg",
GOOSE = "/api/v2/img/goose",
HUG = "/api/v2/img/hug",
KISS = "/api/v2/img/kiss",
LEWD = "/api/v2/img/lewd",
LIZARD = "/api/v2/img/lizard",
MEOW = "/api/v2/img/meow",
NEKO = "/api/v2/img/neko",
PAT = "/api/v2/img/pat",
SLAP = "/api/v2/img/slap",
SMUG = "/api/v2/img/smug",
SPANK = "/api/v2/img/spank",
TICKLE = "/api/v2/img/tickle",
WALLPAPER = "/api/v2/img/wallpaper",
WAIFU = "/api/v2/img/waifu",
WOOF = "/api/v2/img/woof"
}
/**
* @param {string} cat: Response given by Cat endpoint.
* @param {string} response: Response given by 8ball endpoint together with url.
* @param {string} fact: Reponse given by Fact endpoint.
* @param {string} name: Reponse given by Name endpoint.
* @param {string} msg: Reponse given when an error occured.
* @param {string} owo: Reponse given by Owoify endpoint.
* @param {string} why: Reponse given by Why endpoint.
* @param {number} time: The time in ms it took to get a reponse back from the API.
*/
export interface IResponse {
cat?: string;
response?: string;
fact?: string;
url?: string;
name?: string;
msg?: string;
owo?: string;
why?: string;
time: number;
}
async function request(path: string, text?: string): Promise<IResponse> {
let url: string = "https://nekos.life" + path;
if (text) url += `?text=${text}`;
const startTime = Date.now();
const res = await fetch(url);
const json = await res.json();
json['time'] = Date.now() - startTime;
return json;
}
export class Nekos {
/**
* @param {RandomName} name: Name of the endpoint. eg. RandomName.NEKO
* @param {string} text: (Optional) Needed for some endpoints.
* @returns {Promise<IResponse>} Promise
*/
static random(name: RandomName, text?: string): Promise<IResponse> {
return request(name, text);
}
}