2020-07-23 21:10:33 +02:00
|
|
|
# Plang
|
|
|
|
|
|
|
|
<!-- md-toc-begin -->
|
|
|
|
* [About](#about)
|
2020-07-23 21:37:34 +02:00
|
|
|
* [The Plang Language](#the-plang-language)
|
2020-09-22 23:05:25 +02:00
|
|
|
* [PBot commands](#pbot-commands)
|
|
|
|
* [plang](#plang-1)
|
|
|
|
* [plangrepl](#plangrepl)
|
2020-07-23 21:37:34 +02:00
|
|
|
* [PBot built-in Plang functions](#pbot-built-in-plang-functions)
|
|
|
|
* [factget](#factget)
|
|
|
|
* [factset](#factset)
|
|
|
|
* [factappend](#factappend)
|
|
|
|
* [userget](#userget)
|
2020-07-23 21:10:33 +02:00
|
|
|
<!-- md-toc-end -->
|
|
|
|
|
|
|
|
## About
|
2020-07-23 21:53:38 +02:00
|
|
|
The Plang plugin provides a scripting interface to PBot. It has access to PBot
|
2020-07-23 21:10:33 +02:00
|
|
|
internal APIs and state.
|
|
|
|
|
2020-07-23 21:37:34 +02:00
|
|
|
## The Plang Language
|
2020-07-23 21:10:33 +02:00
|
|
|
The scripting language is [Plang](https://github.com/pragma-/Plang). It was
|
2020-09-21 08:12:43 +02:00
|
|
|
written specifically for PBot, but aims to be powerful enough to be used as a general-purpose
|
2020-07-23 21:10:33 +02:00
|
|
|
scripting language embedded into any Perl application.
|
|
|
|
|
|
|
|
This document describes PBot's Plang plugin. To learn how to use the Plang scripting
|
2020-07-23 21:18:53 +02:00
|
|
|
language, see the [Plang documentation](https://github.com/pragma-/Plang/blob/master/README.md).
|
2020-07-23 21:10:33 +02:00
|
|
|
|
2020-09-22 23:05:25 +02:00
|
|
|
## PBot commands
|
|
|
|
### plang
|
2020-07-23 21:10:33 +02:00
|
|
|
Use the `plang` command to run a Plang script.
|
|
|
|
|
|
|
|
Usage: `plang <code>`
|
|
|
|
|
2020-09-22 23:05:25 +02:00
|
|
|
### plangrepl
|
2020-07-23 21:10:33 +02:00
|
|
|
The `plangrepl` command is identical to the `plang` command, except the environment
|
|
|
|
is preserved in-between commands and the types of values is output along with the value.
|
|
|
|
|
2020-07-23 21:37:34 +02:00
|
|
|
## PBot built-in Plang functions
|
|
|
|
[Plang](https://github.com/pragma-/Plang) lets you add custom built-in functions.
|
|
|
|
Several have been added for PBot; they are described here.
|
2020-07-23 21:10:33 +02:00
|
|
|
|
2020-07-23 21:37:34 +02:00
|
|
|
### factget
|
2020-07-23 21:10:33 +02:00
|
|
|
Use the `factget` function to retrieve metadata from factoids.
|
|
|
|
|
2020-09-22 23:05:25 +02:00
|
|
|
Signature: `factget(channel: String, keyword: String, meta: String = "action") -> String | Null`
|
|
|
|
|
2020-07-23 21:10:33 +02:00
|
|
|
The `factget` function takes three paramaters: `channel`, `keyword` and `meta`. The `meta`
|
|
|
|
parameter can be omitted and will default to `"action"`.
|
|
|
|
|
2020-09-22 23:05:25 +02:00
|
|
|
The `factget` function returns a `String` containing the value of the factoid metadata or
|
|
|
|
`null` if the factoid does not exist.
|
2020-07-23 21:10:33 +02:00
|
|
|
|
2020-07-23 21:37:34 +02:00
|
|
|
### factset
|
2020-09-22 23:05:25 +02:00
|
|
|
Use the `factset` function to set metadata values for factoids. The factoid
|
|
|
|
will be created if it does not exist.
|
2020-07-23 21:10:33 +02:00
|
|
|
|
2020-09-22 23:05:25 +02:00
|
|
|
Signature: `factset(channel: String, keyword: String, text: String, meta: String = "action") -> String`
|
2020-07-23 21:10:33 +02:00
|
|
|
|
2020-09-22 23:05:25 +02:00
|
|
|
The `factset` function takes four parameters: `channel`, `keyword`, `text`,
|
|
|
|
and optionally `meta`. If the `meta` parameter is omitted it will default to
|
|
|
|
`"action"`.
|
2020-07-23 21:10:33 +02:00
|
|
|
|
|
|
|
The `factset` function returns a `String` containing the value of `text`.
|
|
|
|
|
2020-07-23 21:37:34 +02:00
|
|
|
### factappend
|
2020-07-23 21:10:33 +02:00
|
|
|
Use the `factappend` function to append text to the `action` metadata for factoids.
|
|
|
|
|
2020-09-22 23:05:25 +02:00
|
|
|
Signature: `factappend(channel: String, keyword: String, text: String) -> String`
|
|
|
|
|
2020-07-23 21:10:33 +02:00
|
|
|
The `factappend` function takes three parameters: `channel`, `keyword` and `text`.
|
|
|
|
|
|
|
|
The `factappend` function returns a `String` containing the value of factoid's `action`
|
|
|
|
metadata with `text` appended.
|
|
|
|
|
2020-07-23 21:37:34 +02:00
|
|
|
### userget
|
2020-07-23 21:10:33 +02:00
|
|
|
Use the `userget` function to retrieve user metadata.
|
|
|
|
|
2020-09-25 04:34:43 +02:00
|
|
|
Signature: `userget(name: String) -> Map | Null`
|
2020-09-22 23:05:25 +02:00
|
|
|
|
2020-07-23 21:10:33 +02:00
|
|
|
The `userget` function takes one parameter: `name`.
|
|
|
|
|
|
|
|
The `userget` function returns a `Map` containing all the metadata of the user, or
|
2020-09-21 08:12:43 +02:00
|
|
|
`null` if there is no user matching `name`.
|
2020-07-23 21:10:33 +02:00
|
|
|
|
|
|
|
See the [Plang Map documentation](https://github.com/pragma-/Plang#map) for a refresher on using Plang maps.
|
|
|
|
|
2020-09-22 23:05:25 +02:00
|
|
|
## Examples
|
|
|
|
### Basic examples
|
2020-07-23 21:10:33 +02:00
|
|
|
|
|
|
|
<pragma-> !plang userget('pragma-')
|
2020-07-25 18:31:24 +02:00
|
|
|
<PBot> { channels: "global", hostmasks: "*!*@unaffiliated/pragmatic-chaos", botowner: 1 }
|
2020-07-23 21:10:33 +02:00
|
|
|
|
2020-09-22 23:05:25 +02:00
|
|
|
<pragma-> !plang userget('pragma-').botowner
|
2020-07-23 21:10:33 +02:00
|
|
|
<PBot> 1
|
2020-07-27 07:54:01 +02:00
|
|
|
|
2020-09-22 23:05:25 +02:00
|
|
|
<pragma-> !plang if userget('pragma-').botowner then print('Greetings master!') else print('Hello mortal.')
|
2020-07-27 07:54:01 +02:00
|
|
|
<PBot> Greetings master!
|
2020-09-22 23:05:25 +02:00
|
|
|
|
|
|
|
### Karma example
|
|
|
|
|
|
|
|
This is just a quick-and-dirty placeholder snippet for now. This section will be updated with a proper
|
|
|
|
and elaborate demonstration of creating proper `karma` commands and triggers.
|
|
|
|
|
|
|
|
<pragma-> !plang var karma = Integer(factget('#karma-data', 'pragma-')); karma += 1; factset('#karma-data', 'pragma-', String(karma));
|
|
|
|
<PBot> 1
|