diff --git a/CHANGELOG.md b/CHANGELOG.md
index c196cd8..22a42e9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,14 @@
### April
+#### 2.0.0
+- Source Code Refactoring
+- Implemented Callbacks Endpoint
+- Updated README
+ - Updated style
+ - Updated `TypeScript Specials` article
+ - Updated examples
+
#### 1.1.0
- Source Code Refactoring
- Dependencies Switch
diff --git a/README.md b/README.md
index 14a3bfe..55d6a0a 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,16 @@
+
+
+
# BPAPI
[![NPM: Version](https://img.shields.io/npm/v/@nightnutsky/bpapi?logo=npm&style=for-the-badge)](https://www.npmjs.com/package/@nightnutsky/bpapi)
[![GitHub: Stars](https://img.shields.io/github/stars/NightNutSky/bpapi?logo=github&style=for-the-badge)](https://github.com/NightNutSky/bpapi/stargazers)
[![GitHub: Source Code](https://img.shields.io/badge/Source%20Code-GitHub-green?logo=github&style=for-the-badge)](https://github.com/NightNutSky/bpapi)
-BPAPI allows you to retrieve and work with information from [BDFD](https://botdesignerdiscord.com) [Public API](https://nilpointer-software.github.io/bdfd-wiki/nightly/resources/api.html) more easier.
+BPAPI allows you to work with [BDFD](https://botdesignerdiscord.com) [Public API](https://nilpointer-software.github.io/bdfd-wiki/nightly/resources/api.html) more easier and pretty!
+
+
+
# Install
```sh
@@ -22,7 +28,7 @@ To get started, you should import/require BPAPI:
```js
const { functionInfo } = require("@nightnutsky/bpapi");
```
-- TypeScript
+- TypeScript (Recommended to use)
- Import all functions:
```ts
import * as bpapi from "@nightnutsky/bpapi";
@@ -31,191 +37,96 @@ To get started, you should import/require BPAPI:
```ts
import { functionInfo } from "@nightnutsky/bpapi";
```
-## Code Examples
-
-### functionInfo()
-```js
-/**
- *
- * @param functionTag A tag (i.e `$addButton[]`, `$nomention`) of the function. Supports non-completed tags (i.e `$addBu` will be represented as `$addButton[]`)
- * @returns A promise containing information about the specified function. If could't find the function, `undefined` is returned.
- */
+## Some Code Examples
+
+### BDFD Functions
+
+```ts
functionInfo('$replaceT').then(info => {
if (info) {
- const tag = info.tag,
- description = info.description,
- intents = info.intents;
-
- console.log(`${tag}:\nDescription: ${description}\nIntents: ${intents}`);
+ const {
+ description,
+ intents,
+ tag
+ } = info;
+ someFunction(RESPONSE.Success, `The function with the \`${tag}\` tag has the following description: \`${description}\` and requires ${intents} intents.`);
} else {
- console.log('Could not find the specified function!')
+ someFunction(RESPONSE.Fail, 'Could not find the function!');
}
});
```
-### functionList()
-```js
-/**
- *
- * @returns A promise containing an array of functions with their information
- */
-functionList().then(list => {
- console.log('Functions That Require Intents:');
- for (const functionInfo of list) {
- if (functionInfo.intents != 'None') {
- const tag = functionInfo.tag,
- intents = functionInfo.intents;
-
- console.log(`${tag}: ${intents} Intent`);
- }
- }
-});
-```
+### BDFD Callbacks
-### functionTagList()
-```js
-/**
- *
- * @returns A promise containing an array of function tags
- */
-functionTagList().then(tagList => {
- console.log('Functions That Start With "n":');
- for (const functionTag of tagList) {
- if (functionTag.includes('$n')) {
- console.log(functionTag);
- }
+```ts
+callbackInfo('$onJ').then(info => {
+ if (info) {
+ const {
+ name
+ } = info;
+ const premium = info.premium ? 'requires' : "doesn't require";
+ someFunction(RESPONSE.Success, `The callback with the \`${name}\` name ${premium} premium hosting time.`);
+ } else {
+ someFunction(RESPONSE.Fail, 'Could not find the callback!');
}
});
```
+
## TypeScript Specials
If you ever worked with TypeScript, then you know that you can (and sometimes must) assign types for your consts, etc.
-If you want to work with plain BDFD Public API, for example, do request to the `api/function_list` endpoint yourself, BPAPI can help you using one of its type - `PublicAPIResponse`.\
-Import this type and assign it to the request's response.
-
-> Original BDFD Public API's response is a bit different and contains unused or deprecated (and now unused) properties. Unlike BDFD Public API, BPAPI only shows actual and a bit modified properties for your comfort.
-
-| Showcase |
-| :------: |
-| ![Showcase](https://user-images.githubusercontent.com/70456337/230720560-c425f057-d09c-4e91-8f68-8f9312d07455.png) |
-| ![Showcase](https://user-images.githubusercontent.com/70456337/230720600-f89d6185-ae72-47c8-ab37-cee6f1d6a9e5.png) |
-
-
-## Raw Returns
-
-Expand
-
-### functionInfo()
-```json
-{
- "tag": "$replaceText[Text;Sample;New;(Amount)]",
- "description": "Replaces 'sample' from 'text' to 'new' 'how many' times. Set 'how many' to -1 to replace everything",
- "arguments": [
- {
- "name": "Text",
- "type": "String",
- "required": true,
- "empty": true
- },
- {
- "name": "Sample",
- "type": "String",
- "required": true,
- "empty": true
- },
- {
- "name": "New",
- "type": "String",
- "required": true,
- "empty": true
- },
- {
- "name": "Amount",
- "type": "Integer",
- "required": false
- }
- ],
- "intents": "None",
- "premium": false
-}
-```
+### Types For BDFD Public API
+If you want to work with plain BDFD Public API, for example, do request to endpoints yourself, BPAPI can help you using types.
-### functionList()
-```json
-[
- ...,
- {
- "tag": "$userJoinedDiscord[User ID;(Format)]",
- "description": "Returns date when given user joined discord. You can also give your own date format",
- "arguments": [
- {
- "name": "User ID",
- "type": "Snowflake",
- "required": true
- },
- {
- "name": "Format",
- "description": "Uses GoLang date format",
- "type": "String",
- "required": false
- }
- ],
- "intents": "None",
- "premium": false
- },
- {
- "tag": "$userJoined[User ID;(Format)]",
- "description": "Returns date when given user joined the guild. You can also give your own date format",
- "arguments": [
- {
- "name": "User ID",
- "type": "Snowflake",
- "required": true
- },
- {
- "name": "Format",
- "description": "Uses GoLang date format",
- "type": "String",
- "required": false
- }
- ],
- "intents": "Members",
- "premium": false
- },
- ...
-]
-```
+Currently, BPAPI has types for request's responses - `FunctionsResponse` and `CallbacksResponse`.
+
+#### `FunctionsResponse`
+
+![FunctionsResponse](https://user-images.githubusercontent.com/70456337/231560564-e590a2e4-5b40-4ee3-a39d-f41362c98e1f.png)
+
+#### `CallbacksResponse`
-### functionTagList()
-```json
-[
- ...,
- "$userInfo[]",
- "$userJoinedDiscord[]",
- "$userJoined[]",
- "$userLeaderboard[]",
- "$userPerms[]",
- "$userReacted[]",
- "$userRoles[]",
- "$userServerAvatar[]",
- "$username",
- "$username[]",
- "$varExistError[]",
- "$varExists[]",
- "$var[]",
- "$variablesCount[]",
- "$webhookAvatarURL[]",
- "$webhookColor[]",
- "$webhookContent[]",
- "$webhookCreate[]",
- "$webhookDelete[]",
- "$webhookDescription[]",
- "$webhookFooter[]",
- "$webhookSend[]",
- "$webhookTitle[]",
- "$webhookUsername[]",
- "$year"
-]
+![CallbacksResponse](https://user-images.githubusercontent.com/70456337/231560588-3c6fd4c7-e0da-4818-89c1-d99b5b8d4a2b.png)
+
+### Types For Enums
+
+As you should know, some BDScript functions have arguments and these arguments have enums.\
+BPAPI will help to work with them as well. While retrieving the argument's enums, you can assign one of the [types](#types) to it.
+
+```ts
+functionInfo('$addB').then(info => {
+ if (info && info.args) {
+ for (const arg of info.args) {
+ if (arg.enumData) {
+ const enums: AddButtonEnums = arg.enumData;
+ // ^ ["primary", "secondary", "success", "danger", "link"]
+ }
+ }
+ }
+});
```
-
\ No newline at end of file
+#### Types
+| Name | Example Function |
+| :------------------------: | :-------------------------: |
+| AddButtonEnums | `$addButton[]` |
+| ModalEnums | `$addTextInput[]` |
+| CategoryEnums | `$categoryChannels[]` |
+| ChannelEnums | `$createChannel[]` |
+| EditButtonEnums | `$editButton[]` |
+| ErrorEnums | `$error[]` |
+| CooldownEnums | `$getCooldown[]` |
+| EmbedDataEnums | `$getEmbedData[]` |
+| InviteInfoEnums | `$getInviteInfo[]` |
+| LeaderboardTypeEnums | `$getLeaderboardValue[]`* |
+| SortEnums | `$getLeaderboardValue[]`** |
+| LeaderboardReturnTypeEnums | `$getLeaderboardValue[]`*** |
+| MessageDataEnums | `$getMessage[]` |
+| TimestampEnums | `$getTimestamp[]` |
+| MembersCountEnums | `$membersCount[]` |
+| UrlEnums | `$url[]` |
+| VariablesCountEnums | `$variablesCount[]` |
+
+> \* - The `Variable type` argument of the function.\
+> \*\* - The `Sort` argument of the function.\
+> \*\*\* - The `Return type` argument of the function.
diff --git a/package-lock.json b/package-lock.json
new file mode 100644
index 0000000..d987a7a
--- /dev/null
+++ b/package-lock.json
@@ -0,0 +1,61 @@
+{
+ "name": "@nightnutsky/bpapi",
+ "version": "1.1.0",
+ "lockfileVersion": 2,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "@nightnutsky/bpapi",
+ "version": "1.1.0",
+ "license": "MIT",
+ "dependencies": {
+ "centra": "^2.6.0"
+ },
+ "devDependencies": {
+ "@types/centra": "^2.2.0"
+ }
+ },
+ "node_modules/@types/centra": {
+ "version": "2.2.0",
+ "resolved": "https://registry.npmjs.org/@types/centra/-/centra-2.2.0.tgz",
+ "integrity": "sha512-TUpM1QoIgXa2VL1LnWbTgde39+rRnsOtvb0v8ZrX8t51g8K1Wwu4HAEXcBg5a56GV5Vm/KazyE5+g4AW8YbKNg==",
+ "dev": true,
+ "dependencies": {
+ "@types/node": "*"
+ }
+ },
+ "node_modules/@types/node": {
+ "version": "18.15.11",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.11.tgz",
+ "integrity": "sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==",
+ "dev": true
+ },
+ "node_modules/centra": {
+ "version": "2.6.0",
+ "resolved": "https://registry.npmjs.org/centra/-/centra-2.6.0.tgz",
+ "integrity": "sha512-dgh+YleemrT8u85QL11Z6tYhegAs3MMxsaWAq/oXeAmYJ7VxL3SI9TZtnfaEvNDMAPolj25FXIb3S+HCI4wQaQ=="
+ }
+ },
+ "dependencies": {
+ "@types/centra": {
+ "version": "2.2.0",
+ "resolved": "https://registry.npmjs.org/@types/centra/-/centra-2.2.0.tgz",
+ "integrity": "sha512-TUpM1QoIgXa2VL1LnWbTgde39+rRnsOtvb0v8ZrX8t51g8K1Wwu4HAEXcBg5a56GV5Vm/KazyE5+g4AW8YbKNg==",
+ "dev": true,
+ "requires": {
+ "@types/node": "*"
+ }
+ },
+ "@types/node": {
+ "version": "18.15.11",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.11.tgz",
+ "integrity": "sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==",
+ "dev": true
+ },
+ "centra": {
+ "version": "2.6.0",
+ "resolved": "https://registry.npmjs.org/centra/-/centra-2.6.0.tgz",
+ "integrity": "sha512-dgh+YleemrT8u85QL11Z6tYhegAs3MMxsaWAq/oXeAmYJ7VxL3SI9TZtnfaEvNDMAPolj25FXIb3S+HCI4wQaQ=="
+ }
+ }
+}
diff --git a/package.json b/package.json
index 1de1125..63ca849 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "@nightnutsky/bpapi",
- "version": "1.1.0",
- "description": "BPAPI allows you to retrieve and work with information from BDFD Public API more easier",
+ "version": "2.0.0",
+ "description": "BPAPI allows you to work with BDFD Public API more easier and pretty!",
"author": "NightNutSky",
"main": "dist/index.js",
"types": "types/types.d.ts",
diff --git a/src/consts.ts b/src/consts.ts
index 90fa3a8..2658287 100644
--- a/src/consts.ts
+++ b/src/consts.ts
@@ -10,12 +10,30 @@ export const RAW_INTENTS = Object.freeze({
None: 0
});
export const ENDPOINT = Object.freeze({
- Function: 'function',
- FunctionList: 'functionList',
- FunctionTagList: 'functionTagList'
+ Functions: {
+ Info: 'function' as 'function',
+ List: 'functionList' as 'functionList',
+ TagList: 'functionTagList' as 'functionTagList'
+ },
+ Callbacks: {
+ Info: 'callback' as 'callback',
+ List: 'callbackList' as 'callbackList',
+ TagList: 'callbackTagList' as 'callbackTagList'
+ }
});
export const ENDPOINT_PATH = Object.freeze({
- Function: 'function/',
- FunctionList: 'function_list',
- FunctionTagList: 'function_tag_list'
+ Functions: {
+ Info: 'function/',
+ List: 'function_list',
+ TagList: 'function_tag_list'
+ },
+ Callbacks: {
+ Info: 'callback/',
+ List: 'callback_list',
+ TagList: 'callback_tag_list'
+ }
+});
+export const REQUEST_TYPE = Object.freeze({
+ Functions: 'functions',
+ Callbacks: 'callbacks'
});
\ No newline at end of file
diff --git a/src/index.ts b/src/index.ts
index 8c58291..8cae5e8 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,57 +1,104 @@
import * as centra from "centra";
import type {
Endpoint,
- FindFunction,
FunctionInfo,
- FunctionIntents,
- FunctionTag,
+ Intents,
GetFunctionInfo,
GetFunctionList,
GetFunctionTagList,
- PublicAPIRequest,
- PublicAPIResponse
+ FunctionsResponse,
+ FindTag,
+ RequestType,
+ CallbacksResponse,
+ GetCallbackTagList,
+ FunctionArguments,
+ CallbackArguments,
+ RawIntents,
+ CallbackInfo,
+ GetCallbackList,
+ GetCallbackInfo,
+ PublicAPIRequest
} from "../types/types";
import {
API,
ENDPOINT,
ENDPOINT_PATH,
INTENTS,
- RAW_INTENTS
+ RAW_INTENTS,
+ REQUEST_TYPE
} from "./consts";
-async function request(endpoint: Endpoint, functionTag?: FunctionTag): PublicAPIRequest {
+
+
+async function request(requestType: RequestType, endpoint: Endpoint, tag?: string): PublicAPIRequest {
let req: centra.Response;
- let data: PublicAPIResponse | PublicAPIResponse[] | string[];
- switch (endpoint) {
- case ENDPOINT.Function:
- const tag = await findFunction(functionTag!);
- if (tag) {
- req = await centra(API + ENDPOINT_PATH.Function + tag).send();
- data = await req.json();
- return data;
- } else {
- return;
+ let data;
+ switch (requestType) {
+ case REQUEST_TYPE.Functions:
+ switch (endpoint) {
+ case ENDPOINT.Functions.Info:
+ const functionTag = await findTag(requestType, tag!);
+ if (functionTag) {
+ req = await centra(API + ENDPOINT_PATH.Functions.Info + functionTag).send();
+ data = await req.json();
+ } else {
+ data = undefined;
+ }
+ break;
+ case ENDPOINT.Functions.List:
+ req = await centra(API + ENDPOINT_PATH.Functions.List).send();
+ data = await req.json();
+ break;
+ case ENDPOINT.Functions.TagList:
+ req = await centra(API + ENDPOINT_PATH.Functions.TagList).send();
+ data = await req.json();
+ break;
+ }
+ break;
+ case REQUEST_TYPE.Callbacks:
+ switch (endpoint) {
+ case ENDPOINT.Callbacks.Info:
+ const callbackTag = await findTag(requestType, tag!);
+ if (callbackTag) {
+ req = await centra(API + ENDPOINT_PATH.Callbacks.Info + callbackTag).send();
+ data = await req.json();
+ } else {
+ data = undefined;
+ }
+ break;
+ case ENDPOINT.Callbacks.List:
+ req = await centra(API + ENDPOINT_PATH.Callbacks.List).send();
+ data = await req.json();
+ break;
+ case ENDPOINT.Callbacks.TagList:
+ req = await centra(API + ENDPOINT_PATH.Callbacks.TagList).send();
+ data = await req.json();
+ break;
}
- case ENDPOINT.FunctionList:
- req = await centra(API + ENDPOINT_PATH.FunctionList).send();
- data = await req.json();
- return data;
- case ENDPOINT.FunctionTagList:
- req = await centra(API + ENDPOINT_PATH.FunctionTagList).send();
- data = await req.json();
- return data;
+ break;
}
+
+ return data;
}
-async function findFunction(functionTag: FunctionTag): FindFunction {
- const tags = await functionTagList();
- for (const tag of tags) {
- if (tag.includes(functionTag)) return tag;
+async function findTag(requestType: RequestType, tag: string): FindTag {
+ let tags: string[];
+ switch (requestType) {
+ case REQUEST_TYPE.Functions:
+ tags = await functionTagList();
+ break;
+ case REQUEST_TYPE.Callbacks:
+ tags = await callbackTagList();
+ break;
+ }
+
+ for (const t of tags) {
+ if (t.includes(tag)) return t;
}
}
function intentsSwitcher(functionIntents: number) {
- let intents: FunctionIntents = INTENTS.None;
+ let intents: Intents = INTENTS.None;
switch (functionIntents) {
case RAW_INTENTS.Presence:
intents = INTENTS.Presence;
@@ -63,14 +110,42 @@ function intentsSwitcher(functionIntents: number) {
return intents;
}
-function buildFunctionInfo(publicAPIResponse: PublicAPIResponse): FunctionInfo {
- return {
- tag: publicAPIResponse.tag,
- description: publicAPIResponse.shortDescription,
- arguments: publicAPIResponse.arguments,
- intents: intentsSwitcher(publicAPIResponse.intents),
- premium: publicAPIResponse.premium
- };
+function buildInfo(requestType: RequestType, publicAPIResponse: FunctionsResponse | CallbacksResponse): FunctionInfo | CallbackInfo {
+ let intents: RawIntents;
+ let args: FunctionArguments[] | CallbackArguments[];
+
+ switch (requestType) {
+ case REQUEST_TYPE.Functions:
+ const {
+ tag,
+ shortDescription,
+ premium
+ } = publicAPIResponse as FunctionsResponse;
+ intents = publicAPIResponse.intents;
+ args = publicAPIResponse.arguments;
+ return {
+ tag: tag,
+ description: shortDescription,
+ args: args,
+ intents: intentsSwitcher(intents),
+ premium: premium
+ };
+ case REQUEST_TYPE.Callbacks:
+ const {
+ name,
+ description,
+ is_premium
+ } = publicAPIResponse as CallbacksResponse;
+ intents = publicAPIResponse.intents;
+ args = publicAPIResponse.arguments;
+ return {
+ name: name,
+ description: description,
+ args: args,
+ intents: intentsSwitcher(intents),
+ premium: is_premium
+ };
+ }
}
/**
@@ -78,10 +153,10 @@ function buildFunctionInfo(publicAPIResponse: PublicAPIResponse): FunctionInfo {
* @param functionTag A tag (i.e `$addButton[]`, `$nomention`) of the function. Supports non-completed tags (i.e `$addBu` will be represented as `$addButton[]`)
* @returns A promise containing information about the specified function. If function wasn't found, returns `undefined`.
*/
-export async function functionInfo(functionTag: FunctionTag): GetFunctionInfo {
- const data = await request(ENDPOINT.Function, functionTag) as PublicAPIResponse | undefined;
+export async function functionInfo(functionTag: string): GetFunctionInfo {
+ const data = await request(REQUEST_TYPE.Functions, ENDPOINT.Functions.Info, functionTag);
if (data) {
- return buildFunctionInfo(data);
+ return buildInfo(REQUEST_TYPE.Functions, data);
} else {
return;
}
@@ -91,11 +166,11 @@ export async function functionInfo(functionTag: FunctionTag): GetFunctionInfo {
* @returns A promise containing an array of functions with their information
*/
export async function functionList(): GetFunctionList {
- const data = await request(ENDPOINT.FunctionList) as PublicAPIResponse[];
+ const data = await request(REQUEST_TYPE.Functions, ENDPOINT.Functions.List);
const res: FunctionInfo[] = [];
for (const functionInfo of data) {
- res.push(buildFunctionInfo(functionInfo));
+ res.push( buildInfo(REQUEST_TYPE.Functions, functionInfo));
}
return res;
}
@@ -103,4 +178,36 @@ export async function functionList(): GetFunctionList {
*
* @returns A promise containing an array of function tags
*/
-export const functionTagList = async (): GetFunctionTagList => await request(ENDPOINT.FunctionTagList) as string[];
+export const functionTagList = async (): GetFunctionTagList => await request(REQUEST_TYPE.Functions, ENDPOINT.Functions.TagList);
+
+/**
+ *
+ * @param callbackTag A tag (i.e `$onJoined[]`, `$onLeave[]`) of the callback. Supports non-completed tags (i.e `$onJo` will be represented as `$onJoined[]`)
+ * @returns A promise containing information about the specified callback. If callback wasn't found, returns `undefined`.
+ */
+export async function callbackInfo(callbackTag: string): GetCallbackInfo {
+ const data = await request(REQUEST_TYPE.Callbacks, ENDPOINT.Callbacks.Info, callbackTag);
+ if (data) {
+ return buildInfo(REQUEST_TYPE.Callbacks, data);
+ } else {
+ return;
+ }
+}
+/**
+ *
+ * @returns A promise containing an array of callbacks with their information
+ */
+export async function callbackList(): GetCallbackList {
+ const data = await request(REQUEST_TYPE.Callbacks, ENDPOINT.Callbacks.List);
+ const res: CallbackInfo[] = [];
+
+ for (const callbackInfo of data) {
+ res.push( buildInfo(REQUEST_TYPE.Callbacks, callbackInfo));
+ }
+ return res;
+}
+/**
+ *
+ * @returns A promise containing an array of callback tags
+ */
+export const callbackTagList = async (): GetCallbackTagList => await request(REQUEST_TYPE.Callbacks, ENDPOINT.Callbacks.TagList);
diff --git a/tsconfig.json b/tsconfig.json
index 3f50c02..6ce445e 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -5,6 +5,7 @@
"target": "ESNext",
"strict": true,
"outDir": "dist",
- "rootDir": "src"
- }
+ "rootDir": "src"
+ },
+ "exclude": ["ignore"]
}
\ No newline at end of file
diff --git a/types/types.d.ts b/types/types.d.ts
index 91c87e2..e49d75f 100644
--- a/types/types.d.ts
+++ b/types/types.d.ts
@@ -1,36 +1,56 @@
-export type Endpoint = 'function' | 'functionList' | 'functionTagList';
+type Endpoint = 'function' | 'functionList' | 'functionTagList' | 'callback' | 'callbackList' | 'callbackTagList';
+type RequestType = 'functions' | 'callbacks';
-export type FunctionTag = string;
-export type FunctionDescription = string;
-export type FunctionIntents = 'None' | 'Members' | 'Presence';
-export type FunctionPremium = boolean;
+export type Intents = 'None' | 'Members' | 'Presence';
+export type RawIntents = 0 | 2 | 256;
export interface FunctionInfo {
/**
* The tag of the function
*/
- tag: FunctionTag;
+ tag: string;
/**
* The description of the function
*/
- description: FunctionDescription;
+ description: string;
/**
* The arguments of the function
*/
- arguments: FunctionArguments | null;
+ args: FunctionArguments[] | null;
/**
* The intents of the function
*/
- intents: FunctionIntents;
+ intents: Intents;
/**
* Whether the function requires premium hosting time
*/
- premium: FunctionPremium;
+ premium: boolean;
}
-export type ArgumentName = string;
-export type ArgumentDescription = string;
-export type ArgumentType =
+export interface CallbackInfo {
+ /**
+ * The name (tag-name) of the callback
+ */
+ name: string;
+ /**
+ * The description of the callback
+ */
+ description: string;
+ /**
+ * The arguments of the callback
+ */
+ args: CallbackArguments[] | [];
+ /**
+ * The intents of the callback
+ */
+ intents: Intents;
+ /**
+ * Whether the callback requires premium hosting time
+ */
+ premium: boolean;
+}
+
+export type FunctionsArgumentType =
'Bool' |
'URL | String' |
'String' |
@@ -55,102 +75,124 @@ export type ArgumentType =
'HowMany | String' |
'Float | Integer' |
'Float';
-export type ArgumentRequirement = boolean;
-export type ArgumentRepeatability = boolean;
-export type ArgumentEmptiness = boolean;
-export type ArgumentEnumData = string[];
+export type CallbacksArgumentType =
+ 'String' |
+ 'Snowflake';
+
+export type AddButtonEnums = readonly ['primary', 'secondary', 'success', 'danger', 'link'];
+export type ModalEnums = readonly ['short', 'paragraph'];
+export type CategoryEnums = readonly ['count', 'name', 'id', 'mention'];
+export type ChannelEnums = readonly ['text', 'voice', 'category', 'stage', 'forum'];
+export type EditButtonEnums = readonly ['primary', 'secondary', 'success', 'danger', 'link'];
+export type ErrorEnums = readonly ['row', 'column', 'command', 'source', 'message'];
+export type CooldownEnums = readonly ['normal', 'global', 'server'];
+export type EmbedDataEnums = readonly ['description', 'footer', 'color', 'image', 'timestamp', 'title'];
+export type InviteInfoEnums = readonly ['uses', 'channel', 'creationDate', 'inviter', 'isTemporary'];
+export type LeaderboardTypeEnums = readonly ['user', 'server', 'globalUser'];
+export type SortEnums = readonly ['desc', 'asc'];
+export type LeaderboardReturnTypeEnums = readonly ['id', 'value'];
+export type MessageDataEnums = readonly ['content', 'authorID', 'username', 'avatar'];
+export type TimestampEnums = readonly ['ns', 'ms', 's'];
+export type MembersCountEnums = readonly ['invisible', 'dnd', 'online', 'offline', 'idle'];
+export type UrlEnums = readonly ['decode', 'encode'];
+export type VariablesCountEnums = readonly ['channel', 'user', 'server', 'globaluser'];
export interface FunctionArguments {
/**
* The name of the argument
*/
- name: ArgumentName;
+ name: string;
/**
* The description of the argument
*/
- description?: ArgumentDescription;
+ description?: string;
/**
* The type of the argument
*/
- type: ArgumentType;
+ type: FunctionsArgumentType;
/**
* Whether the argument is required
*/
- required: ArgumentRequirement;
+ required: boolean;
/**
* Whether the argument can be repeated
*/
- repeatable?: ArgumentRepeatability;
+ repeatable?: boolean;
/**
* Whether the argument can be empty
*/
- empty?: ArgumentEmptiness;
- /**
- * Possible Enums:
- * 1. `success`, `danger`, `link`, `primary`, `secondary`
- * 2. `short`, `paragraph`
- * 3. `name`, `id`, `mention`, `count`
- * 4. `text`, `voice`, `category`, `stage`, `forum`
- * 5. `primary`, `secondary`, `success`, `danger`, `link`
- * 6. `row`, `column`, `command`, `source`, `message`
- * 7. `normal`, `global`, `server`
- * 8. `title`, `description`, `footer`, `color`, `image`, `timestamp`
- * 9. `inviter`, `isTemporary`, `uses`, `channel`, `creationDate`
- * 10. `user`, `server`, `globalUser`
- * 11. `desc`, `asc`
- * 12. `value`, `id`
- * 13. `content`, `authorID`, `username`, `avatar`
- * 14. `ns`, `ms`, `s`
- * 15. `desc`, `asc`
- * 16. `offline`, `idle`, `invisible`, `dnd`, `online`
- * 17. `desc`, `asc`
- * 18. `encode`, `decode`
- * 19. `desc`, `asc`
- * 20. `user`, `server`, `globaluser`, `channel`
- */
- enumData?: ArgumentEnumData;
+ empty?: boolean;
+ /**
+ * The Enums of the argument. If it's TypeScript, the special types can be used
+ * @example
+ * ```ts
+ * import {
+ * functionInfo,
+ * type AddButtonEnums
+ * } from "@nightnutsky/bpapi";
+ *
+ * functionInfo('$addB').then(info => {
+ * if (info && info.args) {
+ * for (const arg of info.args) {
+ * if (arg.enumData) {
+ * const enums: AddButtonEnums = arg.enumData;
+ * // ^ ["primary", "secondary", "success", "danger", "link"]
+ * }
+ * }
+ * }
+ * });
+ *```
+ */
+ enumData?: any;
}
-export type GetFunctionInfo = Promise;
-export type GetFunctionList = Promise;
-export type GetFunctionTagList = Promise;
+export interface CallbackArguments {
+ /**
+ * The name of the argument
+ */
+ name: string;
+ /**
+ * The description of the argument
+ */
+ description: string;
+ /**
+ * The type of the argument
+ */
+ type: CallbacksArgumentType;
+ /**
+ * Whether the argument is required
+ */
+ required: boolean;
+}
-/**
- *
- * @param functionTag A tag (i.e `$addButton[]`, `$nomention`) of the function. Supports non-completed tags (i.e `$addBu` will be represented as `$addButton[]`)
- * @returns A promise containing information about the specified function. If could't find the function, `undefined` is returned.
- */
-export declare function functionInfo(functionTag: FunctionTag): GetFunctionInfo;
-/**
- *
- * @returns A promise containing an array of functions with their information
- */
-export declare function functionList(): GetFunctionList;
-/**
- *
- * @returns A promise containing an array of function tags
- */
-export declare const functionTagList: () => GetFunctionTagList;
+type GetFunctionInfo = Promise;
+type GetFunctionList = Promise;
+type GetFunctionTagList = Promise;
-export interface PublicAPIResponse {
+
+type GetCallbackInfo = Promise;
+type GetCallbackList = Promise;
+type GetCallbackTagList = Promise;
+
+export interface FunctionsResponse {
/**
* The tag of the function
*/
- tag: FunctionTag;
+ tag: string;
/**
* The description of the function
*/
- shortDescription: FunctionDescription;
+ shortDescription: string;
/**
* The description of the function?
*
* *It was never used*
*/
- longDescription: FunctionArguments;
+ longDescription: string;
/**
* The arguments of the function
*/
- arguments: FunctionArguments | null;
+ arguments: FunctionArguments[] | null;
/**
* The intents of the function
*
@@ -158,9 +200,9 @@ export interface PublicAPIResponse {
*
* 2 = Members
*
- * 256 = Intents
+ * 256 = Presence
*/
- intents: 0 | 2 | 256;
+ intents: RawIntents;
/**
* Whether the function requires premium hosting time
*/
@@ -173,5 +215,73 @@ export interface PublicAPIResponse {
color: 0;
}
-export type PublicAPIRequest = Promise;
-export type FindFunction = Promise;
+export interface CallbacksResponse {
+ /**
+ * The name of the callback
+ */
+ name: string;
+ /**
+ * The description of the callback
+ */
+ description: string;
+ /**
+ * The arguments of the callback
+ */
+ arguments: CallbackArguments[] | [];
+ /**
+ * The intents of the callback
+ *
+ * 0 = None
+ *
+ * 2 = Members
+ *
+ * 256 = Presence
+ */
+ intents: RawIntents;
+ /**
+ * Whether the callback requires premium hosting time
+ */
+ is_premium: boolean;
+}
+
+/**
+ *
+ * @param functionTag A tag (i.e `$addButton[]`, `$nomention`) of the function. Supports non-completed tags (i.e `$addBu` will be represented as `$addButton[]`)
+ * @returns A promise containing information about the specified function. If could't find the function, `undefined` is returned.
+ */
+export declare function functionInfo(functionTag: string): GetFunctionInfo;
+/**
+ *
+ * @returns A promise containing an array of functions with their information
+ */
+export declare function functionList(): GetFunctionList;
+/**
+ *
+ * @returns A promise containing an array of function tags
+ */
+export declare const functionTagList: () => GetFunctionTagList;
+
+/**
+ *
+ * @param callbackTag A tag (i.e `$onJoined[]`, `$onLeave[]`) of the callback. Supports non-completed tags (i.e `$onJo` will be represented as `$onJoined[]`)
+ * @returns A promise containing information about the specified callback. If could't find the callback, `undefined` is returned.
+ */
+export declare function callbackInfo(callbackTag: string): GetCallbackInfo;
+/**
+ *
+ * @returns A promise containing an array of callback with their information
+ */
+export declare function callbackList(): GetCallbackList;
+/**
+ *
+ * @returns A promise containing an array of callback tags
+ */
+export declare const callbackTagList: () => GetCallbackTagList;
+
+type PublicAPIRequest = Promise<
+ ResponseType extends FunctionsResponse ? FunctionsResponse | undefined :
+ ResponseType extends FunctionsResponse[] ? FunctionsResponse[] :
+ ResponseType extends CallbacksResponse ? CallbacksResponse | undefined :
+ ResponseType extends CallbacksResponse[] ? CallbacksResponse[] :
+ string[]>;
+type FindTag = Promise;