diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b5f2c62b9..2e27e93ed5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -203,6 +203,8 @@ Up requirements to Django 4.0+, Twisted 22+, Python 3.9 or 3.10 - Add new setting `MAX_NR_SIMULTANEUS_PUPPETS` - how many puppets the account can run at the same time. Used to limit multi-playing. - Make setting `MAX_NR_CHARACTERS` interact better with the new settings above. +- Allow `$search` funcparser func to search tags and to accept kwargs for more + powerful searches passed into the regular search functions. ## Evennia 0.9.5 diff --git a/evennia/utils/funcparser.py b/evennia/utils/funcparser.py index 71d3160124..84fe9f526b 100644 --- a/evennia/utils/funcparser.py +++ b/evennia/utils/funcparser.py @@ -1088,7 +1088,9 @@ def funcparser_callable_search(*args, caller=None, access="control", **kwargs): security. If called without session, the call is aborted. Args: - query (str): The key or dbref to search for. + query (str): The key or dbref to search for. This can consist of any args used + for one of the regular search methods. Also kwargs will be passed into + the search (except the kwargs given below) Keyword Args: return_list (bool): If set, return a list of objects with @@ -1099,6 +1101,7 @@ def funcparser_callable_search(*args, caller=None, access="control", **kwargs): The 'control' permission is required. access (str): Which locktype access to check. Unset to disable the security check. + **kwargs: Will be passed into the main search. Returns: any: An entity match or None if no match or a list if `return_list` is set. @@ -1111,25 +1114,33 @@ def funcparser_callable_search(*args, caller=None, access="control", **kwargs): - "$search(#233)" - "$search(Tom, type=account)" - "$search(meadow, return_list=True)" + - "$search(beach, category=outdoors, type=tag) """ - return_list = kwargs.get("return_list", "false").lower() == "true" + # clean out funcparser-specific kwargs so we can use the kwargs for + # searching + search_kwargs = { + key: value + for key, value in kwargs.items() + if key not in ("funcparser", "raise_errors", "type", "return_list") + } + return_list = kwargs.pop("return_list", "false").lower() == "true" if not args: return [] if return_list else None if not caller: raise ParsingError("$search requires a `caller` passed to the parser.") - query = str(args[0]) - typ = kwargs.get("type", "obj") targets = [] if typ == "obj": - targets = search.search_object(query) + targets = search.search_object(*args, **search_kwargs) elif typ == "account": - targets = search.search_account(query) + targets = search.search_account(*args, **search_kwargs) elif typ == "script": - targets = search.search_script(query) + targets = search.search_script(*args, **search_kwargs) + elif typ == "tag": + targets = search.search_object_by_tag(*args, **search_kwargs) if not targets: if return_list: