Add matrix backend and relevant config generation

This commit is contained in:
Ceda EI 2019-05-18 12:30:31 +05:30
parent 8d62ff9e71
commit 866b6782d0
3 changed files with 43 additions and 0 deletions

12
backends/matrix.py Normal file
View File

@ -0,0 +1,12 @@
from matrix_client.client import MatrixClient
from matrix_client.api import MatrixHttpApi
def send(config, message):
if 'token' in config:
token = config["token"]
else:
token = MatrixClient(config["server"]).login(config["username"],
config["password"])
bot = MatrixHttpApi(config["server"], token=token)
bot.send_message(config["room_id"], message)

View File

@ -64,6 +64,36 @@ Message sent, if you did not recieve a message, check the bot_token and
user_id. Also, ensure that you have started the bot. user_id. Also, ensure that you have started the bot.
""") """)
# Matrix
print("\nDo you want to enable Matrix messages?\n")
config["matrix"] = {}
matrix_enable = get_boolean("y/N ", False)
config["matrix"]["enabled"] = matrix_enable
if matrix_enable:
print("\nEnter matrix homeserver address\n")
config["matrix"]["server"] = input("> ")
print("""
Use token for authorization? (Reply with no if you want to use
username/password)
""")
if get_boolean("y/N ", False):
print("\nEnter matrix token\n")
config["matrix"]["token"] = input("> ")
else:
print("\nEnter matrix username\n")
config["matrix"]["username"] = input("> ")
print("\nEnter matrix password\n")
config["matrix"]["password"] = input("> ")
print("\nEnter Room ID\n")
config["matrix"]["room_id"] = input("> ")
print("\nAttempting to send a test message")
from backends import matrix
matrix.send(config["matrix"], "Test Message from The Long Night")
print("Message sent, if you did not recieve a message, check the " +
"credentials")
print("\nStoring config.") print("\nStoring config.")
with open('config.json', 'w') as f: with open('config.json', 'w') as f:
json.dump(config, f) json.dump(config, f)

View File

@ -1,2 +1,3 @@
bcrypt bcrypt
requests requests
matrix_client