ksoft.js
Advanced tools
Comparing version 1.2.6 to 1.2.7
@@ -5,2 +5,3 @@ const { images } = require('./lib/apis/images'); | ||
const { lyrics } = require('./lib/apis/lyrics'); | ||
const music = require('./lib/apis/music'); | ||
const banCreator = require('./lib/util/banCreator'); | ||
@@ -12,3 +13,3 @@ const Webhook = require('./lib/webhook/server'); | ||
* @prop {number} port webhook http server port | ||
* @prop {String} Authentication Your webhook authentication | ||
* @prop {String} authentication Your webhook authentication | ||
*/ | ||
@@ -30,3 +31,3 @@ class ksoftAPI { | ||
if (webhookOptions.useWebhooks) { | ||
this.webhook = new Webhook(webhookOptions.port, webhookOptions.Authentication); | ||
this.webhook = new Webhook(webhookOptions.port, webhookOptions.authentication); | ||
} | ||
@@ -38,2 +39,3 @@ } | ||
this.lyrics = new lyrics(token); | ||
this.music = new music(token); | ||
this.CreateBan = banCreator; | ||
@@ -40,0 +42,0 @@ } |
@@ -7,3 +7,3 @@ /** | ||
* @prop {String} tag The tag for the image | ||
* | ||
* | ||
* @typedef {Object} getRandomMemeResponse The response for images.getRandomMeme | ||
@@ -14,3 +14,3 @@ * @prop {String} title The title of the meme | ||
* @prop {String} subreddit The subreddit the meme came from | ||
* @prop {Number} upvotes The amount of upvotes on the meme | ||
* @prop {Number} upvotes The amount of upvotes on the meme | ||
* @prop {Number} downvotes How many downvotes are on the meme | ||
@@ -21,7 +21,7 @@ * @prop {Number} comments How many comments are on this meme | ||
* @prop {String} author The author of the meme | ||
* | ||
* | ||
* @typedef {Object} tag | ||
* @prop {String} name The name of the tag | ||
* @prop {Boolean} nsfw Whether this tag is nsfw | ||
* | ||
* | ||
* @typedef {Object} getTagsResponse The response for images.getTags | ||
@@ -31,7 +31,7 @@ * @prop {Array<tag>} models Array of tags | ||
* @prop {Array<String>} nsfw_tags List of nsfw tags | ||
* | ||
* | ||
* @typedef {Object} searchTagsResponse The response for images.searchTags | ||
* @prop {Array<tag>} models The tag object in array form | ||
* @prop {Array<String>} tags The tag name in array form | ||
* | ||
* | ||
* @typedef {Object} getImageFromIdResponse The response for images.getImageFromId | ||
@@ -42,3 +42,3 @@ * @prop {String} url The url of the image | ||
* @prop {String} tag The tag for the image | ||
* | ||
* | ||
* @typedef {Object} getRandomWikiHowResponse The response for images.getRandomWikiHow | ||
@@ -49,3 +49,3 @@ * @prop {String} url The url of the image | ||
* @prop {String} article_url The url of the article | ||
* | ||
* | ||
* @typedef {Object} getRandomCutePictueResponse The response for images.getRandomCutePicture | ||
@@ -62,3 +62,3 @@ * @prop {String} title The title of the cute picture | ||
* @prop {String} author The author of the cute picture | ||
* | ||
* | ||
* @typedef {Object} getRandomNSFWResponse The response for images.getRandomNSFW | ||
@@ -75,3 +75,3 @@ * @prop {String} title The title of the nsfw picture | ||
* @prop {String} author The author of the nsfw picture | ||
* | ||
* | ||
* @typedef {Object} getRandomRedditResponse The response for images.getRandomReddit | ||
@@ -89,175 +89,176 @@ * @prop {String} title The title of the reddit post | ||
*/ | ||
const axios = require('axios') | ||
const axios = require('axios'); | ||
let images = class images { | ||
constructor(token){ | ||
this.token = token | ||
this.http = axios.create({ | ||
baseURL: 'https://api.ksoft.si', | ||
timeout: 2000, | ||
headers: {'Authorization': `NANI ${this.token}`} | ||
}) | ||
} | ||
/** | ||
* Gets random meme from KSoft | ||
* @returns {Promise<getRandomMemeResponse>} Information for random meme | ||
*/ | ||
async getRandomMeme(){ | ||
try{ | ||
const { data } = await this.http.get('/images/random-meme') | ||
return data | ||
}catch(err){ | ||
console.error(err) | ||
} | ||
} | ||
/** | ||
* Gets random image from KSoft | ||
* @param {String} tag tag for image | ||
* @returns {Promise<getRandomImageResponse>} Information for random image | ||
*/ | ||
async getRandomImage(tag){ | ||
try{ | ||
if(!tag) throw new Error("[Ksoft API] No tag found") | ||
const { data } = await this.http.get(`/images/random-image?tag=${tag}`) | ||
return data | ||
}catch(err){ | ||
console.error(err) | ||
} | ||
} | ||
/** | ||
* @returns {Promise<getTagsResponse>} List of tags | ||
*/ | ||
async getTags(){ | ||
try{ | ||
const { data } = await this.http.get(`/images/tags`) | ||
return data | ||
}catch(err){ | ||
console.error(err) | ||
} | ||
} | ||
/** | ||
* @param {String} query Query for tags | ||
* @returns {Promise<searchTagsResponse>} Information about the specified tag | ||
*/ | ||
async searchTags(query){ | ||
if(!query) throw new Error("[Ksoft API] Please define a search query") | ||
try{ | ||
const { data } = await this.http.get(`/images/tags/${encodeURIComponent(query)}`) | ||
return data | ||
}catch(err){ | ||
console.error(err) | ||
} | ||
} | ||
/** | ||
* @param {String} snowflake The url of the image you want to get | ||
* @returns {Promise<getImageFromIdResponse>} Information about the specified image | ||
*/ | ||
async getImageFromId(snowflake){ | ||
if(!snowflake) throw new Error("[Ksoft API] Please define a unique image id") | ||
try{ | ||
const { data } = await this.http.get(`/images/image/${encodeURIComponent(snowflake)}`) | ||
return data | ||
}catch(err){ | ||
console.error(err) | ||
} | ||
} | ||
/** | ||
* @param {Boolean} nsfw Whether you want to allow nsfw content | ||
* @returns {Promise<getRandomWikiHowResponse>} Image and article information | ||
*/ | ||
async getRandomWikiHow(nsfw){ | ||
if(!nsfw) { | ||
try{ | ||
const { data } = await this.http.get(`/images/random-wikihow`) | ||
return data | ||
}catch(err){ | ||
console.error(err) | ||
} | ||
}else{ | ||
try{ | ||
const { data } = await this.http.get(`/images/random-wikihow?nsfw=${nsfw}`) | ||
return data | ||
}catch(err){ | ||
console.error(err) | ||
} | ||
} | ||
} | ||
/** | ||
* @returns {Promise<getRandomCutePictueResponse>} Information about the cute picture | ||
*/ | ||
async getRandomCutePictue(){ | ||
try{ | ||
const { data } = await this.http.get(`/images/random-aww`) | ||
return data | ||
}catch(err){ | ||
console.error(err) | ||
} | ||
} | ||
/** | ||
* @param {Boolean} gif Whether this should be a gif or not | ||
* @returns {Promise<getRandomNSFWResponse>} Information about the nsfw picture | ||
*/ | ||
async getRandomNSFW(gif){ | ||
if(!gif){ | ||
try{ | ||
const { data } = await this.http.get(`/images/random-nsfw`) | ||
return data | ||
}catch(err){ | ||
console.error(err) | ||
} | ||
}else{ | ||
try{ | ||
const { data } = await this.http.get(`/images/random-nsfw?gifs=${gif}`) | ||
return data | ||
}catch(err){ | ||
console.error(err) | ||
} | ||
} | ||
} | ||
/** | ||
* @param {String} subReddit Specified subreddit | ||
* @param {String} span Default: "day", select range from which to get the images. Can be one of the following: "hour", "day", "week", "month", "year", "all" | ||
* @param {Boolean} removeNSFW Whether to remove nsfw content or not | ||
* @returns {Promise<getRandomRedditResponse>} | ||
*/ | ||
async getRandomReddit(subReddit, span, removeNSFW){ | ||
if(!subReddit) throw new Error("Please specify a subreddit") | ||
if(removeNSFW && span){ | ||
try{ | ||
const { data } = await this.http.get(`/images/rand-reddit/${encodeURIComponent(subReddit)}?remove_nsfw=${removeNSFW}&span=${span}`) | ||
return data | ||
}catch(err){ | ||
console.error(err) | ||
} | ||
}else if(removeNSFW){ | ||
try{ | ||
const { data } = await this.http.get(`/images/rand-reddit/${encodeURIComponent(subReddit)}?remove_nsfw=${removeNSFW}`) | ||
return data | ||
}catch(err){ | ||
console.error(err) | ||
} | ||
}else if(span){ | ||
try{ | ||
const { data } = await this.http.get(`/images/rand-reddit/${encodeURIComponent(subReddit)}?span=${encodeURIComponent(span)}`) | ||
return data | ||
}catch(err){ | ||
console.error(err) | ||
} | ||
}else{ | ||
try{ | ||
const { data } = await this.http.get(`/images/rand-reddit/${encodeURIComponent(subReddit)}`) | ||
return data | ||
}catch(err){ | ||
console.error(err) | ||
} | ||
} | ||
} | ||
} | ||
constructor(token) { | ||
this.token = token; | ||
this.http = axios.create({ | ||
baseURL: 'https://api.ksoft.si', | ||
timeout: 2000, | ||
headers: { Authorization: `NANI ${this.token}` }, | ||
}); | ||
} | ||
/** | ||
* Gets random meme from KSoft | ||
* @returns {Promise<getRandomMemeResponse>} Information for random meme | ||
*/ | ||
async getRandomMeme() { | ||
try { | ||
const { data } = await this.http.get('/images/random-meme'); | ||
return data; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
/** | ||
* Gets random image from KSoft | ||
* @param {String} tag tag for image | ||
* @returns {Promise<getRandomImageResponse>} Information for random image | ||
*/ | ||
async getRandomImage(tag) { | ||
try { | ||
if (!tag) throw new Error('[Ksoft API] No tag found'); | ||
const { data } = await this.http.get(`/images/random-image?tag=${tag}`); | ||
return data; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
/** | ||
* @returns {Promise<getTagsResponse>} List of tags | ||
*/ | ||
async getTags() { | ||
try { | ||
const { data } = await this.http.get(`/images/tags`); | ||
return data; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
/** | ||
* @param {String} query Query for tags | ||
* @returns {Promise<searchTagsResponse>} Information about the specified tag | ||
*/ | ||
async searchTags(query) { | ||
if (!query) throw new Error('[Ksoft API] Please define a search query'); | ||
try { | ||
const { data } = await this.http.get(`/images/tags/${encodeURIComponent(query)}`); | ||
return data; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
/** | ||
* @param {String} snowflake The url of the image you want to get | ||
* @returns {Promise<getImageFromIdResponse>} Information about the specified image | ||
*/ | ||
async getImageFromId(snowflake) { | ||
if (!snowflake) throw new Error('[Ksoft API] Please define a unique image id'); | ||
try { | ||
const { data } = await this.http.get(`/images/image/${encodeURIComponent(snowflake)}`); | ||
return data; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
/** | ||
* @param {Boolean} nsfw Whether you want to allow nsfw content | ||
* @returns {Promise<getRandomWikiHowResponse>} Image and article information | ||
*/ | ||
async getRandomWikiHow(nsfw) { | ||
if (!nsfw) { | ||
try { | ||
const { data } = await this.http.get(`/images/random-wikihow`); | ||
return data; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} else { | ||
try { | ||
const { data } = await this.http.get(`/images/random-wikihow?nsfw=${nsfw}`); | ||
return data; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
} | ||
/** | ||
* @returns {Promise<getRandomCutePictueResponse>} Information about the cute picture | ||
*/ | ||
async getRandomCutePictue() { | ||
try { | ||
const { data } = await this.http.get(`/images/random-aww`); | ||
return data; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
/** | ||
* @param {Boolean} gif Whether this should be a gif or not | ||
* @returns {Promise<getRandomNSFWResponse>} Information about the nsfw picture | ||
*/ | ||
async getRandomNSFW(gif) { | ||
if (!gif) { | ||
try { | ||
const { data } = await this.http.get(`/images/random-nsfw`); | ||
return data; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} else { | ||
try { | ||
const { data } = await this.http.get(`/images/random-nsfw?gifs=${gif}`); | ||
return data; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
} | ||
/** | ||
* @param {String} subReddit Specified subreddit | ||
* @param {String} span Default: "day", select range from which to get the images. Can be one of the following: "hour", "day", "week", "month", "year", "all" | ||
* @param {Boolean} removeNSFW Whether to remove nsfw content or not | ||
* @returns {Promise<getRandomRedditResponse>} | ||
*/ | ||
async getRandomReddit(subReddit, span, removeNSFW) { | ||
if (!subReddit) throw new Error('Please specify a subreddit'); | ||
if (removeNSFW && span) { | ||
try { | ||
const { data } = await this.http.get( | ||
`/images/rand-reddit/${encodeURIComponent(subReddit)}?remove_nsfw=${removeNSFW}&span=${span}` | ||
); | ||
return data; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} else if (removeNSFW) { | ||
try { | ||
const { data } = await this.http.get( | ||
`/images/rand-reddit/${encodeURIComponent(subReddit)}?remove_nsfw=${removeNSFW}` | ||
); | ||
return data; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} else if (span) { | ||
try { | ||
const { data } = await this.http.get( | ||
`/images/rand-reddit/${encodeURIComponent(subReddit)}?span=${encodeURIComponent(span)}` | ||
); | ||
return data; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} else { | ||
try { | ||
const { data } = await this.http.get(`/images/rand-reddit/${encodeURIComponent(subReddit)}`); | ||
return data; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
} | ||
}; | ||
module.exports = { | ||
images | ||
} | ||
images, | ||
}; |
{ | ||
"name": "ksoft.js", | ||
"version": "1.2.6", | ||
"version": "1.2.7", | ||
"description": "Official API Wrapper for KSoft.Si API, written in Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -72,3 +72,3 @@ # ksoft.js | ||
proof: String, | ||
appeal_possible: Boolean, | ||
appeal_possible: Boolean | ||
}); | ||
@@ -99,3 +99,3 @@ ``` | ||
bannedOnly: Boolean, | ||
advancedBannedOnly: Boolean, // this can only be used by itself | ||
advancedBannedOnly: Boolean // this can only be used by itself | ||
}); | ||
@@ -108,3 +108,3 @@ ``` | ||
moreInfo: Boolean, | ||
ignoreBots: Boolean, | ||
ignoreBots: Boolean | ||
}); | ||
@@ -169,2 +169,8 @@ ``` | ||
### Music api | ||
```javascript | ||
ksoft.music.recommendations(provider: String, tracks: String | Array<String>) | ||
``` | ||
## Webhook feature | ||
@@ -179,3 +185,3 @@ | ||
port: 2000, // this is the port the http server is going to run on. This can be whatever port you want I am just using 2000 as an example | ||
authentication: 'your webhook authentication token', | ||
authentication: 'your webhook authentication token' | ||
}); | ||
@@ -182,0 +188,0 @@ |
88406
12
1147
218