def process_matches(self, params): val = super().process_matches(params) if val is None: return None else: character_service = Registry.get_instance("character_service") access_service = Registry.get_instance("access_service") char_id = character_service.resolve_char_to_id(val) if char_id is None: return SenderObj(char_id, val.capitalize(), None) else: return SenderObj(char_id, val.capitalize(), access_service.get_access_level(char_id))
def set_value(self, value): util = Registry.get_instance("util") time = util.parse_time(value) if time > 0: self.value = time else: raise Exception("You must enter time in a valid Budatime format")
def get_item_image(self): if isinstance(self.item, DictObject) and self.item.icon: text = Registry.get_instance("text") return text.make_item(self.item.low_id, self.item.high_id, self.item.ql, text.make_image(self.item.icon)) else: return None
def process_matches(self, params): val = super().process_matches(params) if val is None: return None else: character_service = Registry.get_instance("character_service") return SenderObj(character_service.resolve_char_to_id(val), val.capitalize())
def timerevent(handler, budatime, description, is_hidden=False, is_enabled=True): util = Registry.get_instance("util") t = util.parse_time(budatime) handler.event = ["timer:" + str(t), description, is_hidden, is_enabled] return handler
def get_display(self): text = Registry.get_instance("text") options_str = "\n".join(map(lambda opt: text.make_chatcmd(str(opt), "/tell <myname> config setting %s set %s" % (self.name, opt)), self.options)) return """For this setting you must enter a time value. See <a href='chatcmd:///tell <myname> help budatime'>budatime</a> for info on the format of the 'time' parameter. To change this setting: <highlight>/tell <myname> config setting """ + self.name + """ set <i>_time_</i><end> Or choose an option below:\n\n""" + options_str
def process_matches(self, params): budatime_str = params.pop(0) params.pop(0) params.pop(0) params.pop(0) if budatime_str is None: return None else: util = Registry.get_instance("util") return util.parse_time(budatime_str[1:])
def get_item_str(self): if isinstance(self.item, DictObject): item_name = "%s (%s)" % (self.item.name, self.comment ) if self.comment else self.item.name text = Registry.get_instance("text") return text.make_item(self.item.low_id, self.item.high_id, self.item.ql, item_name) else: item_name = "%s (%s)" % ( self.item, self.comment) if self.comment else self.item return item_name
def get_display(self): text = Registry.get_instance("text") clear_str = "" if self.allow_empty: clear_str = "\n\nTo clear this setting:\n\n" + text.make_tellcmd("Clear this setting", "config setting %s clear" % self.name) return """For this setting you can enter any text you want (max. 255 characters). To change this setting: <highlight>/tell <myname> config setting """ + self.name + """ set <i>_value_</i></highlight>""" + clear_str + """
def timerevent(handler, budatime, description, is_system=False, is_enabled=True, run_at_startup=False, is_hidden=False): if is_hidden: log_deprecated_is_hidden(handler) util = Registry.get_instance("util") t = util.parse_time(budatime) handler.event = DictObject({"event_type": "timer:" + str(t), "description": description, "is_system": is_system or is_hidden, "is_enabled": is_enabled, "run_at_startup": run_at_startup}) return handler
def get_display(self): text = Registry.get_instance("text") if self.options: options_str = "\n\nOr choose an option below:\n\n" + "\n".join(map(lambda opt: text.make_chatcmd(str(opt), "/tell <myname> config setting %s set %s" % (self.name, opt)), self.options)) else: options_str = "" return """For this setting you can enter any text you want (max. 255 characters). To change this setting: <highlight>/tell <myname> config setting """ + self.name + """ set <i>_value_</i><end>""" + options_str
def get_item_str(self): if isinstance(self.item, DictObject): item_name = "%s (%s)" % (self.item.name, self.comment ) if self.comment else self.item.name text = Registry.get_instance("text") return text.make_item(self.item.low_id, self.item.high_id, self.item.ql, item_name) + f" (QL {self.item.ql})" else: item_name = "<highlight>%s</highlight>" % self.item if self.comment: item_name += " (%s)" % self.comment return item_name
def get_display(self): text = Registry.get_instance("text") options_str = "\n".join( map( lambda opt: text.make_chatcmd( str(opt), "/tell <myname> config setting %s set %s" % (self.name, opt)), self.options)) return """For this setting you can set any positive integer. To change this setting: <highlight>/tell <myname> config setting """ + self.name + """ set <i>_number_</i><end> Or choose an option below:\n\n""" + options_str
def get_display(self): text = Registry.get_instance("text") clear_str = "" if self.allow_empty: clear_str = "\n\nTo clear this setting:\n\n" + text.make_tellcmd("Clear this setting", "config setting %s clear" % self.name) options_str = "" if self.options: options_str = "\n\nOr choose an option below:\n\n" + "\n".join(map(lambda opt: text.make_tellcmd(str(opt), "config setting %s set %s" % (self.name, opt)), self.options)) return """For this setting you can enter any text you want (max. 255 characters). To change this setting: <highlight>/tell <myname> config setting """ + self.name + """ set <i>_value_</i></highlight>""" + clear_str + options_str
def get_display(self): text = Registry.get_instance("text") if self.options: options_str = "\n\nOr choose an option below:\n\n" + "\n".join(map(lambda opt: text.make_chatcmd(str(opt), "/tell <myname> config setting %s set %s" % (self.name, opt)), self.options)) else: options_str = "" if self.allow_empty: clear_str = "\n\nOr: " + text.make_chatcmd("Clear this setting", "/tell <myname> config setting %s clear" % self.name) else: clear_str = "" return """For this setting you can set any positive integer. To change this setting: <highlight>/tell <myname> config setting """ + self.name + """ set <i>_number_</i><end>""" + clear_str + options_str
def __init__(self, conn: Conn): self.bot = Registry.get_instance("bot") self.db = Registry.get_instance("db") self.text = Registry.get_instance("text") self.alts_service = Registry.get_instance("alts_service") self.points_controller = Registry.get_instance("points_controller") self.job_scheduler = Registry.get_instance("job_scheduler") self.raid_controller = Registry.get_instance("raid_controller") self.auction_start_time = None self.auction_end_time = None self.is_started = False self.items = dict() self.bids = DictObject( ) # self.bids[item_index] = [AuctionBid(), AuctionBid()] self.next_item_index = 1 self.auctioneer: SenderObj = None self.is_running = False self.conn = conn
def __init__(self): self.bot = Registry.get_instance("bot") self.db = Registry.get_instance("db") self.text = Registry.get_instance("text") self.alts_service = Registry.get_instance("alts_service") self.points_controller = Registry.get_instance("points_controller") self.job_scheduler = Registry.get_instance("job_scheduler") self.auction_start_time = None self.auction_end_time = None self.announce_interval = None self.is_started = False self.items = dict() self.winning_bids = dict() self.next_item_index = 1 self.auctioneer: SenderObj = None self.job_id = None self.is_running = False
from core.db import DB from core.logger import Logger from core.registry import Registry db = Registry.get_instance("db") logger = Logger("core.upgrade") def table_info(table_name): if db.type == DB.MYSQL: data = db.query("DESCRIBE %s" % table_name) def normalize_table_info(row): row.name = row.Field row.type = row.Type.upper() return row return list(map(normalize_table_info, data)) elif db.type == DB.SQLITE: return db.query("PRAGMA table_info(%s)" % table_name) else: raise Exception("Unknown database type '%s'" % db.type) def table_exists(table_name): try: db.query("SELECT * FROM %s LIMIT 1" % table_name) return True except Exception: return False
def __init__(self): self.setting_service = Registry.get_instance("setting_service") self.name = None
def get_display_value(self): util = Registry.get_instance("util") return "<highlight>%s<end>" % util.time_to_readable(self.get_value())
def get_display_value(self): util = Registry.get_instance("util") return util.time_to_readable(self.get_value())
def timerevent(handler, budatime, description): util = Registry.get_instance("util") t = util.parse_time(budatime) handler.event = ["timer:" + str(t), description] return handler
if not os.path.exists(config_file): config_creator.create_new_cfg(config_file) logger.debug("Reading config file '%s'" % config_file) with open(config_file, "r") as cfg: config = MapObject(hjson.load(cfg)) # paths to search for instances: core + module_paths paths = ["core"] paths.extend(config.module_paths) logger.debug("Loading instances") Registry.load_instances(paths) Registry.inject_all() bot = Registry.get_instance("bot") bot.init(config, Registry, paths, MMDBParser("text.mdb")) bot.connect(config.server.host, config.server.port) if not bot.login(config.username, config.password, config.character): bot.disconnect() time.sleep(5) exit(3) else: status = bot.run() bot.disconnect() exit(status.value) except KeyboardInterrupt: exit(0) except Exception as e: logger = Logger("bootstrap")
def add_db_to_instances(self, instances): for name in instances: inst = Registry.get_instance(name) inst.db = self.db2
def log_deprecated_is_hidden(handler): util = Registry.get_instance("util") logger.warning("Event option `is_hidden` is deprecated; use `is_system` instead (event %s)" % util.get_handler_name(handler))
exit(0) logger.debug("Reading config file '%s'" % config_file) with open(config_file) as cfg: config = json.load(cfg) logger.debug("Loading instances") Registry.load_instances([ "core", os.path.join("modules", "core"), os.path.join("modules", "addons") ]) Registry.add_instance("mmdb_parser", MMDBParser("text.mdb")) Registry.inject_all() bot = Registry.get_instance("mangopie") db = Registry.get_instance("db") db.connect(config["db_host"], config["db_name"]) bot.init(config, Registry) if int(config["dimension"]) == 1: bot.connect("chat.d1.funcom.com", 7105) elif int(config["dimension"]) == 2: bot.connect("chat.dt.funcom.com", 7109) elif int(config["dimension"]) == 3: bot.connect("localhost", 9993) else: print('Invalid server!') bot.disconnect() time.sleep(5) exit(1)
# load config logger.debug("Reading config file '%s'" % config_file) with open(config_file, "r") as cfg: config = DictObject(hjson.load(cfg)) # paths to search for instances: core + module_paths paths = ["core"] paths.extend(config.module_paths) # load instances logger.debug("Loading instances") Registry.load_instances(paths) Registry.inject_all() # configure database db = Registry.get_instance("db") if config.database.type == "sqlite": db.connect_sqlite("./data/" + config.database.name) elif config.database.type == "mysql": db.connect_mysql(config.database.host, config.database.username, config.database.password, config.database.name) else: raise Exception("Unknown database type '%s'" % config.database.type) # run db upgrade scripts import upgrade # finish initializing bot and modules, and then connect bot = Registry.get_instance("bot") bot.init(config, Registry, paths, MMDBParser("text.mdb")) bot.connect(config.server.host, config.server.port)
def __init__(self): self.setting_manager = Registry.get_instance("setting_manager") self.name = None