-
Notifications
You must be signed in to change notification settings - Fork 0
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
Preparation to merge initial revision of sisbasekt
#3
base: master
Are you sure you want to change the base?
Changes from 37 commits
40e39ce
d823034
099d79e
e0ab065
9919363
82c0a76
d204545
86b93d2
34a510b
91039ec
0059861
86bab14
2506190
ba3c173
a3201e4
38e234e
48fbec5
f257c3f
6a3d630
e61fa83
942a9e7
f600d0f
b32551e
aabf536
92b2067
fc33f85
2cedbb6
7966fd2
8e74767
4a332f2
cd5a2e9
51699cb
79033de
ee1f9d6
5eeaa0d
320644f
15cf55f
b2fd1ac
1243725
154b271
d1c2467
feb4b41
3cc3b7a
8b6c0b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,38 @@ | ||
# sisbase-api | ||
`Type: Subproject` | ||
Subproject of: [`SisbaseKT`](../sisbasekt.md) | ||
|
||
A collection of interfaces representing the Discord API Spec. | ||
Implemented by `Backends`. | ||
|
||
## Dependencies | ||
[types](types.md) | ||
|
||
## Project Structure | ||
`org.sisbase.sisbase-api` | ||
Base package | ||
|
||
`org.sisbase.sisbase-api.rest` | ||
High level wrapper for Discord's Rest API | ||
|
||
alikindsys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`org.sisbase.sisbase-api.gateway` | ||
High level wrapper for Discord's Gateway | ||
|
||
## Usage | ||
|
||
### Implementing a Backend | ||
Backends are the actual libraries that connect to discord. | ||
An example of a valid backend would be Discord4J. | ||
|
||
To implement a gateway backend, extend `GatewayBackend` | ||
To implement a rest backend, extend `RestBackend` | ||
To implement a backend that supports both, extend `AbstractBackend` | ||
|
||
```kt | ||
package org.siscode.sisbasekt-backends.discord4j | ||
class Discord4JBackend() : AbstractBackend { | ||
public restBackend = Discord4JRest(); | ||
public gatewaybackend = Discord4JGateway() | ||
} | ||
``` | ||
Comment on lines
+31
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code snippet is non-descriptive and only duplicates the text above it. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# sisbase-commands | ||
`Type: Subproject` | ||
Subproject of: [`SisbaseKT`](../sisbasekt.md) | ||
|
||
Command library. | ||
|
||
Implemented as an extension. Users can use `sisbase-commands` optionally for command handling, but can also use their own command handling solutions if they so desire. | ||
|
||
## Dependencies | ||
[core](core.md) | ||
|
||
## Commands | ||
Simple interactions with the user caused by a direct call to them. | ||
|
||
Has the following attributes: | ||
|
||
| Field | Type | Description | | ||
|---------------|----------|---------------------------------------------------------------------------------| | ||
| `name` | String | Name of the command | | ||
| `description` | String? | A short description of the command | | ||
| `user` | User | The user that called the command | | ||
| `channel` | Channel | The channel on which the command was called | | ||
| `guild` | Guild? | The guild on which the command was called | | ||
|
||
### Text-based | ||
The third-party command system, based on detecting commands from messages sent on a given discord channel. | ||
Has an extensive permission system since the code is fully controlled by the library. | ||
Requires a system that checks every message for a valid command. | ||
|
||
Extends the base attributes with: | ||
|
||
| Field | Type | Description | | ||
|----------|----------------|-------------------------------------------------------------------------------------------------------------| | ||
| `checks` | [Precondition] | An array with all checks done to the text command by the permission engine, or an empty array if none exist | | ||
| `group` | Group? | The group the command is a part of | | ||
| `alias` | [String] | An array containing all aliases to the command, or an empty array if none exist | | ||
|
||
### Slash | ||
Discord's native command system, supercedes text-based commands but has a limit of how many commands can be registered and require modifying the application. | ||
Does not require a system since discord dispatches the command to the bot via the gateway. | ||
|
||
**Currently, support for slash commands isn't planned, this could change in the future** | ||
|
||
|
||
## Structure of the `sisbase-commands` extension | ||
|
||
### Persistent Data | ||
The extension must hold a `Registry` for commands during the bot lifetime. | ||
|
||
The `Registry` must safeguard against command conflicts, as **only one command** (including overloads) can be registered for a given `Identifier`. | ||
|
||
`Identifier`s are a way to uniquely identify a given command and they include the following fields: | ||
|
||
| Field | Type | Description | Observations | | ||
|----------------------|--------|----------------------------------------------------|----------------------------------------------------------| | ||
| `source` | String | The id of the extension that registers the command | Automatically set based on the extension's metadata file | | ||
| `fullyQualifiedName` | String | The full command path for a given command | Automatically set once the command is registered | | ||
|
||
An example of a `Identifier` is given below: | ||
|
||
Command is called as `/help` | ||
```yml | ||
source: "your-bot" | ||
command: "help" | ||
identifier: "your-bot::help" | ||
``` | ||
|
||
Command is called as `/group subcommand` | ||
```yml | ||
source: "your-bot" | ||
command: "group/subcommand" | ||
identifier: "your-bot::group/subcommand" | ||
``` | ||
|
||
Identifiers don't care about command overloads, this is handled internally by the library. | ||
Mismatches for commands with equal names registered by the same extension will cause the extension to be rejected. (DUPLICATE COMMAND) | ||
Mismatches for commands with equal names registered by different extensions are to be resolved manually on the `overrides.yml` file. (COMMAND MISMATCH) | ||
|
||
Example of a mismatch: | ||
|
||
`ext-a` registers a `help` command. -> `ext-a::help` | ||
`ext-b` also registers a `help` command. -> `ext-b::help` | ||
|
||
Console Output: | ||
``` | ||
[Sisbase-Commands] Command Mismatch Detected: | ||
|
||
The following commands will become unavailable until their mismatches are resolved. | ||
|
||
for `help`: | ||
|
||
`ext-a@version` registered `help` | ||
`ext-b@version` registered `help` | ||
|
||
Please resolve all command mismatches on `overrides.yaml.` | ||
|
||
[Sisbase-Commands] Disabled `ext-a::help` due to: COMMAND MISMATCH | ||
[Sisbase-Commands] Disabled `ext-b::help` due to: COMMAND MISMATCH | ||
``` | ||
|
||
Example of a duplicate command: | ||
|
||
`ext-a` registers a `help` command. -> `ext-a::help` | ||
`ext-a` later registers a `help` command. -> `ext-a::help` | ||
|
||
Console Output: | ||
``` | ||
[Sisbase-Commands] Duplicate Command Detected: | ||
|
||
The following extensions will become unavailable until their duplicate commands are removed. | ||
|
||
for `ext-a`: | ||
|
||
Duplicate `help` command registered. | ||
|
||
Please contact the extension authors to remove the duplicate commands. | ||
|
||
[Sisbase-Commands] Disabled `ext-a` due to: DUPLICATE COMMAND | ||
|
||
``` | ||
|
||
On the case of a critical failure that leads to the extension being shutdown (or on the case of it being disabled) | ||
all commands and hooks **must be unregistered** immediately. | ||
|
||
### Required hooks | ||
|
||
For command parsing: | ||
|
||
| Hook | Usage | | ||
|--------------------------|---------------------------------------------------------------------------------------------------------------| | ||
| `onMessageReceived` | Used for parsing the message contents, building the CommandContext, and forwarding the data to the call site. | | ||
| `onGuildMessageReceived` | Same as `onMessageReceived` | |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,132 @@ | |
`Type: Subproject` | ||
Subproject of : [`SisbaseKT`](../sisbasekt.md) | ||
|
||
Discord extension manager | ||
|
||
## Dependencies | ||
[PF4J](https://github.com/pf4j/pf4j) - Plugin Framework | ||
[api](api.md) | ||
|
||
## Features | ||
|
||
- Systems `META!` | ||
User-provided lifelong processes. Uses range from repeating jobs bound to a timer or connectors between the bot and an external data source. | ||
Systems can be manually unregistered during runtime via the `core.Manager::unregister` API. | ||
Systems can depend on other systems using the `@DependsOn` annotation. | ||
Systems can add "soft dependencies" using the `@Extends` annotation. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Define how. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check feasibility of |
||
|
||
- System Handling `Important!` | ||
Handles the lifetime of systems. | ||
The system lifetime is as follows: | ||
- `PreInit` | ||
- `Init` - **Required** | ||
- `PostInit` | ||
- `Disable` - **Required** | ||
|
||
- Discord Connection `Important!` | ||
*Note: Actual discord connection will be delegated to a `Backend`* | ||
- Secret Storage | ||
- Configuration API | ||
- Prefix Handling `Important!` | ||
*Note: Prefix handling must be open to the user as easily allow configuring an external prefix handler.* | ||
|
||
|
||
## Systems | ||
alikindsys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Long-term, usually lifelong background procedures. | ||
|
||
Has the following attributes: | ||
|
||
| Field | Type | Description | | ||
|----------------------|---------------------|-------------------------------------------------------------------------------------------------------------------| | ||
| `name` | String | Name of the system | | ||
| `description` | String? | A short description of the system | | ||
| `expansions` | [Expansion] | An array of system expansions, or an empty array if none exist | | ||
| `OnInit` | suspend fun | A function that runs on the start of the system's lifetime | | ||
| `OnDisable` | suspend fun | A function that runs on the end of the system's lifetime | | ||
| `CheckPreconditions` | suspend fun -> Bool | A function that runs before `OnInit`, if it returns `true` the system is loaded, otherwise the system is skipped. | | ||
|
||
|
||
### Repeating | ||
Background procedures that repeat at a set interval given by the user. | ||
|
||
Implemented by a `Expansion` that has the following attributes: | ||
| Field | Type | Description | | ||
|-------------|-------------|-----------------------------------------------------------------| | ||
| `timeout` | Duration | The period of time that will be used for repeating the function | | ||
| `OnElapsed` | suspend fun | The function that will be repeated once `timeout` elapses | | ||
|
||
### Discord-linked | ||
Background procedures that reads/writes data to Discord. | ||
|
||
Implemented by a `Expansion` that has the following attributes: | ||
| Field | Type | Description | | ||
|-----------------|----------------------|----------------------------------------------------------------------| | ||
| `applyToClient` | suspend fun (Client) | A function that will be applied to the discord client after `OnInit` | | ||
|
||
### Single-instance | ||
Simple background procedures that are set once the bot loads and are used in other parts of the bot. | ||
|
||
|
||
## Sisbase-Core Lifetime Description | ||
|
||
### Initialization | ||
|
||
1. Loads configuration | ||
2. Start the Backend | ||
3. Wait for the Backend to connect to Discord | ||
4. Loads Extensions | ||
|
||
### Lost Connection to Backend | ||
|
||
5. Stops all Extensions | ||
6. Try restarting the backend 3 times | ||
7. Shuts down the backend | ||
8. Shuts down | ||
|
||
### Connection to Backend is Resumed | ||
|
||
5. Loads Extensions | ||
|
||
## Configuration / Metadata | ||
|
||
alikindsys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
See the [sisbasekt.mod.json Documentation](./mod_json.md) for information about the Metadata File Format. | ||
|
||
-! IDEA: Due to an change in [`types`](types.md), deriving the `@RequireApiVersion` automatically could be done. | ||
-: [Not Required] [FUTURE] | ||
|
||
## Developing extensions | ||
|
||
alikindsys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
In order to make sure your extension is propperly supported, extension writers can annotate their systems with `@RequireApiVersion`. | ||
|
||
On the case of a backend not supporting said version that system will be disabled and a warning will be printed to the console. | ||
|
||
``` | ||
[Sisbase-Loader] Dependency Error: | ||
Extension `id@version` requires | ||
Discord API Version >= X | ||
Backend `id@version` provides | ||
Discord API Version == Z | ||
|
||
The following features will be disabled: | ||
- Feature Name [Description] | ||
- Feature Name [Description] | ||
|
||
Please update or change the backend to get these features back. | ||
``` | ||
|
||
Extension writers can also add `require-api-version` to the `mod.json` metadata file. | ||
|
||
On the case of a backend not supporting said version the extension won't be loaded and an error will be printed to the console. | ||
|
||
``` | ||
[Sisbase-Loader] Critical Dependency Failure: | ||
Extension `id@version` requires | ||
Discord API Version >= X | ||
Backend `id@version` provides | ||
Discord API Version == Z | ||
|
||
Extension `id@version` is now disabled. | ||
|
||
Please update or change the backend to get `id` back. | ||
``` | ||
|
||
alikindsys marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
Features
section