From b5f6711642e8ea1b427904970c7d07c47a07a912 Mon Sep 17 00:00:00 2001 From: BearTS Date: Mon, 8 Feb 2021 15:41:00 +0530 Subject: [PATCH] Update To v1.3.2 (#5) Addition Of RolePlay API --- README.md | 27 ++++++++++++++++++++++----- index.d.ts | 3 ++- package.json | 8 ++++---- src/tamakoapi.js | 29 +++++++++++++++++++++++++---- 4 files changed, 53 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 8d513fa..9833552 100644 --- a/README.md +++ b/README.md @@ -132,13 +132,13 @@ tamako.animalfact('dog') .then(res => console.log(res)) ``` -## image(name) +## image(type) Returns an image link -`name` can be any of the following: -| | | | | | | | | -| - | - | - | - | - | - | - | - | -| bird | dog | cat | dog | fox | koala | panda | redpanda | +`type` can be any of the following: +| | | | | | | | | | | +| - | - | - | - | - | - | - | - | - | - | +| bird | dog | cat | dog | fox | koala | panda | redpanda | tamako | mai | Example ```js @@ -149,6 +149,23 @@ tamako.image('dog') .then(res => console.log(res)) ``` +## roleplay(type) +Returns a gif image link + +`type` can be any of the following: +| | | | | | | | | | | | | | | | | +| - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | +| baka | blush | cry | disgust | feed | happy | holdhands | hug | kiss | pat | poke | slap | sleep | smug | wave | wink | + +Example +```js +const { TAMAKOAPI } = require('tamako-api'); +const tamako = new TAMAKOAPI(); + +tamako.roleplay('hug') +.then(res => console.log(res)) +``` + # Events `error` - Returns an error if an error is returned from the API. Example diff --git a/index.d.ts b/index.d.ts index d7d6091..b4a26b3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -6,7 +6,8 @@ export class API { public pokemon(name: string): Promise; public animequote(): Promise; public animalfact(name: string): Promise; - public image(name: string): Promise; + public image(type: string): Promise; + public roleplay(type: string): Promise; public joke(): Promise; public on(error): error } diff --git a/package.json b/package.json index 0b91c96..4affa62 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tamako-api", - "version": "1.2.5", + "version": "1.3.2", "description": "A package for using the Tamako API Easily!", "main": "index.js", "scripts": { @@ -8,7 +8,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/BearTS/tamako-api/.git" + "url": "git+https://github.com/Tamako-Tech/tamako-api/.git" }, "keywords": [ "API", @@ -22,9 +22,9 @@ "author": "Bear#3437 ", "license": "Apache-2.0", "bugs": { - "url": "https://github.com/BearTS/tamako-api/issues" + "url": "https://github.com/Tamako-Tech/tamako-api/issues" }, - "homepage": "https://github.com/BearTS/tamako-api#readme", + "homepage": "https://github.com/Tamako-Tech/tamako-api#readme", "dependencies": { "node-fetch": "^2.6.1" } diff --git a/src/tamakoapi.js b/src/tamakoapi.js index 5520446..caa2df7 100644 --- a/src/tamakoapi.js +++ b/src/tamakoapi.js @@ -113,12 +113,33 @@ class TAMAKOAPI extends EventEmitter { /**Returns an image - * @name animalfact - * @param {string} name Type to query + * @name image + * @param {string} type Type of query * @returns {string} url URL link to the type of image */ - async image(name) { - const res = await fetch(`${base}/image/${encodeURIComponent(name)}`); + async image(type) { + const res = await fetch(`${base}/image/${type}`); + if (res.status == 401) { + this.emit("error", "Check With Bear#3437"); + return undefined; + } + + const response = await res.json(); + if (response.error) { + this.emit('error', response.error); + return undefined; + } + return response.url; + }; + + + /**Returns an Roleplay gif link + * @name roleplay + * @param {string} type Type of query + * @returns {string} url GIF link to the type of roleplay + */ + async roleplay(type) { + const res = await fetch(`${base}/roleplay/${type}`); if (res.status == 401) { this.emit("error", "Check With Bear#3437"); return undefined;