Skip to content

Commit

Permalink
Setup for v1 rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilloftheshadow committed Apr 27, 2023
1 parent becc737 commit a3452c3
Show file tree
Hide file tree
Showing 22 changed files with 304 additions and 180 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/kiai_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
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
}
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Utilities

Utility packages published by Buape Studios
Utility packages published by Buape Studios
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
"docs": "typedoc"
},
"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",
"eslint": "^8.38.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-turbo": "latest",
"prettier": "latest",
"tsc-watch": "^6.0.0",
"turbo": "latest",
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
9 changes: 5 additions & 4 deletions packages/kiai.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"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"
Expand Down Expand Up @@ -35,15 +35,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.0.0",
"ms": "^2.1.3",
"node-fetch": "^3.3.0"
"node-fetch": "^3.3.1"
},
"keywords": [
"kiai",
Expand Down
83 changes: 26 additions & 57 deletions packages/kiai.js/src/KiaiClient.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,34 @@
import { LevelData, Message } from "@buape/kiai-api-types"
import { RateLimitError } from "@buape/kiai-api-types"
import { RequestHandler } from "./RequestHandler"

export class KiaiClient {
apiKey: string
baseURL: string
debug: boolean
apiKey: string
baseURL: string
debug: boolean

private _requestHandler: RequestHandler
_requestHandler: RequestHandler

/**
* 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; debug?: boolean }) {
this.apiKey = apiKey
this.baseURL = options?.baseURL || "https://api.kiaibot.com/v1"
this.debug = options?.debug || false
this._requestHandler = new RequestHandler(this)
}

/**
* Get the current status of the API
* @returns {Promise<Message>}
*/
public getStatus = async (): Promise<Message> => {
return (await this._requestHandler.request("/status", {}, "GET", {})) as Message
}
public async getRatelimit() {
const res = await this._requestHandler.request("/ratelimit", {}, "GET", {}, true)
return res as RateLimitError
}

/**
* 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
}

/**
* 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() {
return {}
}
}
Loading

0 comments on commit a3452c3

Please sign in to comment.