Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kiai.js v1 #56

Merged
merged 8 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/sixty-parrots-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"kiai.js": major
---

Implement all v1 API features

**This is a major release**, and thus, is a breaking change from previous early releases of Kiai.js.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
* @thewilloftheshadow
/packages/kiai.js @OIRNOIR
/packages/kiai.js @thewilloftheshadow @OIRNOIR
10 changes: 5 additions & 5 deletions .github/workflows/kiai_docs.yml → .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Generate kiai.js docs
name: Generate Docs

on:
push:
Expand Down Expand Up @@ -34,12 +34,12 @@ jobs:
run: pnpm install

- name: Generate Docs
run: pnpm run docs --filter kiai.js
run: pnpm run docs

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
publish_branch: kiaijs-docs
publish_branch: docs
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./packages/kiai.js/docs
cname: kiai.js.org
publish_dir: ./docs
cname: utilities.buape.com
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- uses: pnpm/action-setup@v2.2.4
with:
version: 7
version: 8

- name: Setup Node.js environment
uses: actions/setup-node@v3
Expand Down
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tabWidth": 4,
"semi": false,
"useTabs": true,
"proseWrap": "never",
"printWidth": 150,
"trailingComma": "none",
"singleQuote": false
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"dotenv.enableAutocloaking": false
"dotenv.enableAutocloaking": false,
"findUnusedExports.detectCircularImports": true
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Buape
Copyright (c) 2023 Buape Studios

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
22 changes: 14 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@
"private": true,
"scripts": {
"build": "turbo run build",
"clean": "turbo run clean",
"coverage": "vitest run --coverage",
"docs": "typedoc",
"dev": "dotenv -- turbo run dev",
"pretty": "pnpm run format && pnpm run lint",
"lint": "turbo run lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"lint": "turbo run lint",
"preinstall": "only-allow pnpm",
"clean": "turbo run clean",
"pretty": "pnpm run format && pnpm run lint",
"test": "dotenv -- vitest",
"changeset": "changeset add",
"publish": "changeset version && pnpm run build && changeset publish",
"test": "turbo run test",
"docs": "typedoc"
"publish": "changeset version && pnpm run build && changeset publish"
},
"engines": {
"node": ">=14.0.0"
"node": ">=16.20.0"
},
"dependencies": {
"@changesets/cli": "^2.26.0",
"@typescript-eslint/eslint-plugin": "latest",
"@typescript-eslint/parser": "^5.59.0",
"dotenv-cli": "^7.2.1",
"eslint": "^8.38.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-turbo": "latest",
"prettier": "latest",
"tsc-watch": "^6.0.0",
"turbo": "latest",
Expand All @@ -34,7 +41,6 @@
"vitest": "^0.32.0"
},
"workspaces": [
"apps/*",
"packages/*"
],
"packageManager": "pnpm@8.6.5"
Expand Down
3 changes: 1 addition & 2 deletions packages/dotperms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"scripts": {
"lint": "eslint . --fix",
"build": "unbuild",
"clean": "rimraf dist",
"test": "vitest run"
"clean": "rimraf dist"
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
Expand Down
3 changes: 1 addition & 2 deletions packages/experiments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"scripts": {
"lint": "eslint . --fix",
"build": "unbuild",
"clean": "rimraf dist",
"test": "vitest run"
"clean": "rimraf dist"
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
Expand Down
8 changes: 4 additions & 4 deletions packages/kiai.js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

### Patch Changes

- d7935bc: Switched to unbuild for compiling
- d7935bc: Switched to unbuild for compiling

## 0.1.2

### Patch Changes

- 85d2abd: Add documentation and rename getRank to getData
- 85d2abd: Add documentation and rename getRank to getData

## 0.1.1

### Patch Changes

- be68093: readme.md adjustments
- be68093: readme.md adjustments

## 0.1.0

### Minor Changes

- 33fa1ee: Initial implementation of kiai.js
- 33fa1ee: Initial implementation of kiai.js
21 changes: 21 additions & 0 deletions packages/kiai.js/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Buape Studios

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 2 additions & 4 deletions packages/kiai.js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

This package is the official Javascript wrapper for the public API of [Kiai](https://kiaibot.com).

Note: Kiai is still in beta and not yet released. If you want to join the beta, check us out at https://go.kiai.wtf/discord

## Installation

```bash
Expand All @@ -13,7 +11,7 @@ npm install kiai.js
## Usage

```js
import { KiaiClient } from "@buape/experiments"
import { KiaiClient } from "kiai.js"
const client = new KiaiClient("APIKEY")

client.getData("USERID", "GUILDID") // Returns a levelData object
Expand All @@ -22,4 +20,4 @@ client.addXp("USERID", "GUILDID", 100) // Returns a levelData object
client.setXp("USERID", "GUILDID", 100) // Returns a levelData object
```

Full documentation can be found at https://kiai.js.org/modules
Full documentation can be found at https://utilities.buape.com
12 changes: 6 additions & 6 deletions packages/kiai.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
"name": "kiai.js",
"description": "The official Javascript wrapper for Kiai",
"type": "module",
"version": "0.1.3",
"version": "1.0.0",
"author": {
"name": "Shadow",
"email": "shadow@buape.com"
},
"scripts": {
"lint": "eslint . --fix",
"build": "unbuild",
"clean": "rimraf dist",
"test": "vitest run"
"clean": "rimraf dist"
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
Expand All @@ -35,15 +34,16 @@
"@types/ms": "^0.7.31"
},
"files": [
"dist"
"dist",
"LICENSE"
],
"engines": {
"node": ">=16.17.1"
},
"dependencies": {
"@buape/kiai-api-types": "^0.1.0",
"@buape/kiai-api-types": "^1.1.0",
"ms": "^2.1.3",
"node-fetch": "^3.3.0"
"node-fetch": "^3.3.1"
},
"keywords": [
"kiai",
Expand Down
96 changes: 40 additions & 56 deletions packages/kiai.js/src/KiaiClient.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,49 @@
import { LevelData, Message } from "@buape/kiai-api-types"
import { Message, RateLimitError, VirtualMessage } from "@buape/kiai-api-types"
import { RequestHandler } from "./RequestHandler"
import * as handlers from "./handlers"

export class KiaiClient {
apiKey: string
baseURL: string
debug: boolean
apiKey: string
baseURL: string
version: `v${string}`
debug: boolean
_requestHandler: RequestHandler

private _requestHandler: RequestHandler
blacklist: handlers.Blacklist
leveling: handlers.Leveling
multipliers: handlers.Multipliers
rewards: handlers.Rewards
settings: handlers.Settings

/**
* Create a new KiaiClient
* @param apiKey The API key to use
* @param options The options to use
* @param options.baseURL The base URL to use
* @param options.debug Whether to enable debug mode
* @constructor
*/
constructor(apiKey: string, options?: { baseURL?: string; debug?: boolean }) {
this.apiKey = apiKey
this.baseURL = options?.baseURL || "https://beta.kiaibot.com/api/v1" //TODO: Remove beta once the API is out of beta
this.debug = options?.debug || false
this._requestHandler = new RequestHandler(this)
}
/**
* Create a new KiaiClient
* @param apiKey The API key to use
* @param options The options to use
* @param options.baseURL The base URL to use
* @param options.debug Whether to enable debug mode
* @constructor
*/
constructor(apiKey: string, options?: { baseURL?: string; version: `v${number}`; debug?: boolean }) {
this.apiKey = apiKey
this.version = options?.version || "v1"
this.baseURL = options?.baseURL || `https://api.kiaibot.com/${this.version}`
this.debug = options?.debug || false
this._requestHandler = new RequestHandler(this.baseURL, this.apiKey, this.debug)

/**
* Get the current status of the API
* @returns {Promise<Message>}
*/
public getStatus = async (): Promise<Message> => {
return (await this._requestHandler.request("/status", {}, "GET", {})) as Message
}
this.blacklist = new handlers.Blacklist(this._requestHandler)
this.leveling = new handlers.Leveling(this._requestHandler)
this.multipliers = new handlers.Multipliers(this._requestHandler)
this.rewards = new handlers.Rewards(this._requestHandler)
this.settings = new handlers.Settings(this._requestHandler)
}

/**
* Get the current leveling data of a user
* @param userId The Discord ID of the user
* @param guildId The Discord ID of the guild
* @returns {Promise<LevelData>}
*/
public getData = async (userId: string, guildId: string): Promise<LevelData> => {
return (await this._requestHandler.request(`/guild/${guildId}/rank/${userId}`, {}, "GET", {})) as LevelData
}
public async getRatelimit() {
const res = await this._requestHandler.request("/ratelimit", "GET", {}, {}, true)
return res as RateLimitError
}

/**
* Add XP to a user
* @param userId The Discord ID of the user
* @param guildId The Discord ID of the guild
* @param xp The amount of XP to add (set to negative to remove XP)
* @returns {Promise<LevelData>}
*/
public addXp = async (userId: string, guildId: string, xp: number): Promise<LevelData> => {
return (await this._requestHandler.request(`/guild/${guildId}/editXp/${userId}`, {}, "POST", { xp })) as LevelData
}

/**
* Set the XP of a user
* @param userId The Discord ID of the user
* @param guildId The Discord ID of the guild
* @param xp The amount of XP to set
* @returns {Promise<LevelData>}
*/
public setXp = async (userId: string, guildId: string, xp: number): Promise<LevelData> => {
return (await this._requestHandler.request(`/guild/${guildId}/editXp/${userId}`, {}, "PUT", { xp })) as LevelData
}
public async createVirtualMessage(guildId: string, message: VirtualMessage) {
const result = (await this._requestHandler.request(`/guilds/${guildId}/virtual-messages`, "POST", {}, message)) as Message
return result
}
}
Loading