Socket
Socket
Sign inDemoInstall

ksoft.js

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ksoft.js - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

lib/util/banCreator.js

57

index.js

@@ -1,6 +0,7 @@

const { images } = require("./lib/apis/images")
const { bans } = require("./lib/apis/bans")
const { kumo } = require("./lib/apis/kumo")
const { lyrics } = require("./lib/apis/lyrics")
const Webhook = require("./lib/webhook/server")
const { images } = require('./lib/apis/images');
const { bans } = require('./lib/apis/bans');
const { kumo } = require('./lib/apis/kumo');
const { lyrics } = require('./lib/apis/lyrics');
const banCreator = require('./lib/util/banCreator');
const Webhook = require('./lib/webhook/server');
/**

@@ -12,26 +13,26 @@ * @typedef {Object} webhookOptions webhook options

*/
class ksoftAPI{
/**
* @constructor
* @param {number} token Your ksoft api token
* @param {boolean} useWebhooks Whether you want to use the webhook feature
* @param {webhookOptions} webhookOptions webhook options
*/
constructor(token, webhookOptions){
/**
* The webhook class if useWebhooks is true
* @type {Webhook?}
*/
this.webhook = null
if(webhookOptions.useWebhooks){
this.webhook = new Webhook(webhookOptions.port, webhookOptions.Authentication)
}
this.images = new images(token)
this.bans = new bans(token)
this.kumo = new kumo(token)
this.lyrics = new lyrics(token)
}
class ksoftAPI {
/**
* @constructor
* @param {number} token Your ksoft api token
* @param {boolean} useWebhooks Whether you want to use the webhook feature
* @param {webhookOptions} webhookOptions webhook options
*/
constructor(token, webhookOptions) {
/**
* The webhook class if useWebhooks is true
* @type {Webhook?}
*/
this.webhook = null;
if (webhookOptions.useWebhooks) {
this.webhook = new Webhook(webhookOptions.port, webhookOptions.Authentication);
}
this.images = new images(token);
this.bans = new bans(token);
this.kumo = new kumo(token);
this.lyrics = new lyrics(token);
this.CreateBan = banCreator;
}
}
module.exports = ksoftAPI
module.exports = ksoftAPI;
/**
* @typedef {Object} banInfo Ban info
* @prop {Number} user Users Discord ID that you are banning/reporting
* @prop {Number} mod Users Discord ID who posted/reported the ban
* @prop {String} user_name Users Discord username
* @prop {Number} user_discriminator Users Discord discriminator
* @prop {String} reason Reason why user should be globally banned
* @prop {String} proof URL of the image showing the act
* @prop {Boolean} appeal_possible If appeal should be disabled for that user.
*
* @typedef {Object} BanAddResponse The response from bans.add
* @prop {String} Success Whether it was successful or not
*
* @typedef {Object} BanInfoRespnse The response for bans.getBanInfo
* @prop {Number} id The id of the person banned
* @prop {String} name Name of the person banned
* @prop {String} discriminator The #discriminator of the person banned
* @prop {Number} moderator_id The id of the moderator who banned the person
* @prop {String} reason The reason for the ban
* @prop {String} proof The url for the picture or video of the person doing the thing that got them banned
* @prop {Boolean} is_ban_active Whether or not the ban is active
* @prop {Boolean} can_be_appealed Whether or not the ban can be appealed
* @prop {String} timestamp The timestamp of the ban
* @prop {String} appeal_reason the reason of the appeal if available
* @prop {String} appeal_date The date of the appeal if available
* @prop {String} requested_by The person who requested this information
* @prop {Boolean} exists Whether or not this ban exists
*
* @typedef {Object} banCheckResponse The response for bans.check
* @prop {Boolean} is_banned Whether or not this person is banned
*
* @typedef {Object} banListResponse The response of bans.list
* @prop {Number} ban_count How many bans the api is holding
* @prop {Number} page_count How many pages are in the api
* @prop {Number} per_page How many bans are on each page
* @prop {Number} page What page your on
* @prop {Number} on_page How many bans are on this page
* @prop {Number} next_page The numer of the next page
* @prop {any} previous_page The number of the previous page. Will return null if 0
* @prop {Array<BanInfoRespnse>} data List of bans
*
* @typedef {Object} SimpleBanObject Basic ban info
* @prop {Number} id ID of the user banned
* @prop {String} reason Reason for the ban
* @prop {String} proof Proof of the ban
* @prop {Number} moderator_id ID of the moderator who banned the person
* @prop {Boolean} active Whether or not the ban is active
*
* @typedef {Object} banUpdatesResponse The response of bans.getUpdates
* @prop {Array<SimpleBanObject>} data Array of bans on that date
* @prop {Number} current_timestamp Current timestamp of update
*/
* @typedef {Object} banInfo Ban info
* @prop {Number} user Users Discord ID that you are banning/reporting
* @prop {Number} mod Users Discord ID who posted/reported the ban
* @prop {String} user_name Users Discord username
* @prop {Number} user_discriminator Users Discord discriminator
* @prop {String} reason Reason why user should be globally banned
* @prop {String} proof URL of the image showing the act
* @prop {Boolean} appeal_possible If appeal should be disabled for that user.
*
* @typedef {Object} BanAddResponse The response from bans.add
* @prop {String} Success Whether it was successful or not
*
* @typedef {Object} BanInfoRespnse The response for bans.getBanInfo
* @prop {Number} id The id of the person banned
* @prop {String} name Name of the person banned
* @prop {String} discriminator The #discriminator of the person banned
* @prop {Number} moderator_id The id of the moderator who banned the person
* @prop {String} reason The reason for the ban
* @prop {String} proof The url for the picture or video of the person doing the thing that got them banned
* @prop {Boolean} is_ban_active Whether or not the ban is active
* @prop {Boolean} can_be_appealed Whether or not the ban can be appealed
* @prop {String} timestamp The timestamp of the ban
* @prop {String} appeal_reason the reason of the appeal if available
* @prop {String} appeal_date The date of the appeal if available
* @prop {String} requested_by The person who requested this information
* @prop {Boolean} exists Whether or not this ban exists
*
* @typedef {Object} banCheckResponse The response for bans.check
* @prop {Boolean} is_banned Whether or not this person is banned
*
* @typedef {Object} banListResponse The response of bans.list
* @prop {Number} ban_count How many bans the api is holding
* @prop {Number} page_count How many pages are in the api
* @prop {Number} per_page How many bans are on each page
* @prop {Number} page What page your on
* @prop {Number} on_page How many bans are on this page
* @prop {Number} next_page The numer of the next page
* @prop {any} previous_page The number of the previous page. Will return null if 0
* @prop {Array<BanInfoRespnse>} data List of bans
*
* @typedef {Object} SimpleBanObject Basic ban info
* @prop {Number} id ID of the user banned
* @prop {String} reason Reason for the ban
* @prop {String} proof Proof of the ban
* @prop {Number} moderator_id ID of the moderator who banned the person
* @prop {Boolean} active Whether or not the ban is active
*
* @typedef {Object} banUpdatesResponse The response of bans.getUpdates
* @prop {Array<SimpleBanObject>} data Array of bans on that date
* @prop {Number} current_timestamp Current timestamp of update
*/
const axios = require('axios')
const FormData = require("form-data")
const axios = require('axios');
const FormData = require('form-data');
let bans = class bans {
constructor(token){
this.token = token
this.http = axios.create({
baseURL: 'https://api.ksoft.si',
timeout: 2000,
headers: {'Authorization': `NANI ${this.token}`}
})
}
/**
* @param {banInfo} banData
* @returns {Promise<BanAddResponse>} If the Post was successful or not
*/
async add(banData){
if(!banData) throw new Error("[Ksoft API] Please specify json banData")
const form = new FormData()
for ( const key in banData ) {
form.append(key, banData[key]);
}
try{
const { data } = await this.http.post("/bans/add",form,{
headers: form.getHeaders()
})
return data
}catch(err){
console.error(err)
}
}
/**
* @param {String} userID The userID of the person you want to get info for
* @returns {Promise<BanInfoRespnse>} info about the ban
*/
async getBanInfo(userID){
if(!userID) throw new Error("[Ksoft API] Please specify user ID")
if(typeof userID !== "string") throw new Error("[Ksoft API] userID must be a string")
try{
const { data } = await this.http.get(`/bans/info?user=${userID}`)
return data
}catch(err){
console.error(err)
}
}
/**
* @param {String} userID The user id for the person being banned
* @returns {Promise<banCheckResponse>} Whether or not the ban is active
*/
async check(userID){
if(!userID) throw new Error("[Ksoft API] Please specify user ID")
if(typeof userID !== "string") throw new Error("[Ksoft API] userID must be a string")
try{
const { data } = await this.http.get(`/bans/check?user=${userID}`)
return data
}catch(err){
console.error(err)
}
}
/**
*
* @param {Number} page Which page to return
* @param {Number} perPage How many items per page
* @returns {Promise<banListResponse>} List of ban objects
*/
async list(page,perPage){
if(!page && !perPage){
try{
const { data } = await this.http.get(`/bans/list`)
return data
}catch(err){
console.error(err)
}
}else if(!perPage){
try{
const { data } = await this.http.get(`/bans/list?page=${page}`)
return data
}catch(err){
console.error(err)
}
}else if(!page){
try{
const { data } = await this.http.get(`/bans/list?per_page=${perPage}`)
return data
}catch(err){
console.error(err)
}
}else{
try{
const { data } = await this.http.get(`/bans/list?page=${page}&per_page=${perPage}`)
return data
}catch(err){
console.error(err)
}
}
}
/**
* @param {Number} epochDate An epoch date. Example: 1539915420 (October 19 2018)
* @returns {Promise<banUpdatesResponse>} List of bans on that date. will return empty array if nothing on that date
*/
async getUpdate(epochDate){
if(!epochDate) throw new Error("[Ksoft API] Please specify an epochDate. Example: 1539915420")
try{
const { data } = await this.http.get(`/bans/updates?timestamp=${epochDate}`)
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}` },
});
}
/**
* @param {banInfo} banData
* @returns {Promise<BanAddResponse>} If the Post was successful or not
*/
async add(banData) {
if (!banData) throw new Error('[Ksoft API] Please specify the banData');
if (banData.data) {
const jsonBanData = banData.data;
}
if (!jsonBanData.user || !jsonBanData.proof || !jsonBanData.reason)
throw new Error('[Ksoft API] user, reason, and proof fields are required');
if (jsonBanData.appeal_possible === false || jsonBanData.appeal_possible === true)
await setAppealString(jsonBanData.appeal_possible);
const form = new FormData();
for (const key in jsonBanData) {
form.append(key, jsonBanData[key]);
}
try {
const { data } = await this.http.post('/bans/add', form, {
headers: form.getHeaders(),
});
return data;
} catch (err) {
console.error(err);
}
async function setAppealString(boolean) {
return (jsonBanData.appeal_possible = `${boolean}`);
}
}
const form = new FormData();
for (const key in banData) {
form.append(key, banData[key]);
}
try {
const { data } = await this.http.post('/bans/add', form, {
headers: form.getHeaders(),
});
return data;
} catch (err) {
console.error(err);
}
}
/**
* @param {String} userID The userID of the person you want to get info for
* @returns {Promise<BanInfoRespnse>} info about the ban
*/
async getBanInfo(userID) {
if (!userID) throw new Error('[Ksoft API] Please specify user ID');
if (typeof userID !== 'string') throw new Error('[Ksoft API] userID must be a string');
try {
const { data } = await this.http.get(`/bans/info?user=${userID}`);
return data;
} catch (err) {
console.error(err);
}
}
/**
* @param {String} userID The user id for the person being banned
* @returns {Promise<banCheckResponse>} Whether or not the ban is active
*/
async check(userID) {
if (!userID) throw new Error('[Ksoft API] Please specify user ID');
if (typeof userID !== 'string') throw new Error('[Ksoft API] userID must be a string');
try {
const { data } = await this.http.get(`/bans/check?user=${userID}`);
return data;
} catch (err) {
console.error(err);
}
}
/**
*
* @param {Number} page Which page to return
* @param {Number} perPage How many items per page
* @returns {Promise<banListResponse>} List of ban objects
*/
async list(page, perPage) {
if (!page && !perPage) {
try {
const { data } = await this.http.get(`/bans/list`);
return data;
} catch (err) {
console.error(err);
}
} else if (!perPage) {
try {
const { data } = await this.http.get(`/bans/list?page=${page}`);
return data;
} catch (err) {
console.error(err);
}
} else if (!page) {
try {
const { data } = await this.http.get(`/bans/list?per_page=${perPage}`);
return data;
} catch (err) {
console.error(err);
}
} else {
try {
const { data } = await this.http.get(`/bans/list?page=${page}&per_page=${perPage}`);
return data;
} catch (err) {
console.error(err);
}
}
}
/**
* @param {Number} epochDate An epoch date. Example: 1539915420 (October 19 2018)
* @returns {Promise<banUpdatesResponse>} List of bans on that date. will return empty array if nothing on that date
*/
async getUpdate(epochDate) {
if (!epochDate) throw new Error('[Ksoft API] Please specify an epochDate. Example: 1539915420');
try {
const { data } = await this.http.get(`/bans/updates?timestamp=${epochDate}`);
return data;
} catch (err) {
console.error(err);
}
}
};
module.exports = {
bans
}
bans,
};
{
"name": "ksoft.js",
"version": "1.1.0",
"description": "Official API Wrapper for KSoft.Si API, written in Node.js",
"main": "index.js",
"scripts": {
"test": "nodemon -q ./testing/test.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ksoft-si/ksoft.js.git"
},
"keywords": [
"api-wrapper",
"api-client",
"image",
"lyrics-fetcher",
"discord-bot",
"discord-js"
],
"author": "x_rebelfighter_x",
"license": "MIT",
"bugs": {
"url": "https://github.com/ksoft-si/ksoft.js/issues"
},
"homepage": "https://github.com/ksoft-si/ksoft.js#readme",
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"express": "^4.16.4",
"form-data": "^2.3.3",
"public-ip": "^2.4.0"
},
"devDependencies": {
"eslint": "^5.6.0",
"eslint-config-standard": "^12.0.0",
"standard": "^12.0.1"
}
"name": "ksoft.js",
"version": "1.1.1",
"description": "Official API Wrapper for KSoft.Si API, written in Node.js",
"main": "index.js",
"scripts": {
"test": "nodemon -q ./testing/test.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ksoft-si/ksoft.js.git"
},
"keywords": [
"api-wrapper",
"api-client",
"image",
"lyrics-fetcher",
"discord-bot",
"discord-js"
],
"author": "x_rebelfighter_x",
"license": "MIT",
"bugs": {
"url": "https://github.com/ksoft-si/ksoft.js/issues"
},
"homepage": "https://github.com/ksoft-si/ksoft.js#readme",
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"express": "^4.16.4",
"form-data": "^2.3.3",
"public-ip": "^2.4.0"
},
"devDependencies": {
"eslint": "^5.6.0",
"eslint-config-standard": "^12.0.0",
"standard": "^12.0.1"
}
}
# ksoft.js
Official API Wrapper for [KSoft](https://docs.ksoft.si/api/) API, written in Node.js

@@ -7,2 +8,3 @@

installing...
```

@@ -15,36 +17,37 @@ npm install ksoft.js --save

### Images Api
```javascript
ksoft.images.getRandomMeme()
ksoft.images.getRandomMeme();
```
```javascript
ksoft.images.getRandomImage(tag)
ksoft.images.getRandomImage(tag);
```
```javascript
ksoft.images.getTags()
ksoft.images.getTags();
```
```javascript
ksoft.images.searchTags(tag)
ksoft.images.searchTags(tag);
```
```javascript
ksoft.images.getImageFromId(snowflake)
ksoft.images.getImageFromId(snowflake);
```
```javascript
ksoft.images.getRandomWikiHow(nsfw)
ksoft.images.getRandomWikiHow(nsfw);
```
```javascript
ksoft.images.getRandomCutePicture()
ksoft.images.getRandomCutePicture();
```
```javascript
ksoft.images.getRandomNSFW()
ksoft.images.getRandomNSFW();
```
```javascript
ksoft.images.getRandomReddit(subReddit,removeNSFW,span)
ksoft.images.getRandomReddit(subReddit, removeNSFW, span);
```

@@ -56,26 +59,26 @@

ksoft.bans.add({
user: String ,
mod: String ,
user_name: String ,
user_discriminator: String ,
reason: String ,
proof: String,
appeal_possible: Boolean
})
user: String,
mod: String,
user_name: String,
user_discriminator: String,
reason: String,
proof: String,
appeal_possible: Boolean,
});
```
```javascript
ksoft.bans.getBanInfo(userID)
ksoft.bans.getBanInfo(userID);
```
```javascript
ksoft.bans.check(userID)
ksoft.bans.check(userID);
```
```javascript
ksoft.bans.list(page,perPage)
ksoft.bans.list(page, perPage);
```
```javascript
ksoft.bans.getUpdate(epochDate)
ksoft.bans.getUpdate(epochDate);
```

@@ -87,19 +90,19 @@

ksoft.kumo.search(q, {
fast: Boolean,
more: Boolean,
mapZoom: Number,
includeMap: Boolean
})
fast: Boolean,
more: Boolean,
mapZoom: Number,
includeMap: Boolean,
});
```
```javascript
ksoft.kumo.getSimpleWeather(reportType,q,units,lang,icons)
ksoft.kumo.getSimpleWeather(reportType, q, units, lang, icons);
```
```javascript
ksoft.kumo.geoip(ip)
ksoft.kumo.geoip(ip);
```
```javascript
ksoft.kumo.convertCurrency(from,to,value)
ksoft.kumo.convertCurrency(from, to, value);
```

@@ -111,17 +114,17 @@

ksoft.lyrics.search(q, {
textOnly: Boolean,
limit: Number
})
textOnly: Boolean,
limit: Number,
});
```
```javascript
ksoft.lyrics.getArtistById(id)
ksoft.lyrics.getArtistById(id);
```
```javascript
ksoft.lyrics.getAlbumById(id)
ksoft.lyrics.getAlbumById(id);
```
```javascript
ksoft.lyrics.getTrackById(id)
ksoft.lyrics.getTrackById(id);
```

@@ -134,12 +137,12 @@

```javascript
const Ksoft = require("ksoft.js")
const ksoft = new Ksoft("your ksoft token", {
useWebhooks: true,
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"
})
const Ksoft = require('ksoft.js');
const ksoft = new Ksoft('your ksoft token', {
useWebhooks: true,
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',
});
ksoft.webhook.on("ready", info => {
console.log(info) // this will return the host your http server is running on. This is what you will give to ksoft to send the info to. { "host": "yourpublicip:theportyouspecified"}
})
ksoft.webhook.on('ready', info => {
console.log(info); // this will return the host your http server is running on. This is what you will give to ksoft to send the info to. { "host": "yourpublicip:theportyouspecified"}
});
```

@@ -150,10 +153,27 @@

```javascript
// this is an extension of the previous example. Everything works on events so you can simply do this
// this is an extension of the previous example. Everything works on events so you can simply do this
ksoft.webhook.on('ban', banData => {
console.log(banData) // there you simply get the banInfo sent from ksoft. All the event names are the same as on the ksoft documentation so if you want more info just go to https://docs.ksoft.si/api/webhooks
})
ksoft.webhook.on('ban', banData => {
console.log(banData); // there you simply get the banInfo sent from ksoft. All the event names are the same as on the ksoft documentation so if you want more info just go to https://docs.ksoft.si/api/webhooks
});
```
## Using the BanCreator utility
```javascript
// the ksoft variable I am using is the initialized Ksoft class
const ban = new ksoft.CreateBan()
.setUserID('1234567892355822') // this is required
.setModID('44457845784574578')
.setUserName('blahblahblah')
.setUserDiscriminator('1234')
.setReason('testing123') // also required
.setProof('proof') // this is also required
.isAppealable(true);
ksoft.bans.add(ban).then(res => {
console.log(res); // { success: true}
});
```
Special thanks to sdf for helping me troubleshoot some stuff :)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc