Merge branch 'master' of github.com:anoadragon453/nio-template

* 'master' of github.com:anoadragon453/nio-template:
  Encryption support is required
  Add matrix-reminder-bot to projects list
  Allow specifying a different config file location
This commit is contained in:
Andrew Morgan 2020-06-23 02:11:41 +01:00
commit 6564e8d3f0
4 changed files with 19 additions and 21 deletions

View file

@ -10,6 +10,8 @@ matrix-nio can be found
* [anoadragon453/msc-chatbot](https://github.com/anoadragon453/msc-chatbot) - A matrix bot for matrix spec proposals
* [anoadragon453/matrix-episode-bot](https://github.com/anoadragon453/matrix-episode-bot) - A matrix bot to post episode links
* [TheForcer/vision-nio](https://github.com/TheForcer/vision-nio) - A general purpose matrix chatbot
* [anoadragon453/matrix-reminder-bot](https://github.com/anoadragon453/matrix-reminder-bot
) - A matrix bot to remind you about things
Want your project listed here? [Edit this
doc!](https://github.com/anoadragon453/nio-template/edit/master/README.md)

View file

@ -61,7 +61,6 @@ class Config(object):
self.device_id = self._get_cfg(["matrix", "device_id"], required=True)
self.device_name = self._get_cfg(["matrix", "device_name"], default="nio-template")
self.homeserver_url = self._get_cfg(["matrix", "homeserver_url"], required=True)
self.enable_encryption = self._get_cfg(["matrix", "enable_encryption"], default=False)
self.command_prefix = self._get_cfg(["command_prefix"], default="!c") + " "

32
main.py
View file

@ -2,6 +2,7 @@
import logging
import asyncio
import sys
from time import sleep
from nio import (
AsyncClient,
@ -24,7 +25,13 @@ logger = logging.getLogger(__name__)
async def main():
# Read config file
config = Config("config.yaml")
# A different config file path can be specified as the first command line argument
if len(sys.argv) > 1:
config_filepath = sys.argv[1]
else:
config_filepath = "config.yaml"
config = Config(config_filepath)
# Configure the database
store = Storage(config.database_filepath)
@ -34,7 +41,7 @@ async def main():
max_limit_exceeded=0,
max_timeouts=0,
store_sync_tokens=True,
encryption_enabled=config.enable_encryption,
encryption_enabled=True,
)
# Initialize the matrix client
@ -66,19 +73,14 @@ async def main():
logger.error(f"Failed to login: %s", login_response.message)
return False
except LocalProtocolError as e:
# There's an edge case here where the user enables encryption but hasn't installed
# the correct C dependencies. In that case, a LocalProtocolError is raised on login.
# Warn the user if these conditions are met.
if config.enable_encryption:
logger.fatal(
"Failed to login and encryption is enabled. Have you installed the correct dependencies? "
"https://github.com/poljar/matrix-nio#installation"
)
return False
else:
# We don't know why this was raised. Throw it at the user
logger.fatal("Error logging in: %s", e)
return False
# There's an edge case here where the user hasn't installed the correct C
# dependencies. In that case, a LocalProtocolError is raised on login.
logger.fatal(
"Failed to login. Have you installed the correct dependencies? "
"https://github.com/poljar/matrix-nio#installation "
"Error: %s", e
)
return False
# Login succeeded!

View file

@ -18,11 +18,6 @@ matrix:
device_id: ABCDEFGHIJ
# What to name the logged in device
device_name: nio-template
# End-to-end encryption support
#
# Enabling this requires installing the matrix-nio encryption dependencies
# as described here: https://github.com/poljar/matrix-nio#installation
enable_encryption: true
storage:
# The path to the database