From 14501db8dee01d4be8fb9413adeb5d044fe2e2e9 Mon Sep 17 00:00:00 2001 From: Elias Watson Date: Sat, 22 Mar 2025 19:19:23 -0400 Subject: [PATCH] Handle missing account in Command --- evennia/commands/command.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/evennia/commands/command.py b/evennia/commands/command.py index f676df49bb..26c1ca7e8e 100644 --- a/evennia/commands/command.py +++ b/evennia/commands/command.py @@ -623,6 +623,22 @@ Command \"{cmdname}\" has no defined `func()` method. Available properties on th )[0] return settings.CLIENT_DEFAULT_WIDTH + def _get_account_option(self, option): + """ + Retrieve the value of a specified account option. + + Args: + option (str): The name of the option to retrieve. + + Returns: + The value of the specified account option if the account exists, + otherwise the default value from settings.OPTIONS_ACCOUNT_DEFAULT. + + """ + if self.account: + return self.account.options.get(option) + return settings.OPTIONS_ACCOUNT_DEFAULT.get(option) + def styled_table(self, *args, **kwargs): """ Create an EvTable styled by on user preferences. @@ -638,8 +654,8 @@ Command \"{cmdname}\" has no defined `func()` method. Available properties on th or incomplete and ready for use with `.add_row` or `.add_collumn`. """ - border_color = self.account.options.get("border_color") - column_color = self.account.options.get("column_names_color") + border_color = self._get_account_option("border_color") + column_color = self._get_account_option("column_names_color") colornames = ["|%s%s|n" % (column_color, col) for col in args] @@ -699,9 +715,9 @@ Command \"{cmdname}\" has no defined `func()` method. Available properties on th """ colors = dict() - colors["border"] = self.account.options.get("border_color") - colors["headertext"] = self.account.options.get("%s_text_color" % mode) - colors["headerstar"] = self.account.options.get("%s_star_color" % mode) + colors["border"] = self._get_account_option("border_color") + colors["headertext"] = self._get_account_option("%s_text_color" % mode) + colors["headerstar"] = self._get_account_option("%s_star_color" % mode) width = width or self.client_width() if edge_character: @@ -722,7 +738,7 @@ Command \"{cmdname}\" has no defined `func()` method. Available properties on th else: center_string = "" - fill_character = self.account.options.get("%s_fill" % mode) + fill_character = self._get_account_option("%s_fill" % mode) remain_fill = width - len(center_string) if remain_fill % 2 == 0: