2020-02-06 18:32:36 +01:00
```
2020-02-07 11:28:57 +01:00
_ _ _____ __ _____ ___ ____ ___ _____
2020-02-06 18:32:36 +01:00
| | | |/ _ \ \ / / |_ _/ _ \ | __ ) / _ \_ _|
2020-02-07 11:28:57 +01:00
| |_| | | | \ \ /\ / / | || | | | | _ \| | | || |
| _ | |_ | |\ V V / | || |_| | | |_) | |_| || |
|_| |_|\___/ \_/\_/ |_| \___/ |____/ \___/ |_|
2020-02-06 18:32:36 +01:00
2020-02-07 11:28:57 +01:00
```
2020-02-06 18:32:36 +01:00
2020-02-07 11:28:57 +01:00
# How to play around with a local bot
2020-02-06 18:32:36 +01:00
2020-02-07 11:28:57 +01:00
Take a look at the existing bots:
2020-02-06 18:32:36 +01:00
2020-02-07 11:28:57 +01:00
- [streambot ](./streambot )
- [logbot ](./logbot )
2021-01-10 16:10:39 +01:00
- [RECbot ](./RECbot ) (*work-in-progess*)
2020-02-06 18:32:36 +01:00
2020-02-07 11:28:57 +01:00
They're implemented using [slixmpp ](https://slixmpp.readthedocs.io/ ).
2020-02-06 18:32:36 +01:00
2020-02-07 11:28:57 +01:00
The idea is that you create a single python file (`mybot.py` for example) and using the `slixmpp` library, you write a single Python class which knows how to speak XMPP, join rooms, respond to commands etc (see [ClientXMPP ](https://slixmpp.readthedocs.io/api/clientxmpp.html#slixmpp.clientxmpp.ClientXMPP ) for more). Following the logbot/streambot example, 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!).
2020-02-06 18:32:36 +01:00
2020-02-07 11:28:57 +01:00
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):
2020-02-06 18:32:36 +01:00
2020-02-07 11:28:57 +01:00
```
2021-01-10 16:10:39 +01:00
$ pip3 install -r requirements.txt
$ python3 streambot/streambot.py
2020-02-07 11:28:57 +01:00
```
2020-02-06 18:32:36 +01:00
2020-02-07 11:28:57 +01:00
# How to run a bot on the varia systers server
2020-02-06 18:32:36 +01:00
2020-02-07 11:28:57 +01:00
## Make a bot
2020-02-06 18:34:44 +01:00
2020-02-07 11:28:57 +01:00
Firstly, clone the bots repository.
2020-02-06 18:32:36 +01:00
2020-02-07 11:28:57 +01:00
```
$ 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!)
```
2020-02-06 18:32:36 +01:00
2020-02-07 11:28:57 +01:00
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).
2020-02-06 18:32:36 +01:00
2020-02-07 11:28:57 +01:00
## Push your changes
2020-02-06 18:32:36 +01:00
Push the changes you made to the server.
2020-02-07 11:28:57 +01:00
`$ git add mynewcoolbot/bot.py`
2020-02-06 18:32:36 +01:00
or
2020-02-07 11:28:57 +01:00
`$ git add -A`
But be sure you want to add all the files you added to the repo.
`$ git commit -m "your commit message"`
2020-02-06 18:32:36 +01:00
2020-02-07 11:28:57 +01:00
Something informative is best.
2020-02-06 18:32:36 +01:00
2020-02-06 18:34:44 +01:00
`$ git push`
2020-02-06 18:32:36 +01:00
You can also check the status of your repository by typing
2020-02-06 18:34:44 +01:00
`$ git status`
2020-02-06 18:32:36 +01:00
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.
2020-02-07 11:28:57 +01:00
## Let the bot run continuously
2020-02-06 18:32:36 +01:00
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.
There is a "bots" config file, where you can add your new bot to.
2020-02-07 11:28:57 +01:00
To do this, log into the server:
2020-02-06 18:32:36 +01:00
2020-02-06 18:34:44 +01:00
`$ ssh username@vvvvvvaria.org -p 12345`
2020-02-06 18:32:36 +01:00
2020-02-07 11:28:57 +01:00
Open the config file using your Sudo rights:
2020-02-06 18:32:36 +01:00
2020-02-07 11:28:57 +01:00
```
$ sudo nano /etc/supervisor/conf.d/bots.conf
```
2020-02-06 18:32:36 +01:00
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]
2020-02-07 11:28:57 +01:00
directory = /srv/gitea/clones/bots
2020-02-06 18:32:36 +01:00
user = bot
environment=PATH="/srv/gitea/clones/bots/.venv/lib/python3.7/site-packages:%(ENV_PATH)s"
2020-02-07 11:28:57 +01:00
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
2020-02-06 18:32:36 +01:00
```
Save and exit!
2020-02-06 18:34:44 +01:00
`CTRL+X Y [enter]`
2020-02-06 18:32:36 +01:00
2020-02-07 11:28:57 +01:00
Now, we need to restart `supervisor` itself, in order to activate these changes to the config:
2020-02-06 18:32:36 +01:00
2020-02-06 18:34:44 +01:00
`$ sudo service supervisor restart`
2020-02-06 18:32:36 +01:00
It will activate all the bots! And hopefully they work!!
2020-02-06 16:56:57 +01:00
2020-02-07 11:28:57 +01:00
You can check with:
2020-02-06 17:33:16 +01:00
2020-02-07 11:28:57 +01:00
```
$ sudo supervisorctl status bots:
```
If there are errors, have a look in:
```
$ ls /var/log/supervisor
```