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}")
async def search_objects( self, name: Union[str, Text], candidates: Optional[Iterable[GameObjectKey]] = None, exact=False, aliases=True): if isinstance(name, Text): name = name.plain if candidates is None: candidates = [obj.key for obj in self.objects.values()] search_candidates = list() for can in candidates: results = await self.db.get_object(can) if results.data: search_candidates.append((can, results.data)) name_lower = name.strip().lower() if exact: for obj in search_candidates: if name_lower == obj[1]['name'].lower(): return obj, None else: if (found := partial_match(name, search_candidates, key=lambda x: x[1]['name'])): return found, None
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 run(self): args, unknown_args = self.parser.parse_known_args() option = args.operation.lower() operation = option if option not in self.choices: option = "_passthru" try: if args.init: self.option_init(args.init[0], unknown_args) option = "_noop" operation = "_noop" if option in ["start", "stop", "_passthru"]: # first, ensure we are running this program from the proper directory. self.set_profile_path(args) os.chdir(self.profile_path) # next, insert the new cwd into path. import sys sys.path.insert(0, os.getcwd()) # now we should be able to import appdata! from appdata.config import Launcher l_config = Launcher() l_config.setup() # choose either all apps or a specific app to focus on. if args.app: if not (found := partial_match(args.app[0], l_config.applications)): raise ValueError( f"No registered Athanor application: {args.app[0]}" ) self.applications = [found] else: self.applications = l_config.applications # Find and execute the operation. if not (op_func := self.operations.get(option, None)): raise ValueError(f"No operation: {option}")
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}!")
name = "@ic" re_match = re.compile(r"^(?P<cmd>@ic)(?: +(?P<args>.+)?)?", flags=re.IGNORECASE) help_category = "Character Management" character_type = "PLAYER" async def execute(self): mdict = self.match_obj.groupdict() acc = self.entry.user if not (chars := acc.namespaces[self.character_type]): 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 error = await self.entry.game.create_or_join_session(self.entry, found) if error: raise CommandException(error) class SelectScreenCommand(Command): name = "look" re_match = re.compile(r"^(?P<cmd>look)(?: +(?P<args>.+)?)?", flags=re.IGNORECASE) async def execute(self): await self.executor.show_select_screen(self.executor)
nicks=use_nicks) for word in words: ilower = word.lower() if ilower in simple_words: continue keywords[ilower].append(can) for n in whole: full_names[n.lower()].append(can) nlower = name.lower() if exact: if (found := full_names.get(nlower, None)): out.extend(found) else: if quoted: m = partial_match(nlower, full_names.keys()) if m: out.extend(full_names[m]) else: m = partial_match(nlower, keywords.keys()) if m: out.extend(keywords[m]) if not out: return out, "Nothing was found." if first_only: out = [out[0]] elif multi_match: if quant is None: quant = 1