Browse Source

Another run on the README

master
decentral1se 10 months ago
parent
commit
b1edd4bf19
No known key found for this signature in database GPG Key ID: 5E2EF5A63E3718CC
  1. 127
      README.md

127
README.md

@ -9,117 +9,34 @@
> status: experimental
# How to play around with a local bot?
# Bots
These bots are written using [slixmpp](https://slixmpp.readthedocs.io/) or [xbotlib](https://git.vvvvvvaria.org/decentral1se/xbotlib).
The Varia XMPP botspace. These bots are written using
[slixmpp](https://slixmpp.readthedocs.io/) and sometimes also
[xbotlib](https://git.vvvvvvaria.org/decentral1se/xbotlib).
The idea is that you create a single python file (`mybot.py` for example) and then using one of the above libraries, you write a single Python class which knows how to speak XMPP, join rooms, respond to commands etc. Following the examples in this repository, you can create a command line interface using `argparse` and then start to run it on your own computer first for testing and fun (and not spamming everyone else until your bot is ready!).
# Write your own
If you want to play around with the streambot/logbot, do the following and answer the questions (you might want to create your own testing room to join beforehand):
The idea is that you create a single python file and then using one of the
above libraries, you write a single Python class which knows how to speak XMPP,
join rooms, respond to commands etc. Probably the simplest place to start is by
reading the [`xbotlib` getting started guide](https://git.vvvvvvaria.org/decentral1se/xbotlib#user-content-getting-started).
```
$ python -m venv .venv && source .venv/bin/activate
$ pip install -r requirements.txt
$ python streambot/streambot.py
```
# How to run a bot on the varia systers server
## Make a bot
Firstly, clone the bots repository.
```
$ git clone https://git.vvvvvvaria.org/varia/bots
$ git clone ssh://gitea@vvvvvvaria.org:12345/varia/bots.git # or ssh if you prefer (no passwords to type later!)
```
Create a new folder, say, `mynewcoolbot` and add your Python script to the
folder. If your bot uses any Python dependencies, add them to the
`requirements.txt` file in the repository (please use a == with the version so
we can avoid things breaking later).
## Push your changes
Push the changes you made to the server.
`$ git add mynewcoolbot/bot.py`
or
`$ git add -A`
But be sure you want to add all the files you added to the repo.
`$ git commit -m "your commit message"`
Something informative is best.
`$ git push`
You can also check the status of your repository by typing
`$ git status`
After your push, a git hook is pulling the changes: the `bots` folder on the
server (which sits at `/srv/gitea/clones/varia/bots`) is updated. After that,
`supervisor` restarts all the bots.
## Let the bot run continuously
# Deploy it on the Varia server
To let the bot run all day all night, you can use a "service" and use the
software "supervisor". It will take care of starting and stopping your bot when
there are changes made to the code or at midnight when the backups are being
made.
Add a configuration entry to `/etc/supervisor/conf.d/bots.conf` like the following.
There is a "bots" config file, where you can add your new bot to.
To do this, log into the server:
`$ ssh username@vvvvvvaria.org -p 12345`
Open the config file using your Sudo rights:
```
$ sudo nano /etc/supervisor/conf.d/bots.conf
```
Copy/paste one of the other bot's details and add a new one to this file. This
is how the details of the pub.club bot look like:
```
[program:logbot-pub.club]
directory = /srv/gitea/clones/bots
user = bot
```conf
[program:whisperbot]
directory=/srv/gitea/clones/bots/whisperbot.xbotlib
user=bot
autostart=true
autorestart=true
environment=PATH="/srv/gitea/clones/bots/.venv/lib/python3.7/site-packages:%(ENV_PATH)s"
command =
.venv/bin/python
logbot/logbot.py
-j bot@vvvvvvaria.org
-p streaming
-r afijeno@muc.vvvvvvaria.org
-n logbot
-o /var/www/logs/pub.club
command=/srv/gitea/clones/bots/.venv/bin/python3 whisperbot.py --password <YOUR-PASSWORD>
```
Save and exit!
`CTRL+X Y [enter]`
Now, we need to restart `supervisor` itself, in order to activate these changes to the config:
`$ sudo service supervisor restart`
It will activate all the bots! And hopefully they work!!
You can check with:
```
$ sudo supervisorctl status bots:
```
If there are errors, have a look in:
```
$ ls /var/log/supervisor
```
Then `systemctl restart supervisorctl` and then check if it comes up with
`supervisorctl status bots:`. Logs for all bots can be found in
`/var/log/supervisor/`. Finally, when you git push your bot changes, a git hook
will restart your bot.

Loading…
Cancel
Save