Merge pull request #3751 from EliasWatson/commands-without-account
Handle missing account in Command
This commit is contained in:
commit
f533a2737a
3 changed files with 31 additions and 11 deletions
|
|
@ -623,6 +623,22 @@ Command \"{cmdname}\" has no defined `func()` method. Available properties on th
|
||||||
)[0]
|
)[0]
|
||||||
return settings.CLIENT_DEFAULT_WIDTH
|
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):
|
def styled_table(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Create an EvTable styled by on user preferences.
|
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`.
|
or incomplete and ready for use with `.add_row` or `.add_collumn`.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
border_color = self.account.options.get("border_color")
|
border_color = self._get_account_option("border_color")
|
||||||
column_color = self.account.options.get("column_names_color")
|
column_color = self._get_account_option("column_names_color")
|
||||||
|
|
||||||
colornames = ["|%s%s|n" % (column_color, col) for col in args]
|
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 = dict()
|
||||||
colors["border"] = self.account.options.get("border_color")
|
colors["border"] = self._get_account_option("border_color")
|
||||||
colors["headertext"] = self.account.options.get("%s_text_color" % mode)
|
colors["headertext"] = self._get_account_option("%s_text_color" % mode)
|
||||||
colors["headerstar"] = self.account.options.get("%s_star_color" % mode)
|
colors["headerstar"] = self._get_account_option("%s_star_color" % mode)
|
||||||
|
|
||||||
width = width or self.client_width()
|
width = width or self.client_width()
|
||||||
if edge_character:
|
if edge_character:
|
||||||
|
|
@ -722,7 +738,7 @@ Command \"{cmdname}\" has no defined `func()` method. Available properties on th
|
||||||
else:
|
else:
|
||||||
center_string = ""
|
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)
|
remain_fill = width - len(center_string)
|
||||||
if remain_fill % 2 == 0:
|
if remain_fill % 2 == 0:
|
||||||
|
|
|
||||||
|
|
@ -1484,7 +1484,7 @@ class CmdName(ObjManipCommand):
|
||||||
obj = None
|
obj = None
|
||||||
if self.lhs_objs:
|
if self.lhs_objs:
|
||||||
objname = self.lhs_objs[0]["name"]
|
objname = self.lhs_objs[0]["name"]
|
||||||
if objname.startswith("*"):
|
if objname.startswith("*") and caller.account:
|
||||||
# account mode
|
# account mode
|
||||||
obj = caller.account.search(objname.lstrip("*"))
|
obj = caller.account.search(objname.lstrip("*"))
|
||||||
if obj:
|
if obj:
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,8 @@ class CmdNick(COMMAND_DEFAULT_CLASS):
|
||||||
|
|
||||||
if "clearall" in switches:
|
if "clearall" in switches:
|
||||||
caller.nicks.clear()
|
caller.nicks.clear()
|
||||||
caller.account.nicks.clear()
|
if caller.account:
|
||||||
|
caller.account.nicks.clear()
|
||||||
caller.msg("Cleared all nicks.")
|
caller.msg("Cleared all nicks.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -789,15 +790,18 @@ class CmdAccess(COMMAND_DEFAULT_CLASS):
|
||||||
hierarchy_full = settings.PERMISSION_HIERARCHY
|
hierarchy_full = settings.PERMISSION_HIERARCHY
|
||||||
string = "\n|wPermission Hierarchy|n (climbing):\n %s" % ", ".join(hierarchy_full)
|
string = "\n|wPermission Hierarchy|n (climbing):\n %s" % ", ".join(hierarchy_full)
|
||||||
|
|
||||||
if self.caller.account.is_superuser:
|
if caller.account and caller.account.is_superuser:
|
||||||
cperms = "<Superuser>"
|
cperms = "<Superuser>"
|
||||||
pperms = "<Superuser>"
|
pperms = "<Superuser>"
|
||||||
else:
|
else:
|
||||||
cperms = ", ".join(caller.permissions.all())
|
cperms = ", ".join(caller.permissions.all())
|
||||||
pperms = ", ".join(caller.account.permissions.all())
|
if caller.account:
|
||||||
|
pperms = ", ".join(caller.account.permissions.all())
|
||||||
|
else:
|
||||||
|
pperms = "<No account>"
|
||||||
|
|
||||||
string += "\n|wYour access|n:"
|
string += "\n|wYour access|n:"
|
||||||
string += f"\nCharacter |c{caller.key}|n: {cperms}"
|
string += f"\nCharacter |c{caller.key}|n: {cperms}"
|
||||||
if utils.inherits_from(caller, DefaultObject):
|
if utils.inherits_from(caller, DefaultObject) and caller.account:
|
||||||
string += f"\nAccount |c{caller.account.key}|n: {pperms}"
|
string += f"\nAccount |c{caller.account.key}|n: {pperms}"
|
||||||
caller.msg(string)
|
caller.msg(string)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue