package 1.1.0

This commit is contained in:
night0721 2021-09-09 04:19:10 +08:00
parent 193249b143
commit 08e984b00b
9 changed files with 137 additions and 0 deletions

15
.gitignore vendored Normal file
View file

@ -0,0 +1,15 @@
# Packages
node_modules/
package-lock.json
# Log files
logs/
*.log
# Environment
.env
# Miscellaneous
.tmp/
.vscode/
.DS_Store

15
.npmignore Normal file
View file

@ -0,0 +1,15 @@
# Packages
node_modules/
package-lock.json
# Log files
logs/
*.log
# Environment
.env
# Miscellaneous
.tmp/
.vscode/
.DS_Store

1
README.md Normal file
View file

@ -0,0 +1 @@
# Cath

3
index.js Normal file
View file

@ -0,0 +1,3 @@
const APIClient = require("./src/class/apiclient");
const random8ball = require("./src/functions/8ball");
module.exports = { random8ball, APIClient };

38
package.json Normal file
View file

@ -0,0 +1,38 @@
{
"name": "cath",
"version": "1.1.0",
"description": "A powerful package that can interact with Cath API",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon .",
"start": "node .",
"node-update": "npm i --save-dev node@16 && npm config set prefix=$(pwd)/node_modules/node && export PATH=$(pwd)/node_modules/node/bin:$PATH",
"node-clean": "rm -rf node_modules && rm package-lock.json && npm cache clear --force && npm cache clean --force && npm i",
"node-update-then-clean": "npm run node-update && npm run node-clean-cache",
"canvas": "npm uninstall canvas && npm i canvas",
"all": "npm run node-update && npm run node-clean && npm uninstall canvas && npm i canvas && node ."
},
"repository": {
"type": "git",
"url": "git+https://github.com/CathTeam/cath.git"
},
"bugs": {
"url": "https://github.com/CathTeam/cath/issues"
},
"homepage": "https://github.com/CathTeam/cath#readme",
"keywords": [
"cath",
"cath.exe",
"cat",
"api",
"discord",
"codm"
],
"author": "Ń1ght#0001",
"license": "Apache-2.0",
"dependencies": {
"axios": "^0.21.4",
"discord.js": "^13.1.0"
}
}

35
src/class/apiclient.js Normal file
View file

@ -0,0 +1,35 @@
const axios = require("axios");
const config = require("../utils/config.json");
/**
* @class APIClient
**/
class APIClient {
/**
* @name APIClient
* @kind constructor
* @param {String} key Authorization Key for API (Only for CODM commands)
* @param {String} [options.key]
*/
constructor(key, options = {}) {
if (key && typeof key !== "string")
throw new TypeError("API key must be a string");
if (key) this.key = key;
}
/**
* Sends a CODM perk object
* @returns {Promise<Object>}
* @param {String} name
*/
async getperk(name) {
const data = await axios
.get(`${config.api}/api/v1/codm/perks?name=${name}`, {
headers: {
Authorization: this.key,
},
})
.then(res => res.data)
.catch(err => console.error(`Unauthorized to use`));
return data;
}
}
module.exports = APIClient;

13
src/functions/8ball.js Normal file
View file

@ -0,0 +1,13 @@
const axios = require("axios");
const config = require("../utils/config.json");
/**
* Sends a 8ball response
* @returns {Promise<String>}
*/
async function random() {
const data = await axios
.get(`${config.api}/api/v1/fun/8ball`)
.then(res => res.data);
return data.answer;
}
module.exports = random;

14
src/typings/index.d.ts vendored Normal file
View file

@ -0,0 +1,14 @@
declare module "cath" {
export class APIClient {
public constructor(key: string, options?: APIClientOptions);
private key: string;
public options?: APIClientOptions;
public random8ball(): Promise<String>;
public getperk(perk: string): Promise<Object>;
}
export type APIClientOptions = {
codm?: string;
};
}

3
src/utils/config.json Normal file
View file

@ -0,0 +1,3 @@
{
"api": "https://www.cathapi.gq"
}