2018-12-16 15:38:47 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""
|
|
|
|
This is Peter. Peter is using the Python Matrix Bot API
|
|
|
|
"""
|
|
|
|
|
2019-01-12 14:13:21 +00:00
|
|
|
__author__ = "Dennis Potter"
|
|
|
|
__copyright__ = "Copyright 2019, Dennis Potter"
|
|
|
|
__credits__ = ["Dennis Potter"]
|
|
|
|
__license__ = "GPL-3.0"
|
|
|
|
__version__ = "0.5.0"
|
|
|
|
__maintainer__ = "Dennis Potter"
|
|
|
|
__email__ = "dennis@dennispotter.eu"
|
|
|
|
|
2018-12-16 15:38:47 +00:00
|
|
|
import json
|
2019-01-12 14:13:21 +00:00
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import threading
|
2018-12-16 15:38:47 +00:00
|
|
|
|
|
|
|
# Bot API import
|
|
|
|
from matrix_bot_api.matrix_bot_api import MatrixBotAPI
|
|
|
|
|
2019-01-12 14:13:21 +00:00
|
|
|
CONFIG_LOCATION = os.path.join(os.path.dirname(__file__), 'config.json')
|
|
|
|
|
2018-12-16 15:38:47 +00:00
|
|
|
def main():
|
|
|
|
# Load the configuration
|
2019-01-12 14:13:21 +00:00
|
|
|
with open(CONFIG_LOCATION) as json_data:
|
2018-12-16 15:38:47 +00:00
|
|
|
config = json.load(json_data)
|
|
|
|
|
|
|
|
# Create an instance of the MatrixBotAPI
|
|
|
|
bot = MatrixBotAPI(config)
|
|
|
|
|
|
|
|
# Start polling
|
|
|
|
bot.start_polling()
|
|
|
|
|
2019-01-12 14:13:21 +00:00
|
|
|
# Stall this thread while the bot runs in other threads. On ^C, this will
|
|
|
|
# indicate to all threads that they should cancel
|
2018-12-16 15:38:47 +00:00
|
|
|
try:
|
2019-01-12 14:13:21 +00:00
|
|
|
forever = threading.Event();
|
|
|
|
forever.wait()
|
2018-12-16 15:38:47 +00:00
|
|
|
except:
|
|
|
|
bot.cancel = True
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|