diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a3bfa41 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +# Packages +node_modules/ +package-lock.json + +# Log files +logs/ +*.log + +# Environment +.env + +# Miscellaneous +.tmp/ +.vscode/ +.DS_Store diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..a3bfa41 --- /dev/null +++ b/.npmignore @@ -0,0 +1,15 @@ +# Packages +node_modules/ +package-lock.json + +# Log files +logs/ +*.log + +# Environment +.env + +# Miscellaneous +.tmp/ +.vscode/ +.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..31d7896 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Cath diff --git a/index.js b/index.js new file mode 100644 index 0000000..f5518cf --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +const APIClient = require("./src/class/apiclient"); +const random8ball = require("./src/functions/8ball"); +module.exports = { random8ball, APIClient }; diff --git a/package.json b/package.json new file mode 100644 index 0000000..df66bea --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/src/class/apiclient.js b/src/class/apiclient.js new file mode 100644 index 0000000..006c734 --- /dev/null +++ b/src/class/apiclient.js @@ -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} + * @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; diff --git a/src/functions/8ball.js b/src/functions/8ball.js new file mode 100644 index 0000000..6e4b21f --- /dev/null +++ b/src/functions/8ball.js @@ -0,0 +1,13 @@ +const axios = require("axios"); +const config = require("../utils/config.json"); +/** + * Sends a 8ball response + * @returns {Promise} + */ +async function random() { + const data = await axios + .get(`${config.api}/api/v1/fun/8ball`) + .then(res => res.data); + return data.answer; +} +module.exports = random; diff --git a/src/typings/index.d.ts b/src/typings/index.d.ts new file mode 100644 index 0000000..17830a9 --- /dev/null +++ b/src/typings/index.d.ts @@ -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; + public getperk(perk: string): Promise; + } + export type APIClientOptions = { + codm?: string; + }; +} diff --git a/src/utils/config.json b/src/utils/config.json new file mode 100644 index 0000000..fcb8deb --- /dev/null +++ b/src/utils/config.json @@ -0,0 +1,3 @@ +{ + "api": "https://www.cathapi.gq" +}