-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
becc737
commit a3452c3
Showing
22 changed files
with
304 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} | ||
} | ||
} |
Oops, something went wrong.