diff --git a/_api/commands.md b/_api/commands.md new file mode 100644 index 00000000..5a270d1d --- /dev/null +++ b/_api/commands.md @@ -0,0 +1,56 @@ +--- +layout: documentation +title: Commands +description: The Command API lets you add new commands. +type: server +--- + +The Command API lets you add new commands. + +## Methods + +### `#add(command: Object)` + +Adds a new command. + +Attributes of command: + +**`input: Function`** +: The implementation of the command, see the arguments below: + +**`allowDisconnected: Boolean`** +: If `true` this command can be execute when the client isn't connected. + +## Arguments of a command: + +**`client: PublicClient`** +: The client API + +**`target: Object`** +: `target.network` is the network this command was run in, `target.chan` the corresponding channel. + +**`command: String`** +: The command name (lowercase). + +**`args: Array of String`** +: The arguments the command was executed with. + +## Example + +```js +const helloWorldCommand = { + input: function (client, target, command, args) { + if(args.length === 0) { + client.sendMessage("Hello World", target.chan); + } else { + client.sendMessage("Hello " + args[0], target.chan); + } + }, + allowDisconnected: true +}; +module.exports = { + onServerStart: api => { + api.Commands.add("helloworld", helloWorldCommand); + }, +}; +``` \ No newline at end of file diff --git a/_api/public-client.md b/_api/public-client.md new file mode 100644 index 00000000..7be37437 --- /dev/null +++ b/_api/public-client.md @@ -0,0 +1,96 @@ +--- +layout: documentation +title: Public Client +description: The Public Client API lets you interact with the client +type: server +--- + +The Public Client API lets you interact with the client + +## Methods + +### `#runAsUser(command: String, targetId: String)` + +Allows to make the client send a message/run a command. + +Arguments: + +**`command: String`** +: IRC command to run, this is in the same format that a client would send to the server (eg: JOIN #test). + +**`targetId: String`** +: The id of the channel to simulate the command coming from. Replies will go to this channel if appropriate + +### `#createChannel(attributes: Object)` + +Allows to create a new channel. + +Attributes: + +**`id: Number`** +: The id of the channel, defaults to 0. + +**`messages: Array of Msg`** +: The messages of the channel, defaults to empty array. + +**`name: String`** +: The name of the channel, defaults to empty string. + +**`key: String`** +: The key of the channel, defaults to empty string. + +**`topic: String`** +: The topic of the channel, defaults to empty string. + +**`type: Chan.Type`** +: The type of the channel, defaults to `CHANNEL`. Available types: `CHANNEL`, `LOBBY`, `QUERY`, `SPECIAL`. +Special is used for banlist, invitelist, channellist or ignorelist. + +**`state: Chan.State`** +: The state of the channel, defaults to `PARTED`, Possible states: `PARTED`, `JOINED`. + +**`firstUnread: Number`** +: The first unread message, defaults to 0. + +**`unread: Number`** +: The number of unread messages, defaults to 0. + +**`highlight: Number`** +: The number of highlights, defaults to 0. + +**`users: Map from String to User`** +: The users of the channel, key is the lowercase nick, the value is the user object. Defaults to empty map. + +### `#sendToBrowser(event: String, data: Object)` + +Emits an `event` to the browser client, with `data` in the body of the event. + +Arguments: + +**`event: String`** +: Name of the event, must be something the browser will recognise. + +**`data: Object`** +: Body of the event, can be anything, but will need to be properly interpreted by the client. + +### `#getChannel(channelId: Number)` + +Looks up a channel by ID. + +Arguments: + +**`channelId: Number`** +: The id of the channel to return. + +### `#sendMessage(text: String, chan: Chan)` + +Sends a message to this client, displayed in the given channel. +This message will be displayed as a plugin message, the sender will be the name of your plugin (define in your package.json under thelounge.name) and defaults to the package name. + +Arguments: + +**`text: String`** +: The content of the message. + +**`chan: Chan`** +: The channel to send this message into.