update
This commit is contained in:
20
glados.py
20
glados.py
@@ -7,6 +7,8 @@ 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:
|
||||
@@ -14,9 +16,11 @@ else:
|
||||
|
||||
class Bot:
|
||||
def __init__(self):
|
||||
self.client = MatrixClient(config.BOT_SERVER)
|
||||
self.client = MatrixClient(config.BOT_SERVER, config.BOT_TOKEN)
|
||||
try:
|
||||
self.client.login_with_password(config.BOT_USERNAME, config.BOT_PASSWORD)
|
||||
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:
|
||||
@@ -24,6 +28,9 @@ class Bot:
|
||||
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)
|
||||
@@ -33,15 +40,16 @@ class Bot:
|
||||
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 "@" + config.BOT_USERNAME in event['sender']:
|
||||
return
|
||||
|
||||
if event['type'] == "m.room.message":
|
||||
self.plugin_manager.notify_message(room, event)
|
||||
if event['type'] == "m.room.message":
|
||||
self.plugin_manager.notify_message(room, event)
|
||||
|
||||
def main():
|
||||
bot = Bot()
|
||||
|
||||
Reference in New Issue
Block a user