Add "help" trigger and help() static method to trigger objects
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
from typing import Iterable, Optional, TYPE_CHECKING
|
||||
from typing import Iterable, Optional, Sequence, Union, TYPE_CHECKING
|
||||
import dataclasses
|
||||
import re
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from agame.item import ItemInst
|
||||
@@ -9,3 +11,32 @@ def search_item_name(seq: Iterable["ItemInst"], item_name: str) -> Optional["Ite
|
||||
if item.name.lower() == item_name.lower() or item_name.lower() in item.synonyms:
|
||||
return item
|
||||
return None
|
||||
|
||||
|
||||
def trigger_help_builder(
|
||||
actions: Union[str, Sequence[str]], args: Union[str, Sequence[str]] = ()
|
||||
) -> str:
|
||||
actions = (actions,) if isinstance(actions, str) else actions
|
||||
args = (args,) if isinstance(args, str) else args
|
||||
|
||||
actions = (
|
||||
f"(({actions}))"
|
||||
if isinstance(actions, str)
|
||||
else "/".join(f"(({a}))" for a in actions)
|
||||
)
|
||||
|
||||
def fmt_arg(a: str):
|
||||
if "[" in a and "]" in a:
|
||||
return f"{{{{{a}}}}}"
|
||||
else:
|
||||
return a
|
||||
|
||||
if args:
|
||||
args = (
|
||||
fmt_arg(args)
|
||||
if isinstance(args, str)
|
||||
else " ".join(fmt_arg(a) for a in args)
|
||||
)
|
||||
return f"{actions} {args}"
|
||||
else:
|
||||
return actions
|
||||
|
||||
Reference in New Issue
Block a user