-
Notifications
You must be signed in to change notification settings - Fork 6
SkyChat Plugin Development Documentation
SkyChat, a room-based messaging application, supports extension through custom plugins. Plugins are categorized into two types: RoomPlugin
and GlobalPlugin
. This document guides developers on writing plugins for SkyChat using TypeScript.
- Storage Path: Defines the base path for persistent storage.
- Rules: Specifies command rules like cooldowns, parameter patterns, etc.
- Command Execution: Implements command checking and execution logic.
- Storage Management: Methods for loading and syncing plugin data.
- User Data Handling: Functions to load and save user-specific data.
- Inherits from
Plugin
. - Room Instance: Attached to a specific room.
- Storage Path: Overrides to provide room-specific storage path.
- Hooks: Methods for intercepting room events (e.g., message broadcast, connection events).
- Inherits from
Plugin
. - Global Availability: Instantiated once at the room manager level.
- Storage Path: Overrides to provide a global storage path.
- Hooks: Methods for handling application-wide events (e.g., new messages, connection events).
-
Choose the Plugin Type:
-
RoomPlugin
: For room-specific functionality. -
GlobalPlugin
: For application-wide functionality.
-
-
Create the Plugin Class:
- Extend
RoomPlugin
orGlobalPlugin
. - Implement required methods and properties.
- Extend
-
Implement Command Logic:
- Define
commandName
andcommandAliases
. - Set up the
rules
property to define command parameters and constraints. - Implement the
run
method with the plugin's core logic.
- Define
-
Handle Storage and User Data:
- Use
syncStorage
andloadStorage
for persistent data. - Manage user-specific data with
getUserData
andsaveUserData
.
- Use
-
Implement Hooks (if needed):
- Override methods like
onNewMessageHook
,onConnectionClosed
, etc.
- Override methods like
-
Testing and Debugging:
- Test the plugin in a development environment.
- Ensure compatibility with SkyChat's core features.
Effective error handling is crucial for maintaining the stability and reliability of your plugin. Here's an example to illustrate robust error handling in a plugin method:
async run(alias: string, param: string, connection: Connection): Promise<void> {
const id = parseInt(param.split(' ')[0]);
// Find message
const message = await this.room.getMessageById(id);
if (!message) {
throw new Error('Message not found');
}
// Additional plugin logic here...
}
In this example, the run
method begins by parsing and validating the input parameter. If the expected message is not found, it throws an error with a descriptive message. This approach ensures that the plugin fails gracefully and provides clear feedback to the user or the system about what went wrong.