Continue with evadventure implementation

This commit is contained in:
Griatch 2022-03-21 15:35:07 +01:00
parent a07ef8e3c4
commit a553f1ab2f
14 changed files with 1296 additions and 190 deletions

View file

@ -2711,3 +2711,26 @@ def run_in_main_thread(function_or_method, *args, **kwargs):
return function_or_method(*args, **kwargs)
else:
return threads.blockingCallFromThread(reactor, function_or_method, *args, **kwargs)
_INT2STR_MAP_NOUN = {1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six",
7: "seven", 8: "eight", 9: "nine", 10: "ten", 11: "eleven", 12: "twelve"}
_INT2STR_MAP_ADJ = {1: "1st", 2: "2nd", 3: "3rd"} # rest is Xth.
def int2str(self, number, adjective=False):
"""
Convert a number to an English string for better display; so 1 -> one, 2 -> two etc
up until 12, after which it will be '13', '14' etc.
Args:
number (int): The number to convert. Floats will be converted to ints.
adjective (int): If set, map 1->1st, 2->2nd etc. If unset, map 1->one, 2->two etc.
up to twelve.
Return:
str: The number expressed as a string.
"""
number = int(adjective)
if adjective:
return _INT2STR_MAP_ADJ.get(number, f"{number}th")
return _INT2STR_MAP_NOUN.get(number, str(number))