From 19aaa1a54655e51aa703953c74c5a1c33ef8a848 Mon Sep 17 00:00:00 2001 From: Ville Ranki Date: Wed, 25 Nov 2020 22:09:18 +0200 Subject: [PATCH] Disabled a few modules by default, added docs and scripts for running locally. --- README.md | 23 ++++++++++++++++++++++- hemppa.service | 19 +++++++++++++++++++ modules/mxma.py | 1 + modules/relay.py | 1 + modules/teamup.py | 9 ++++++--- run.sh | 7 +++++++ 6 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 hemppa.service create mode 100644 run.sh diff --git a/README.md b/README.md index 4ca8607..8351fe8 100644 --- a/README.md +++ b/README.md @@ -457,7 +457,7 @@ This module is disabled by default. * Log in as the newly created user (easiest is Element Web in private window) * Get user's access token (In Element Web see Settings / Help & about) -## Running on host +## Running locally Run something like (tested on Ubuntu): @@ -472,6 +472,27 @@ MATRIX_USER="@user:matrix.org" MATRIX_ACCESS_TOKEN="MDAxOGxvYlotofcharacters53Cg NOTE: The Pipfile does not define the python version as it is always strict and causes problems. See https://github.com/pypa/pipenv/issues/1050 . Python 3.7 and 3.8 should both work fine. +## Running locally with systemd unit file (Raspberry Pi etc) + +First modify run.sh and make sure Hemppa starts successfully with it. + +There's a systemd unit file you can use. It assumes hemppa is installed to /opt/hemppa and +is run as user pi in group pi. Note: this is probably not the smartest way to do this, feel free +to do a PR for better way. + +If your user is not pi, modify hemppa.service first. + +``` bash +sudo ln -s `pwd` /opt/hemppa +sudo ln -s hemppa.service /lib/systemd/system +sudo systemctl daemon-reload +sudo systemctl enable hemppa.service +sudo systemctl start hemppa.service +sudo systemctl status hemppa.service +``` + +Status should show "Active: active (running)" + ## Running with Docker Create .env file and set variables: diff --git a/hemppa.service b/hemppa.service new file mode 100644 index 0000000..1f740bf --- /dev/null +++ b/hemppa.service @@ -0,0 +1,19 @@ +[Unit] +Description=Hemppa the Bot +Wants=network-online.target +After=network-online.target +StartLimitIntervalSec=500 +StartLimitBurst=5 + +[Service] +Type=simple +WorkingDirectory=/opt/hemppa/ +ExecStart=/opt/hemppa/run.sh +StandardInput=tty-force +Restart=always +RestartSec=5s +User=pi +Group=pi + +[Install] +WantedBy=multi-user.target diff --git a/modules/mxma.py b/modules/mxma.py index b951f46..7a4a980 100644 --- a/modules/mxma.py +++ b/modules/mxma.py @@ -12,6 +12,7 @@ class MatrixModule(PollingService): self.poll_interval_random = 2 self.owner_only = True self.send_all = True + self.enabled = False async def poll_implementation(self, bot, account, roomid, send_messages): try: diff --git a/modules/relay.py b/modules/relay.py index adf5d9a..e9a2153 100644 --- a/modules/relay.py +++ b/modules/relay.py @@ -6,6 +6,7 @@ class MatrixModule(BotModule): super().__init__(name) self.bridges = dict() self.bot = None + self.enabled = False async def message_cb(self, room, event): if self.bot.should_ignore_event(event): diff --git a/modules/teamup.py b/modules/teamup.py index 26a2ec2..2333a17 100644 --- a/modules/teamup.py +++ b/modules/teamup.py @@ -10,9 +10,12 @@ from modules.common.module import BotModule class MatrixModule(BotModule): - api_key = None - calendar_rooms = dict() # Roomid -> [calid, calid..] - calendars = dict() # calid -> Calendar + def __init__(self, name): + super().__init__(name) + self.api_key = None + self.calendar_rooms = dict() # Roomid -> [calid, calid..] + self.calendars = dict() # calid -> Calendar + self.enabled = False async def matrix_poll(self, bot, pollcount): if self.api_key: diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..5b8339b --- /dev/null +++ b/run.sh @@ -0,0 +1,7 @@ +#!/bin/bash +export MATRIX_USER="@user:matrix.org" +export MATRIX_ACCESS_TOKEN="lotOfCharactersHere" +export MATRIX_SERVER="https://matrix.org" +# export JOIN_ON_INVITE="True" +export BOT_OWNERS="@owner:matrix.org" +pipenv run python3 bot.py