~technomancy/pengbot

An IRC bot written in Fennel
Expose rudimentary sandboxed fennel module.
Actually look up sandbox env correctly.
Update master fennel to nearly 0.4.0.

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~technomancy/pengbot
read/write
git@git.sr.ht:~technomancy/pengbot

You can also use your local clone with git send-email.

P'eng bot

In the northern ocean there is a fish, called the k'un, I do not know how many thousand li in size. This k'un changes into a bird, called the p'eng. Its back is I do not know how many thousand li in breadth. When it is moved, it flies, its wings obscuring the sky like clouds.

When on a voyage, this bird prepares to start for the Southern Ocean, the Celestial Lake. And in the Records of Marvels we read that when the p'eng flies southwards, the water is smitten for a space of three thousand li around, while the bird itself mounts upon a great wind to a height of ninety thousand li, for a flight of six months' duration.

  • Chuang Tzu

A bot written in Fennel for IRC and Fediverse.

Pengbot's IRC mode can run either on a conventional computer or on a microcontroller; see Micropeng below.

Usage

For IRC:

$ ./fennel pengbot.fnl chat.freenode.net 6667 pengbot "#pengbot" "#otherchan"

For Fediverse:

$ ./fennel fediverse.fnl https://auth-code42342221@fedi.host [90]

The Fediverse mode is highly insecure and will transmit your credentials over connection that doesn't do TLS verification; use at your own risk.

The second argument is how many seconds to pause in between looking for notifications; omit it to check only once.

On IRC, commands are prefixed with a comma or can be addressed directly to the bot's nick. On Fediverse, you must address the bot and begin your command with a comma.

Run ,help to get a list of commands. The main commands are:

  • ,echo TEXT: echo back the text
  • ,set TERM DEFINITION: store a term and its definition
  • ,get TERM: retrieve a term's definition
  • ,forget TERM: delete a term's definition
  • ,eval FORM: evaluate a piece of Fennel code and print return value

Stores dictionary data (from set command) in the data/ directory that it's launched from. No limits are in place to prevent it from filling up the disk yet, so disable that command if you're worried.

Requirements: Lua 5.1+ and luasocket.

Micropeng

Pengbot can also run on a NodeMCU device such as the US$3 Wemos D1 Mini.

Ensure the directory that pip installs to is on your $PATH; on some systems this is $HOME/.local/bin.

If you don't have a compatible NodeMCU build on your device, you may need to flash that first.

$ pip install --user esptool
$ esptool.py --port /dev/ttyUSB0  write_flash -fm dio 0x00000 nodemcu-leds-int.bin

You'll need to configure wifi on your device before you start. Open a Lua repl to the device (i.e. screen /dev/ttyUSB0 115200) and run:

> wifi.setmode(wifi.STATION)
> wifi.sta.config({ssid="cybre-netwerk", pwd="reindeerflotilla"})

Then exit the terminal. This setting will persist through device reboots.

Install nodemcu-uploader to allow uploading:

$ pip install --user nodemcu-uploader

Finally, upload the pengbot code to the device:

$ make upload NICK=micropeng2 CHANNEL=mychan

When pengbot is running on NodeMCU, the on and off commands can toggle gpio pins. However, in this mode the eval command is unavailable due to memory limitations. You can also use the leds command to set LED effects.

TODO: kill ghosted connections

License

Copyright © 2018-2019 Phil Hagelberg and contributors

Distributed under the GNU General Public License version 3 or later; see file LICENSE.