def __init__(self, config): # state object gets passed to chat commands, etc. self.state = { "players": {}, "maps": [], "current_map_index": 0, "server_config": config["server_config"] } self.config = config["tiny_config"] self.sm = Gbx.Client(self.config['address']) self.sm.init() self.sm.SetApiVersion("2012-06-19") self.sm.Authenticate(self.config['username'], self.config['password']) self.sm.EnableCallbacks(True) self.command_handler, self.cb_handler = plugin_loader(self.sm, config['plugins']) #mode_loader(self.sm, self.state, self.state['server_config']['default_mode']) # Placeholder configuration (see issue #1) server_cfg = self.state['server_config'] name = server_cfg['name'] default_mode = server_cfg['default_mode'] if server_cfg['append_mode'] == True: name = "%s (%s)" % (name, default_mode) self.sm.SetServerName(name) self.sm.SetServerPassword(server_cfg['password']) self.sm.SetServerPasswordForSpectator(server_cfg['password']) try: mode_cfg = server_cfg['modes'][default_mode]['mode_settings'] self.sm.SetModeScriptSettings(mode_cfg) except KeyError: pass self.sync() dump_state(self.sm, self.state) # Callbacks self.sm.set_default_method(self.cb_default) self.cb_handler.add("ManiaPlanet.PlayerChat", self.cb_player_chat) self.cb_handler.add("ManiaPlanet.PlayerConnect", self.cb_player_connect) self.cb_handler.add("ManiaPlanet.PlayerDisconnect", self.cb_player_disconnect) self.cb_handler.add("ManiaPlanet.BeginMap", self.cb_begin_map) self.cb_handler.add("ManiaPlanet.MapListModified", self.cb_map_list_modified)
from plugins.util.plugin import plugin_loader app = Flask(__name__) class SMSBot(object): pass smsbot = SMSBot() ### Load commands smsbot.commands = {} command_handler = plugin_loader() ### Run commands @app.route("/", methods=["POST"]) def command(): text = request.values.get('Body', None) if " " in text: command, arg = text[1:].split(" ", 1) else: command = text arg = None result = command_handler.run(command, arg) resp = twilio.twiml.Response()