neekuro 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,65 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * @typedef {import('../typings').APIClientData} APIClientData
5
+ * @typedef {import('../typings').GifResponse} GifResponse
6
+ */
7
+
8
+ const APIError = require('../classes/errors/apierror');
9
+
10
+ const fetch = import('node-fetch');
11
+
12
+ /**
13
+ * Clase APIClient
14
+ * Se encarga de la comunicacion y control de solicitudes a la api
15
+ */
16
+ class APIClient {
17
+ /**
18
+ * Instanciamiento de la clase
19
+ * @param {string} baseURL link principal de la api
20
+ * @param {APIClientData} data objeto para las solicitudes
21
+ */
22
+ constructor(baseURL, data) {
23
+ /**
24
+ * url principal
25
+ * @type {string}
26
+ */
27
+ this.baseURL = baseURL
28
+ /**
29
+ * data
30
+ * @type {APIClientData}
31
+ */
32
+ this.data = data
33
+ }
34
+ /**
35
+ * Obtiene el objeto compartido por la api a traves de la ruta y con autorizacion por token
36
+ * @param {string} endpoint establece la ruta a la que se quiere comunicar
37
+ * @returns {Promise<GifResponse>}
38
+ * @throws {APIError} solo si sucede un error entre solicitudes
39
+ */
40
+ async get(endpoint) {
41
+ try {
42
+ const response = await (await fetch).default(`${this.baseURL}${endpoint}`, {
43
+ method: 'GET',
44
+ headers: {
45
+ 'Authorization': `${this.data.token}`,
46
+ 'Content-Type': 'application/json'
47
+ }
48
+ });
49
+
50
+ if (!response.ok) {
51
+ throw new APIError(endpoint, response, await response.json());
52
+ }
53
+
54
+ return response.json()
55
+ } catch (error) {
56
+ if (error instanceof APIError) {
57
+ throw error;
58
+ } else {
59
+ throw new APIError(endpoint, { message: error.message }, {});
60
+ }
61
+ }
62
+ }
63
+ }
64
+
65
+ module.exports = APIClient;
@@ -0,0 +1,384 @@
1
+ import { Response } from "node-fetch";
2
+
3
+ //#region constants
4
+
5
+ /**
6
+ * Categoria SFW
7
+ * aqui encontraras categorias no nsfw como accion y reaccion
8
+ * @example
9
+ * // obtiene el objeto SFW
10
+ * const SFW = require('neekuro').SFW
11
+ */
12
+ export const SFW: {
13
+ /**
14
+ * Funcion principal para obtener gifs de cierta categoria
15
+ * @param category category: corresponde a la subcategoria de SFW
16
+ * @param gif gif: corresponde al gif que quieras obtener por categoria
17
+ * @example
18
+ * const { SFW } = require('neekuro')
19
+ *
20
+ * // se obtiene el objeto (es necesario que esto sea dentro de una funcion asincrona)
21
+ * let cuddle = await SFW.getGif('action', 'cuddle')
22
+ *
23
+ * // obtener url
24
+ * cuddle.getUrl();
25
+ * // obtener anime
26
+ * cuddle.getAnime();
27
+ */
28
+ getGif<T extends SfwCategories>(category: T, gif: GifMap[T]): Promise<NekoGif>
29
+ }
30
+
31
+ //#endregion
32
+
33
+ //#region types
34
+
35
+ export type ActionGifs =
36
+ 'cook' |
37
+ 'cuddle' |
38
+ 'cure' |
39
+ 'draw' |
40
+ 'drive' |
41
+ 'eat' |
42
+ 'explosion' |
43
+ 'feed' |
44
+ 'hug' |
45
+ 'kickbut' |
46
+ 'kill' |
47
+ 'kiss' |
48
+ 'lick' |
49
+ 'pat' |
50
+ 'peek' |
51
+ 'playing' |
52
+ 'poke' |
53
+ 'punch' |
54
+ 'run' |
55
+ 'sape' |
56
+ 'shoot' |
57
+ 'sip' |
58
+ 'slap' |
59
+ 'sleep' |
60
+ 'stare' |
61
+ 'tickle' |
62
+ 'travel' |
63
+ 'work';
64
+
65
+ export type ReactionGifs = 'angry' |
66
+ 'blush' |
67
+ 'bored' |
68
+ 'confused' |
69
+ 'cry' |
70
+ 'dance' |
71
+ 'laugh' |
72
+ 'like' |
73
+ 'pout' |
74
+ 'scream' |
75
+ 'smug' |
76
+ 'think' |
77
+ 'vomit' |
78
+ 'wink';
79
+
80
+ export type SfwCategories = 'action' | 'reaction';
81
+
82
+ export type FontNames = 'arial' | 'calibri' | 'custom';
83
+
84
+ //#endregion
85
+
86
+
87
+ //#region inferfaces
88
+
89
+ export interface APIClientData {
90
+ token: string
91
+ }
92
+
93
+ export interface WelcomeBackgroundData {
94
+ type: 'color' | 'image'
95
+ value: string | Buffer
96
+ }
97
+
98
+ export interface WelcomeAvatarData {
99
+ x?: number
100
+ y?: number
101
+ border?: string
102
+ radio?: number
103
+ }
104
+
105
+ export interface WelcomeTextData {
106
+ x?: number
107
+ y?: number
108
+ font_size?: number
109
+ text_color?: string
110
+ }
111
+
112
+ export interface WelcomeData {
113
+ font: FontNames;
114
+ width: number;
115
+ height: number;
116
+ background: WelcomeBackgroundData;
117
+ avatar: {
118
+ source: string | Buffer | null;
119
+ x: number;
120
+ y: number;
121
+ radio: number;
122
+ border: string;
123
+ };
124
+ title: {
125
+ content: string | null;
126
+ x: number;
127
+ y: number;
128
+ font_size: number;
129
+ text_color: string;
130
+ };
131
+ description: {
132
+ content: string | null;
133
+ x: number;
134
+ y: number;
135
+ font_size: number;
136
+ text_color: string;
137
+ };
138
+ }
139
+
140
+ export interface NekoGifInterface {
141
+ url: string | null
142
+ anime?: string | null
143
+ }
144
+
145
+ export declare interface GifMap {
146
+ action: ActionGifs
147
+ reaction: ReactionGifs
148
+ }
149
+
150
+ export interface GifResponse extends ApiResponse {
151
+ data?: {
152
+ url: string;
153
+ anime: string;
154
+ }
155
+ }
156
+
157
+ export interface ApiResponse {
158
+ message?: string,
159
+ code: number
160
+ }
161
+
162
+ //#endregion
163
+
164
+ //#region Classes
165
+
166
+ /**
167
+ * Clase Welcome
168
+ * Genera una imagen de bienvenida para discord
169
+ * @example
170
+ * const welcome = new neekuro.Welcome()
171
+ * .setResolution(1200, 600)
172
+ * .setFont('arial')
173
+ * .setTitle('¡Bienvenido!', { text_color: '#FF5733' })
174
+ * .setDescription('Al servidor de la comunidad', { font_size: 24 });
175
+ */
176
+ export class Welcome {
177
+ private data: WelcomeData;
178
+
179
+ /**
180
+ * Construye una nueva instancia de Welcome con configuración predeterminada
181
+ */
182
+ constructor();
183
+
184
+ /**
185
+ * Establece la resolución de la imagen de bienvenida
186
+ * @param width Ancho en píxeles o 'default' para 1024px
187
+ * @param height Alto en píxeles o 'default' para 450px
188
+ * @throws {NekoError} Si los parámetros son inválidos
189
+ */
190
+ setResolution(width: number | 'default', height: number | 'default'): this;
191
+
192
+ /**
193
+ * Configura la tipografía para el texto de la imagen
194
+ * @param name Nombre de la fuente predefinida o 'custom' para personalizada
195
+ * @param dir Ruta al archivo .ttf (requerido si name='custom')
196
+ * @throws {NekoError} Si la fuente no existe o los parámetros son inválidos
197
+ */
198
+ setFont(name: FontNames, dir?: string): this;
199
+
200
+ /**
201
+ * Agrega un título a la imagen de bienvenida
202
+ * @param text Texto del título
203
+ * @param data Configuración opcional del título
204
+ * @throws {NekoError} Si los parámetros son inválidos
205
+ */
206
+ setTitle(text: string, data?: WelcomeTextData): this;
207
+
208
+ /**
209
+ * Agrega una descripción a la imagen de bienvenida
210
+ * @param text Texto de la descripción
211
+ * @param data Configuración opcional de la descripción
212
+ * @throws {NekoError} Si los parámetros son inválidos
213
+ */
214
+ setDescription(text: string, data?: WelcomeTextData): this;
215
+
216
+ /**
217
+ * Establece el fondo de la imagen (color o imagen)
218
+ * @param type Tipo de fondo ('color' o 'image')
219
+ * @param data Color hexadecimal o imagen (URL/Buffer)
220
+ * @throws {NekoError} Si los parámetros son inválidos
221
+ */
222
+ setBackground(type: 'color' | 'image', data: string | Buffer): this;
223
+
224
+ /**
225
+ * Establece el avatar y su configuración
226
+ * @param source URL o Buffer de la imagen (formatos soportados: JPEG, PNG, GIF)
227
+ * @param data Configuración opcional del avatar
228
+ * @throws {NekoError} Si los parámetros son inválidos o el formato no es soportado
229
+ */
230
+ setAvatar(source: string | Buffer, data?: WelcomeAvatarData): this;
231
+
232
+ /**
233
+ * Genera la imagen de bienvenida con la configuración actual
234
+ * @returns Buffer de la imagen generada
235
+ * @throws {NekoError} Si faltan datos requeridos
236
+ * @throws {Error} Si hay problemas al cargar imágenes
237
+ */
238
+ build(): Promise<Buffer>;
239
+ }
240
+
241
+ /**
242
+ * Clase Usuario
243
+ * Instancia al usuario que va a usar la api
244
+ * @example
245
+ * let { User } = require('neekuro')
246
+ * let user = new User('token')
247
+ */
248
+ export class User {
249
+ private token_: string | undefined;
250
+ private getToken(): string;
251
+
252
+ /**
253
+ * puedes establecer el token a partir de aqui, pero recomiendo usar el metodo dedicado
254
+ * @param token Token de la api
255
+ */
256
+ constructor(token: string);
257
+ /**
258
+ * establece el token para usar la api
259
+ * @example
260
+ * // no tan recomendada (token expuesto)
261
+ * user.setToken('mf3a***');
262
+ * // recomendada (token oculto)
263
+ * user.setToken(process.env['NeeKuroToken']);
264
+ */
265
+ public token(token: string): void;
266
+ }
267
+
268
+ /**
269
+ * Clase NekoGif
270
+ * Crea un objeto Gif a partir de la respuesta del servidor
271
+ */
272
+ export class NekoGif {
273
+ private url: string | null;
274
+ private anime: string | null;
275
+
276
+ /**
277
+ * Recepcion de la respuesta del servidor.
278
+ * @param response respuesta del servidor
279
+ */
280
+ constructor(response: GifResponse);
281
+
282
+ /**
283
+ * Obten la url del gif
284
+ * @returns {string | null} string: URL
285
+ */
286
+ public getUrl(): string | null;
287
+ /**
288
+ * Obten el anime del gif
289
+ * @returns {string | null} string: Anime
290
+ */
291
+ public getAnime(): string | null;
292
+ }
293
+
294
+ /**
295
+ * Clase BaseUser
296
+ * Unicamente es para el manejo del token a traves de todo el paquete
297
+ */
298
+ export class BaseUser {
299
+
300
+ /**
301
+ * Obten el token del usuario si este ya se estableció
302
+ * @returns {string} Token de usuario
303
+ */
304
+ public static getToken(): string
305
+
306
+ /**
307
+ * Establece el token "global" para todo el paquete
308
+ * @param token token: token a establecer
309
+ */
310
+ public static setToken(token: string): void
311
+ }
312
+
313
+ /**
314
+ * Clase APIClient
315
+ * Se encarga de hacer las solicitudes al servidor
316
+ */
317
+ export class APIClient {
318
+ /**
319
+ * Instanciamiento de la clase
320
+ * @param baseUrl baseUrl: link principal de la api
321
+ * @param data data: objeto para las solicitudes (unicamente requiere el token dentro)
322
+ * @example
323
+ * new APIClient('/ruta', { token: '***' });
324
+ */
325
+ constructor(baseUrl: string, data: APIClientData);
326
+ /**
327
+ * Obtiene el objeto compartido por la api rest a traves de la ruta y con autorizacion por token
328
+ * @param endpoint establece la ruta a la que se quiere comunicar en la api
329
+ * @throws {APIError} solo si sucede un error entre solicitudes
330
+ */
331
+ public get(endpoint: string): Promise<GifResponse>
332
+ }
333
+
334
+ /**
335
+ * Clase APIError
336
+ * Errores personalizados respecto a la api rest
337
+ */
338
+ export class APIError extends Error {
339
+
340
+ /**
341
+ * url a la que se realizo la solicitud
342
+ */
343
+ url: string;
344
+
345
+ /**
346
+ * codigo HTTP de la api
347
+ */
348
+ statusCode: number;
349
+
350
+ /**
351
+ * respuesta de la api
352
+ */
353
+ data: ApiResponse;
354
+
355
+ /**
356
+ * Determina el mensaje del error basado en el codigo
357
+ * @param response respuesta de la api
358
+ * @returns Mensaje de error
359
+ */
360
+ private determineMessage(response: ApiResponse): string;
361
+
362
+ /**
363
+ * Instanciamiento de un error de api
364
+ * @param endpoint endpoint: ruta solicitada
365
+ * @param response response: respuesta por node-fetch
366
+ * @param data data: objeto dado por la api
367
+ */
368
+ constructor(endpoint: string, response: Awaited<Response>, data: ApiResponse);
369
+ }
370
+
371
+ /**
372
+ * Clase NekoError
373
+ * Errores personalizados respecto al paquete
374
+ */
375
+ export class NekoError extends Error {
376
+ /**
377
+ * Instanciamiento de un error del paquete
378
+ * @param name name: nombre del error
379
+ * @param message message: mensaje del error
380
+ */
381
+ constructor(name: string, message: string);
382
+ }
383
+
384
+ //#endregion