#!/usr/bin/env python3 # -*- coding: utf-8 -* from matrix_client.client import MatrixClient from matrix_client.api import MatrixRequestError import os import sys from plugins.plugin_manager import PluginManager if len(sys.argv) > 1: config = __import__(sys.argv[1]) else: import config class Bot: def __init__(self): self.client = MatrixClient(config.BOT_SERVER, config.BOT_TOKEN) try: if not config.BOT_TOKEN: self.client.login(config.BOT_USERNAME, config.BOT_PASSWORD) print(self.client.token) except MatrixRequestError as e: print(e) if e.code == 403: print("Bad username/password") sys.exit(1) self.plugin_manager = PluginManager(self, config) for plugin in ['help', 'say', 'admin', 'free_games']: self.plugin_manager.load_plugin(plugin) self.rooms = {} for room_id, room_data in config.rooms.items(): self.rooms[room_id] = self.client.join_room(room_id) self.rooms[room_id].add_listener(self.callback) def run(self): self.client.start_listener_thread() #return client.sync_thread print("Bot ready, listening...") while True: input() def callback(self, room, event): if "@" + config.BOT_USERNAME in event['sender']: return if event['type'] == "m.room.message": self.plugin_manager.notify_message(room, event) def main(): bot = Bot() bot.run() if __name__ == "__main__": main()