dkmud/utils/utils.py

38 lines
888 B
Python
Raw Permalink Normal View History

2022-01-10 14:42:13 +01:00
def has_tag(obj, key, category):
2022-02-17 18:33:26 +01:00
return obj.tags.get(key=key, category=category) is not None;
2022-01-10 14:42:13 +01:00
def fmt_light(message):
return "|r\u2600|y {} |r\u2600|n".format(message)
2022-02-17 18:33:26 +01:00
2022-01-10 14:42:13 +01:00
def fmt_dark(message):
return "|w\u2600|=h {} |w\u2600|n".format(message)
2022-02-17 18:33:26 +01:00
2022-01-10 14:42:13 +01:00
def toggle_effect(obj, effect):
if has_tag(obj, effect, "effect"):
obj.tags.remove(effect, category="effect")
else:
obj.tags.add(effect, category="effect")
2022-02-17 18:33:26 +01:00
2022-01-10 14:42:13 +01:00
def has_effect(obj, effect):
return has_tag(obj, effect, "effect")
2022-02-17 18:33:26 +01:00
2022-01-10 14:42:13 +01:00
def has_effect_in(obj, effects):
return any(True for effect in effects if has_tag(obj, effect, "effect"))
2022-02-17 18:33:26 +01:00
2022-01-10 14:42:13 +01:00
def indefinite_article(name):
"""Return the right english indefinite article for given name."""
the_vowels = ["a","e","i","o","u"]
value = ""
if name[0].lower() in the_vowels:
value = "an"
else:
value = "a"
2022-02-17 18:33:26 +01:00
return value