Add matrix backend and relevant config generation
This commit is contained in:
parent
8d62ff9e71
commit
866b6782d0
|
@ -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)
|
|
@ -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.
|
||||
""")
|
||||
|
||||
# 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.")
|
||||
with open('config.json', 'w') as f:
|
||||
json.dump(config, f)
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
bcrypt
|
||||
requests
|
||||
matrix_client
|
||||
|
|
Loading…
Reference in New Issue