def display_help_file(self, data, name): total = set() for k, v in data.items(): total.update(v) if not (found := partial_match(name, total, key=lambda x: x.name)): raise CommandException(f"No help for: {name}")
def execute(self): mdict = self.match_obj.groupdict() args = mdict.get('args', 'accounts') if args is None: args = 'accounts' options = { 'accounts': self.who_accounts, 'connections': self.who_connections, 'characters': self.who_characters } if not (op := partial_match(args, options.keys())): raise CommandException("Need to provide option: accounts, connections, or characters")
def execute(self): mdict = self.match_obj.groupdict() args = mdict.get("args", None) if not args: raise CommandException("@import requires arguments!") if not hasattr(self.enactor, 'penn'): Importer(self.enactor, 'outdb') self.msg("Database loaded and ready to Import!") op_map = {'grid': self.op_grid, 'accounts': self.op_accounts} if not (op := partial_match(args, op_map.keys())): raise CommandException( f"Invalid operation for @import. supports: {op_map.keys()}")
def set(self, key, value, **kwargs): """ Change an individual option. Args: key (str): The key of an option that can be changed. Allows partial matching. value (str): The value that should be checked, coerced, and stored.: kwargs (any, optional): These are passed into the Option's validation function, save function and display function and allows to customize either. Returns: value (any): Value stored in option, after validation. """ if not key: raise ValueError("Option field blank!") if not (match := partial_match(key, self.options_dict.keys())): raise ValueError("Option not found!")
def execute(self): mode = self.gather_arg() if not mode: raise CommandException("What mode are we listing in?") options = { 'accounts': self.list_accounts, 'districts': self.list_districts } if not (choice := options.get(partial_match(mode.clean, options.keys()), None)): raise CommandException(f"That is not a valid choice. Choices are: {options.keys()}")
def timezone(entry, option_key="Timezone", **kwargs): """ Takes user input as string, and partial matches a Timezone. Args: entry (str): The name of the Timezone. option_key (str): What this Timezone is used for. Returns: A PYTZ timezone. """ if not entry: raise ValueError(f"No {option_key} entered!") found = partial_match(entry, _TZ_DICT.keys()) if found: return _TZ_DICT[found[0]] raise ValueError(f"Could not find timezone '{entry}' for {option_key}!")
class CharSelectCommand(Command): name = "@ic" re_match = re.compile(r"^(?P<cmd>@ic)(?: +(?P<args>.+)?)?", flags=re.IGNORECASE) help_category = 'Character Management' def execute(self): mdict = self.match_obj.groupdict() acc = self.enactor.relations.get('account', None) if not (chars := acc.characters.all()): raise CommandException("No characters to join the game as!") if not (args := mdict.get("args", None)): names = ', '.join([obj.name for obj in chars]) self.msg(text=f"You have the following characters: {names}") return if not (found := partial_match(args, chars, key=lambda x: x.name)): self.msg(text=f"Sorry, no character found named: {args}") return if not (pview := found.playviews.all()): pview, errors = self.core.mapped_typeclasses['playview'].create( objid=f"playview_{found.objid}") if errors: raise CommandException(errors) pview.at_playview_creation(found, self.enactor) else: pview = pview[0] self.enactor.join(pview) class SelectScreenCommand(Command): name = "look"
def cobj(self, abbr): if self.ccp is None: if not (code_object := partial_match("Core Code Parent <CCP>", self.objects.values(), key=lambda x: x.name)): raise Exception("Oops. No Core Code Parent in database!") self.ccp = code_object
for iden in self.generate_identifiers_for(can, names=names, aliases=aliases): ilower = iden.lower() if ilower in ('the', 'of', 'an', 'a', 'or', 'and'): continue identifiers[iden.lower()].append(can) out = [] if exact: if (found := identifiers.get(target.lower())): out = found else: return out else: m = partial_match(target, identifiers.keys()) if not m: return out out = identifiers[m] if (q := gdict.get('quant')): if q == 'all': return out else: q = int(q) if len(out) < q: l = list() l.append(out[q - 1]) else: return [] else: