3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-05 03:29:33 +01:00
pbot/README.md

416 lines
19 KiB
Markdown
Raw Normal View History

2020-01-21 07:43:08 +01:00
# PBot
2021-06-12 10:25:47 +02:00
PBot is a versatile IRCv3 Bot written in Perl
2014-12-30 00:28:05 +01:00
2020-01-08 03:41:37 +01:00
<!-- md-toc-begin -->
2021-06-14 03:24:19 +02:00
* [Installation / Quick Start](#installation--quick-start)
* [Features](#features)
2021-06-14 03:35:00 +02:00
* [IRCv3 capable](#ircv3-capable)
2021-06-14 03:24:19 +02:00
* [Powerful command interpreter](#powerful-command-interpreter)
* [Piping](#piping)
* [Substitution](#substitution)
* [Variables](#variables)
* [Selectors](#selectors)
* [Inline invocation](#inline-invocation)
2021-06-14 04:04:13 +02:00
* [Chaining](#chaining)
2021-06-14 03:24:19 +02:00
* [Background processing](#background-processing)
* [Scripting interface](#scripting-interface)
* [Extensible](#extensible)
* [Factoids](#factoids)
2021-06-14 04:04:13 +02:00
* [Code factoids](#code-factoids)
2021-06-14 03:24:19 +02:00
* [Plugins](#plugins)
* [Modules](#modules)
* [Functions](#functions)
2021-06-14 03:35:00 +02:00
* [Virtual machine to safely execute user-submitted code](#virtual-machine-to-safely-execute-user-submitted-code)
2021-06-14 03:24:19 +02:00
* [Powerful user management](#powerful-user-management)
2021-06-14 03:35:00 +02:00
* [Useful IRC quality-of-life improvements](#useful-irc-quality-of-life-improvements)
2021-06-14 03:24:19 +02:00
* [Channel management and protection](#channel-management-and-protection)
* [Easy configuration](#easy-configuration)
2021-06-14 03:35:00 +02:00
* [Live reloading of core modules or data files](#live-reloading-of-core-modules-or-data-files)
2021-06-14 03:24:19 +02:00
* [Documentation](#documentation)
* [Frequently Asked Questions](#frequently-asked-questions)
* [Support](#support)
* [License](#license)
2020-01-08 03:41:37 +01:00
<!-- md-toc-end -->
2020-01-21 07:43:08 +01:00
## Installation / Quick Start
To get up-and-running quickly, check out the [Quick Start guide](doc/QuickStart.md).
2014-12-30 00:28:05 +01:00
2020-01-21 07:43:08 +01:00
## Features
2020-01-08 03:38:45 +01:00
2021-06-14 03:35:00 +02:00
### IRCv3 capable
2021-06-14 03:24:19 +02:00
PBot supports several features of the IRCv3 specification.
2021-06-14 03:24:19 +02:00
* client capability negotiation
* SASL authentication
* account-notify, extended-join, and more.
2020-02-17 23:50:02 +01:00
2020-01-22 06:24:27 +01:00
### Powerful command interpreter
2020-04-10 04:04:14 +02:00
PBot has a powerful command interpreter with useful functionality, and tons of
built-in commands.
2020-01-08 06:16:02 +01:00
For more information, see the [Commands documentation.](doc/Commands.md)
2020-01-08 06:16:02 +01:00
2020-01-22 06:24:27 +01:00
#### Piping
2020-01-14 23:41:12 +01:00
You can pipe output from one command as input into another command, indefinitely.
2020-01-08 06:16:02 +01:00
2020-01-14 23:41:12 +01:00
<pragma-> !echo hello world | {sed s/world/everybody/} | {uc}
<PBot> HELLO EVERYBODY
2020-01-08 06:16:02 +01:00
[Learn more.](doc/Commands.md#piping)
2020-01-22 06:24:27 +01:00
#### Substitution
2020-01-14 23:41:12 +01:00
You can insert the output from another command at any point within a command. This
substitutes the command with its output at the point where the command was used.
<pragma-> !echo This is &{echo a demonstration} of command substitution
<PBot> This is a demonstration of command substitution
For example, suppose you want to make a Google Image Search command. The naive
way would be to simply do:
<pragma-> !factadd img /call echo https://google.com/search?tbm=isch&q=$args
Unfortuately this would not support queries containing spaces or certain symbols. But
never fear! We can use command substitution and the `uri_escape` function from the
`func` command.
Note that you must escape the command substitution to insert it literally into the
factoid otherwise it will be expanded first.
<pragma-> !factadd img /call echo https://google.com/search?tbm=isch&q=\&{func uri_escape $args}
<pragma-> !img spaces & stuff
<PBot> https://google.com/search?tbm=isch&q=spaces%20%26%20stuff
[Learn more.](doc/Commands.md#substitution)
2020-01-22 06:24:27 +01:00
#### Variables
2020-01-14 23:41:12 +01:00
You can use factoids as variables and interpolate them within commands.
<pragma-> !factadd greeting "Hello, world"
<pragma-> !echo greeting is $greeting
<PBot> greeting is Hello, world
PBot variable interpolation supports [expansion modifiers](doc/Factoids.md#expansion-modifiers), which can be chained to
combine their effects.
<pragma-> !echo $greeting:uc
<PBot> HELLO, WORLD
[Learn more.](doc/Factoids.md#list-variables)
2020-06-03 08:44:02 +02:00
#### Selectors
You can select a random item from a selection list and interpolate the value within commands.
<pragma-> !echo This is a %(neat|cool|awesome) bot.
<PBot> This is a cool bot.
[Learn more.](doc/Commands.md#selectors)
2020-01-22 06:24:27 +01:00
#### Inline invocation
2020-01-14 23:41:12 +01:00
You can invoke up to three commands inlined within a message. If the message
is addressed to a nick, the output will also be addressed to them.
<pragma-> newuser13: Check the !{version} and the !{help} documentation.
<PBot> newuser13: PBot version 2696 2020-01-04
<PBot> newuser13: To learn all about me, see https://github.com/pragma-/pbot/tree/master/doc
2020-01-08 06:16:02 +01:00
[Learn more.](doc/Commands.md#command-invocation)
2021-06-14 04:04:13 +02:00
#### Chaining
You can execute multiple commands sequentially as one command.
<pragma-> !echo Test! ;;; me smiles. ;;; version
<PBot> Test! * PBot smiles. PBot version 2696 2020-01-04
[Learn more.](doc/Commands.md#chaining)
2020-02-15 07:58:16 +01:00
2021-06-14 04:04:13 +02:00
#### Background processing
All of PBot's internal commands complete instantly, but suppose you make a Plugin that provides a command that may potentially take a long time to complete?
Not a problem! You can use the [`cmdset`](doc/Admin.md#cmdset) command to set the `background-process` [command metadata](doc/Admin.md#command-metadata-list)
2020-02-15 08:10:18 +01:00
and the command will now run as a background process, allowing PBot to carry on with its duties.
2020-02-15 07:58:16 +01:00
The familiar [`ps`](doc/Admin.md#ps) and [`kill`](doc/Admin.md#kill) commands can be used to list and kill the background processes.
2020-02-15 08:22:02 +01:00
You can also [`cmdset`](doc/Admin.md#cmdset) the `process-timeout` [command metadata](doc/Admin.md#command-metadata-list) to set the timeout, in seconds, before the command is automatically killed. Otherwise the `processmanager.default_timeout` [registry value](doc/Registry.md) will be used.
### Scripting interface
PBot uses [Plang](https://github.com/pragma-/Plang) as a scripting language. You can use the
scripting language to construct advanced commands that are capable of interacting with PBot
internal API functions.
[Learn more.](doc/Plugins/Plang.md)
2020-02-17 23:46:09 +01:00
### Extensible
2021-06-14 03:48:02 +02:00
Additional commands and functionality can be added to PBot in the following ways.
2020-02-17 23:46:09 +01:00
2021-06-14 03:24:19 +02:00
#### Factoids
2020-01-08 06:16:02 +01:00
Factoids are a very special type of command. Anybody interacting with PBot
2021-06-14 03:48:02 +02:00
can create, edit, delete and invoke factoids.
2020-01-08 06:16:02 +01:00
2021-06-14 03:48:02 +02:00
A simple factoid merely displays the text the creator sets.
2020-01-08 06:16:02 +01:00
<pragma-> !factadd hello /say Hello, $nick!
<PBot> hello added to global channel.
2020-01-10 01:59:09 +01:00
2020-01-08 06:16:02 +01:00
<pragma-> PBot, hello
<PBot> Hello, pragma-!
Significantly more complex factoids can be built by using `$variables`, command-substitution,
2021-06-14 03:48:02 +02:00
command-piping, `/code` invocation, command prefixes such as `/say`, `/me`, `/msg`, and more!
2020-01-08 06:16:02 +01:00
2020-01-08 10:45:11 +01:00
PBot factoids include these advanced features:
2020-01-21 07:43:08 +01:00
* [undo/redo history](doc/Factoids.md#factundo)
* [changelog history](doc/Factoids.md#factlog)
* [channel namespaces](doc/Factoids.md#channel-namespaces)
2021-06-14 04:13:12 +02:00
* [`factadd`](doc/Factoids.md#factadd) and [`factchange`](doc/Factoids.md#factchange) commands accept a `-url` option that sets the factoid contents from a paste website. In other words, you can edit a factoid's contents using your local editor, preserving line-breaks and indentation.
2020-01-21 07:49:11 +01:00
* [advanced `$variable` interpolation](doc/Factoids.md#expansion-modifiers) (`$var:lc` to lowercase contents, `$var:ucfirst` to uppercase first letter, etc)
* [factoid-based variable lists](doc/Factoids.md#list-variables) (e.g., add a factoid `colors` containing "red green blue" and then `!echo $colors` will randomly pick one)
* [advanced argument processing](doc/Factoids.md#special-variables-1) (indexing, splicing, etc)
* [metadata](doc/Factoids.md#factoid-metadata) (e.g. owner, times used, last used date, locked, etc)
* [special commands](doc/Factoids.md#special-commands) (`/say`, `/me`, `/msg`, `/code`, etc)
2020-01-08 10:45:11 +01:00
* and much, much more!
For more information, see the [Factoids documentation](doc/Factoids.md).
2020-01-08 06:16:02 +01:00
2021-06-14 04:04:13 +02:00
#### Code factoids
Code factoids are a special type of factoid that executes its contents within a sandboxed virtual machine.
The contents of code factoids must begin with the `/code` command:
2020-01-08 03:38:45 +01:00
/code <language> <code>
2020-01-10 01:59:09 +01:00
For example, the venerable `rot13` function:
<pragma-> !factadd rot13 /code sh echo "$@" | tr a-zA-Z n-za-mN-ZA-M
<PBot> rot13 added to global channel.
<pragma-> !rot13 Pretty neat, huh?
<PBot> Cerggl arng, uhu?
2021-06-14 03:24:19 +02:00
Making a `choose` command:
2021-06-14 04:04:13 +02:00
<pragma-> !factadd choose /code zsh _arr=($args); print $_arr[$((RANDOM % $#_arr + 1))]
2021-06-14 03:24:19 +02:00
<PBot> choose added to global channel.
2021-06-14 04:35:24 +02:00
Using the `choose` command via an [inlined command](doc/Commands.md#inline-invocation):
2021-06-14 03:24:19 +02:00
<pragma-> hmm, what should I have for dinner? !{choose chicken "roast beef" pizza meatloaf}
<PBot> pizza
You can even pipe output from other commands to Code Factoids.
2020-01-10 01:59:09 +01:00
<pragma-> !echo test | {rot13}
<PBot> grfg
For more information, see the [Code Factoid documentation](doc/Factoids.md#code).
2021-06-14 03:24:19 +02:00
#### Plugins
2020-01-14 23:41:12 +01:00
PBot can dynamically load and unload Perl modules to alter its behavior.
2020-01-28 07:05:43 +01:00
These are some of the plugins that PBot has; there are many more:
2020-01-14 23:41:12 +01:00
Plugin | Description
--- | ---
[GoogleSearch](Plugins/GoogleSearch.pm) | Performs Internet searches using the Google search engine.
[UrlTitles](Plugins/UrlTitles.pm) | When a URL is seen in a channel, intelligently display its title. It will not display titles that are textually similiar to the URL, in order to maintain the channel signal-noise ratio.
[Quotegrabs](Plugins/Quotegrabs.pm) | Grabs channel messages as quotes for posterity. Can grab messages from anywhere in the channel history. Can grab multiple messages at once!
[Weather](Plugins/Weather.pm) | Fetches and shows weather data for a location.
2020-01-30 10:18:44 +01:00
[Wttr](Plugins/Wttr.pm) | Advanced weather Plugin with tons of options. Uses wttr.in.
2020-01-14 23:41:12 +01:00
[RemindMe](Plugins/RemindMe.pm) | Lets people set up reminders. Lots of options.
[ActionTrigger](Plugins/ActionTrigger.pm) | Lets admins set regular expression triggers to execute PBot commands or factoids.
[AntiAway](Plugins/AntiAway.pm) | Detects when a person uses annoying in-channel away messages and warns them.
[AutoRejoin](Plugins/AutoRejoin.pm) | Automatically rejoin channels if kicked or removed.
[AntiNickSpam](Plugins/AntiNickSpam.pm) | Detects when a person is spamming an excessive number of nicks in the channel and removes them.
[AntiRepeat](Plugins/AntiRepeat.pm) | Warn people about excessively repeating messages. Kicks if they fail to heed warnings.
[AntiTwitter](Plugins/AntiTwitter.pm) | Warn people about addressing others with `@<nick>`. Kicks if they fail to heed warnings.
[Date](Plugins/Date.pm) | Displays date and time for a timezone.
2020-01-14 23:41:12 +01:00
There are even a few games!
Plugin | Description
--- | ---
2020-02-05 05:49:56 +01:00
[Spinach](Plugins/Spinach.pm) | An advanced multiplayer Trivia game engine with a twist! A question is shown. Everybody privately submits a false answer. All false answers and the true answer is shown. Everybody tries to guess the true answer. Points are gained when people pick your false answer!
2020-01-14 23:41:12 +01:00
[Battleship](Plugins/Battleship.pm) | The classic Battleship board game, simplified for IRC
[Connect4](Plugins/Connect4.pm) | The classic Connect-4 game.
2021-06-14 03:24:19 +02:00
#### Modules
2020-01-08 06:16:02 +01:00
Modules are external command-line executable programs and scripts that can be
2020-01-28 07:05:43 +01:00
loaded as PBot commands.
2020-01-08 06:16:02 +01:00
Suppose you have the [Qalculate!](https://qalculate.github.io/) command-line
program and you want to provide a PBot command for it. You can create a _very_ simple
shell script containing:
2020-01-08 06:16:02 +01:00
#!/bin/sh
qalc "$*"
2020-01-08 06:16:02 +01:00
And let's call it `qalc.sh` and put it in PBot's `modules/` directory.
2020-01-28 07:05:43 +01:00
Then you can load it with the [`load`](doc/Admin.md#load) command.
2020-01-21 07:43:08 +01:00
!load qalc qalc.sh
2020-01-28 07:05:43 +01:00
Now you have a [Qalculate!](https://qalculate.github.io/) calculator in PBot!
2020-01-08 03:38:45 +01:00
2020-01-08 06:16:02 +01:00
<pragma-> !qalc 2 * 2
<PBot> 2 * 2 = 4
2020-01-08 03:41:37 +01:00
2020-01-08 06:16:02 +01:00
These are just some of the modules PBot comes with; there are several more:
2020-01-08 03:41:37 +01:00
Module | Description
--- | ---
[C-to-English translator](modules/c2english) | Translates C code to natural English sentences.
[C precedence analyzer](modules/paren) | Adds parentheses to C code to demonstrate precedence.
[C Jeopardy! game](modules/cjeopardy) | C programming trivia game based on the Jeopardy! TV game show.
[C Standard citations](modules/c11std.pl) | Cite specified sections/paragraphs from the C standard.
[Virtual machine](modules/compiler_vm) | Executes arbitrary code and commands within a virtual machine.
2020-01-08 03:41:37 +01:00
[dict.org Dictionary](modules/dict.org.pl) | Interface to dict.org for definitions, translations, acronyms, etc.
[Urban Dictionary](modules/urban) | Search Urban Dictionary for definitions.
[Manpages](modules/man.pl) | Display a concise formatting of manual pages (designed for C functions)
For more information, see the [Modules documentation](doc/Modules.md).
2020-01-08 10:45:11 +01:00
2021-06-14 03:24:19 +02:00
#### Functions
2020-02-14 03:25:33 +01:00
Functions are commands that accept input, manipulate it and then output the result. They are extremely
useful with [piping](#piping) or [command substituting](#substitution).
2020-02-14 03:48:02 +01:00
For example, the `uri_escape` function demonstrated in the [Substitution](#substitution) section earlier
makes text safe for use in a URL.
2020-02-14 03:25:33 +01:00
<pragma-> uri_escape thing's & words
<PBot> thing%27s%20%26%20words
We also saw the `sed` and `uc` functions demonstrated in [Piping](#piping). The `sed` function
replaces text using a substitution regex. The `uc` function uppercases the text.
2020-02-14 03:25:33 +01:00
<pragma-> echo Hello world! | {sed s/world/universe/} | {uc}
<PBot> HELLO UNIVERSE!
Here's a short list of the Functions that come with PBot.
2020-02-14 03:25:33 +01:00
Name | Description
--- | ---
`uri_escape` | Percent-encodes unsafe URI characters.
`sed` | Performs sed-like regex substitution.
2021-06-14 05:38:15 +02:00
`grep` | Searches a string, using a regex, and prints the matching whole-word (e.g. `echo pizza hamburger hotdog \| {grep burger}` outputs `hamburger`).
2020-02-14 03:25:33 +01:00
`pluralize` | Intelligently makes a word or phrase plural.
`unquote` | Removes surrounding quotation marks.
`title` | Title-cases text. That is, lowercases the text then uppercases the first letter of each word.
`ucfirst` | Uppercases the first character of the text.
`uc` | Uppercases all characters.
`lc` | Lowercases all characters.
Additional Functions can easily be added by making a very simple PBot Plugin.
For more information, see the [Functions documentation](doc/Functions.md).
2020-01-10 01:59:09 +01:00
2021-06-14 03:35:00 +02:00
### Virtual machine to safely execute user-submitted code
2020-01-10 01:59:09 +01:00
PBot can integrate with a virtual machine to safely execute arbitrary user-submitted
2020-01-10 02:10:58 +01:00
operating system commands or code.
2020-01-10 01:59:09 +01:00
PBot supports [several shells and languages](doc/Factoids.md#supported-languages) out of the box!
2021-06-14 04:04:13 +02:00
One of PBot's most powerful features, [Code Factoids](#code-factoids), would not be possible without this.
2021-06-14 03:35:00 +02:00
2020-01-10 01:59:09 +01:00
<pragma-> !sh echo Remember rot13? | tr a-zA-Z n-za-mN-ZA-M
<PBot> Erzrzore ebg13?
2020-01-10 04:19:33 +01:00
<!-- -->
<nil> !go package main\nimport "fmt"\nfunc main() { fmt.Print("foo" == "foo"); }
<PBot> true
2020-01-10 04:19:33 +01:00
<!-- -->
<pragma-> !python print('Hello there!')
<PBot> Hello there!
2020-01-10 01:59:09 +01:00
PBot has extensive support for the C programming language. For instance, the C programming language
plugin is integrated with the GNU Debugger. It will print useful debugging information.
2020-01-10 02:12:03 +01:00
<pragma-> !cc char *p = 0; *p = 1;
2020-01-10 01:59:09 +01:00
<PBot> runtime error: store to null pointer of type 'char'
Program received signal SIGSEGV, Segmentation fault at
statement: *p = 1; <local variables: p = 0x0>
2020-01-10 02:05:37 +01:00
It can display the value of the most recent statement if there is no program output.
2020-01-10 01:59:09 +01:00
<pragma-> !cc sizeof (int)
<PBot> no output: sizeof(int) = 4
For more information about the C programming language plugin, see [the `cc` command in the Modules documentation.](doc/Modules.md#cc)
For more information about the virtual machine, see the [Virtual Machine documentation.](doc/VirtualMachine.md)
2021-06-14 03:24:19 +02:00
### Powerful user management
PBot has powerful yet simple user management functionality and commands.
* instead of generic access-levels, [fine-grained user capabilities](doc/Admin.md#user-capabilities) limit what users may do
* user accounts can be global or channel-specific
* users can be recognized by hostmask or required to login with password
* users can adjust their [user-metadata](doc/Admin.md#user-metadata-list) with the [`my`](doc/Commands.md#my) command
* and much, much more!
For more information, see the [Admin documentation.](doc/Admin.md#user-management-commands)
2021-06-14 03:35:00 +02:00
### Useful IRC quality-of-life improvements
2021-06-14 03:24:19 +02:00
* [`mode`](doc/Admin.md#mode) command can take wildcards, e.g. `mode +ov foo* bar*` to op nicks beginning with `foo` and voice nicks beginning with `bar`
* `unban <nick>` and `unmute <nick>` will remove all bans/mutes matching their current or previously seen hostmasks or accounts
* [`ban`](doc/Admin.md#banmute) and [`mute`](doc/Admin.md#banmute) will intelligently set banmasks; supports timeouts
* [`ban`](doc/Admin.md#banmute) and [`mute`](doc/Admin.md#banmute) can take a comma-separate list of nicks. Will intelligently group them into multiple `MODE +bbbb` commands
* [`kick`](doc/Admin.md#kick) can take a comma-separated list of nicks; also accepts wildcards
* and much, much more!
For more information, see the [Admin documentation.](doc/Admin.md)
### Channel management and protection
PBot can perform the typical channel management tasks.
* opping/deopping, etc
* channel-mode tracking
* user hostmask/alias tracking
* ban-evasion detection
* flood detection
* whitelisting, blacklisting, etc
* spam/advertisement detection
* and much, much more!
For more information, see the [Channels documentation](doc/Admin.md#channel-management-commands) and the [Anti-abuse documentation](doc/AntiAbuse.md)
### Easy configuration
PBot's settings are contained in a central registry of key/value pairs grouped by sections.
These settings can easily be configured via several methods:
* [PBot's command-line arguments](doc/Registry.md#overriding-registry-values-via-command-line)
* [simple built-in commands (`regset`, `regunset`, etc)](doc/Registry.md#registry-commands)
* [editing](doc/Registry.md#editing-registry-file) the [`$data_dir/registry`](data/registry) plain-text JSON file
For more information, see the [Registry documentation.](doc/Registry.md)
2021-06-14 03:35:00 +02:00
### Live reloading of core modules or data files
Suppose you edit some PBot source file, be it a core file such as [PBot/Interpreter.pm](PBot/Interpreter.pm) or
a Plugin such as [Plugins/Wttr.pm](Plugins/Wttr.pm). Or suppose there's a PBot update available. Most simple
bots would require you to shut down the bot and restart it in order to see the modifications.
Not PBot! you can simply use the [`refresh`](doc/Admin.md#refresh) command to reload all modified
PBot core files and Plugins without bot restart.
You can also use the [`reload`](doc/Admin.md#reload) command to reload any modified
configuration or data files.
2020-01-21 07:43:08 +01:00
## Documentation
2020-01-10 03:57:18 +01:00
See the [PBot documentation](doc) for more information.
2020-01-03 05:00:51 +01:00
2020-01-28 08:46:10 +01:00
## Frequently Asked Questions
If you have a question, try the [PBot FAQ](doc/FAQ.md)!
2020-01-21 07:43:08 +01:00
## Support
2021-06-14 03:24:19 +02:00
For additional questions and support, feel free to join the `#pbot` channel on the [Libera.Chat](https://libera.chat/guides) IRC network ([Web Chat](https://web.libera.chat/#pbot)).
2014-12-30 00:28:05 +01:00
2020-01-21 07:43:08 +01:00
## License
2020-01-08 04:10:55 +01:00
PBot is licensed under the [Mozilla Public License, version 2](https://www.mozilla.org/en-US/MPL/2.0/).