obot

python3 bot library


License
Unlicense
Install
pip install obot==100

Documentation

README

Welcome to BOTLIB,

BOTLIB is a pure python3 bot library you can use to program bots, uses a JSON in file database with a versioned readonly storage and reconstructs objects based on type information in the path. It can be used to display RSS feeds, act as a UDP to IRC relay and you can program your own commands for it.

BOTLIB is placed in the Public Domain and has no COPYRIGHT and no LICENSE.

INSTALL

BOTLIB can be found on pypi, see http://pypi.org/project/botlib

installation is through pypi:

$ sudo pip3 install botlib --upgrade --force-reinstall

CONFIGURE

BOTLIB has it's own CLI, the bot program, you can run it on the shell prompt and, as default, it won't do anything:

$ bot
$

use bot <cmd> to run a command directly, e.g. the cmd command shows a list of commands:

$ bot cmd
cfg,cmd,dlt,dne,dpl,flt,fnd,ftc,krn,log,met,mod,rem,rss,thr,ver,upt

configuration is done with the cfg command:

$ bot cfg server=irc.freenode.net channel=\#dunkbots nick=botje
ok

start the bot with the irc module enabled:

$ bot mods=irc
>

a shell is started as well so you can type commands on the bot's console.

COMMANDS

programming your own commands is easy, open mod/hlo.py and add the following code:

def hlo(event):
    event.reply("hello %s" % event.origin)

recreate the dispatch table by using the tbl command:

$ bin/tbl > bot/tbl.py

now you can type the "hlo" command, showing hello <user>:

$ bot hlo
hello root@console

PROGRAMMING

BOTLIB provides a library you can use to program objects under python3. It provides a basic BigO Object, that mimics a dict while using attribute access and provides a save/load to/from json files on disk. Objects can be searched with a little database module, provides read-only files to improve persistence and use a type in filename reconstruction.

Basic usage is this:

>>> from bot.obj import Object
>>> o = Object()
>>> o.key = "value"
>>> o.key
'value'
>>> o
{"key": "value"}

Objects can be saved and loaded to JSON files:

>>> from bot.obj import Object, cfg
>>> cfg.wd = "data"
>>> o = Object()
>>> o.key = "value"
>>> path = o.save()
>>> path
'bot.obj.Object/4b58abe2-3757-48d4-986b-d0857208dd96/2021-04-12/21:15:33.734994
>>> oo = Object().load(path)
>>> oo.key
'value'

Objects try to mimic a dictionary while trying to be an object with normal attribute access as well. Hidden methods are provided as are the basic methods like get, items, keys, register, set, update, values.

great for giving objects peristence by having their state stored in files.

24/7

to run BOTLIB 24/7 you need to enable the bots service under systemd:

edit /etc/systemd/system/bot.service and add the following txt:

[Unit]
Description=BOT - 24/7 channel service
After=multi-user.target

[Service]
DynamicUser=True
StateDirectory=bot
LogsDirectory=bot
CacheDirectory=bot
ExecStart=/usr/local/bin/bots
CapabilityBoundingSet=CAP_NET_RAW

[Install]
WantedBy=multi-user.target

then enable the bot service with:

$ sudo systemctl enable bot
$ sudo systemctl daemon-reload

edit the irc configuration:

$ sudo botc cfg server=irc.freenode.net channel=\#dunkbots

and start the bot:

$ sudo systemctl start bot

if you don't want the bot to startup at boot, remove the service file:

$ sudo rm /etc/systemd/system/bot.service

CONTACT

have fun coding

Bart Thate (bthate67@gmail.com)
botfather on #dunkbots irc.freenode.net