Update admin.py
Extend and fix fstring usage.
This commit is contained in:
parent
bf6eeb288f
commit
f58354ce23
1 changed files with 31 additions and 37 deletions
|
|
@ -76,12 +76,11 @@ class CmdBoot(COMMAND_DEFAULT_CLASS):
|
||||||
# Boot by account object
|
# Boot by account object
|
||||||
pobj = search.account_search(args)
|
pobj = search.account_search(args)
|
||||||
if not pobj:
|
if not pobj:
|
||||||
caller.msg("Account %s was not found." % args)
|
caller.msg(f"Account {args} was not found.")
|
||||||
return
|
return
|
||||||
pobj = pobj[0]
|
pobj = pobj[0]
|
||||||
if not pobj.access(caller, "boot"):
|
if not pobj.access(caller, "boot"):
|
||||||
string = "You don't have the permission to boot %s." % (pobj.key,)
|
caller.msg(f"You don't have the permission to boot {pobj.key,}.")
|
||||||
caller.msg(string)
|
|
||||||
return
|
return
|
||||||
# we have a bootable object with a connected user
|
# we have a bootable object with a connected user
|
||||||
matches = SESSIONS.sessions_from_account(pobj)
|
matches = SESSIONS.sessions_from_account(pobj)
|
||||||
|
|
@ -96,9 +95,9 @@ class CmdBoot(COMMAND_DEFAULT_CLASS):
|
||||||
|
|
||||||
feedback = None
|
feedback = None
|
||||||
if "quiet" not in self.switches:
|
if "quiet" not in self.switches:
|
||||||
feedback = "You have been disconnected by %s.\n" % caller.name
|
feedback = f"You have been disconnected by {caller.name}.\n"
|
||||||
if reason:
|
if reason:
|
||||||
feedback += "\nReason given: %s" % reason
|
feedback += "f\nReason given: {reason}"
|
||||||
|
|
||||||
for session in boot_list:
|
for session in boot_list:
|
||||||
session.msg(feedback)
|
session.msg(feedback)
|
||||||
|
|
@ -106,8 +105,7 @@ class CmdBoot(COMMAND_DEFAULT_CLASS):
|
||||||
|
|
||||||
if pobj and boot_list:
|
if pobj and boot_list:
|
||||||
logger.log_sec(
|
logger.log_sec(
|
||||||
"Booted: %s (Reason: %s, Caller: %s, IP: %s)."
|
f"Booted: {pobj} (Reason: {reason}, Caller: {caller}, IP: {self.session.address})."
|
||||||
% (pobj, reason, caller, self.session.address)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -130,7 +128,7 @@ def list_bans(cmd, banlist):
|
||||||
table = cmd.styled_table("|wid", "|wname/ip", "|wdate", "|wreason")
|
table = cmd.styled_table("|wid", "|wname/ip", "|wdate", "|wreason")
|
||||||
for inum, ban in enumerate(banlist):
|
for inum, ban in enumerate(banlist):
|
||||||
table.add_row(str(inum + 1), ban[0] and ban[0] or ban[1], ban[3], ban[4])
|
table.add_row(str(inum + 1), ban[0] and ban[0] or ban[1], ban[3], ban[4])
|
||||||
return "|wActive bans:|n\n%s" % table
|
return f"|wActive bans:|n\n{table}"
|
||||||
|
|
||||||
|
|
||||||
class CmdBan(COMMAND_DEFAULT_CLASS):
|
class CmdBan(COMMAND_DEFAULT_CLASS):
|
||||||
|
|
@ -227,7 +225,7 @@ class CmdBan(COMMAND_DEFAULT_CLASS):
|
||||||
ServerConfig.objects.conf("server_bans", banlist)
|
ServerConfig.objects.conf("server_bans", banlist)
|
||||||
self.caller.msg(f"{typ}-ban '|w{ban}|n' was added. Use |wunban|n to reinstate.")
|
self.caller.msg(f"{typ}-ban '|w{ban}|n' was added. Use |wunban|n to reinstate.")
|
||||||
logger.log_sec(
|
logger.log_sec(
|
||||||
"Banned {typ}: {ban.strip()} (Caller: {self.caller}, IP: {self.session.address})."
|
f"Banned {typ}: {ban.strip()} (Caller: {self.caller}, IP: {self.session.address})."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -267,7 +265,7 @@ class CmdUnban(COMMAND_DEFAULT_CLASS):
|
||||||
if not banlist:
|
if not banlist:
|
||||||
self.caller.msg("There are no bans to clear.")
|
self.caller.msg("There are no bans to clear.")
|
||||||
elif not (0 < num < len(banlist) + 1):
|
elif not (0 < num < len(banlist) + 1):
|
||||||
self.caller.msg("Ban id |w%s|x was not found." % self.args)
|
self.caller.msg(f"Ban id |w{self.args}|n was not found.")
|
||||||
else:
|
else:
|
||||||
# all is ok, ask, then clear ban
|
# all is ok, ask, then clear ban
|
||||||
ban = banlist[num - 1]
|
ban = banlist[num - 1]
|
||||||
|
|
@ -282,7 +280,7 @@ class CmdUnban(COMMAND_DEFAULT_CLASS):
|
||||||
ServerConfig.objects.conf("server_bans", banlist)
|
ServerConfig.objects.conf("server_bans", banlist)
|
||||||
self.caller.msg(f"Cleared ban {num}: '{value}'")
|
self.caller.msg(f"Cleared ban {num}: '{value}'")
|
||||||
logger.log_sec(
|
logger.log_sec(
|
||||||
"Unbanned: {value.strip()} (Caller: {self.caller}, IP: {self.session.address})."
|
f"Unbanned: {value.strip()} (Caller: {self.caller}, IP: {self.session.address})."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -351,20 +349,20 @@ class CmdEmit(COMMAND_DEFAULT_CLASS):
|
||||||
if not obj:
|
if not obj:
|
||||||
return
|
return
|
||||||
if rooms_only and obj.location is not None:
|
if rooms_only and obj.location is not None:
|
||||||
caller.msg("%s is not a room. Ignored." % objname)
|
caller.msg(f"{objname} is not a room. Ignored.")
|
||||||
continue
|
continue
|
||||||
if accounts_only and not obj.has_account:
|
if accounts_only and not obj.has_account:
|
||||||
caller.msg("%s has no active account. Ignored." % objname)
|
caller.msg(f"{objname} has no active account. Ignored.")
|
||||||
continue
|
continue
|
||||||
if obj.access(caller, "tell"):
|
if obj.access(caller, "tell"):
|
||||||
obj.msg(message)
|
obj.msg(message)
|
||||||
if send_to_contents and hasattr(obj, "msg_contents"):
|
if send_to_contents and hasattr(obj, "msg_contents"):
|
||||||
obj.msg_contents(message)
|
obj.msg_contents(message)
|
||||||
caller.msg("Emitted to %s and contents:\n%s" % (objname, message))
|
caller.msg(f"Emitted to {objname} and contents:\n{message}")
|
||||||
else:
|
else:
|
||||||
caller.msg("Emitted to %s:\n%s" % (objname, message))
|
caller.msg(f"Emitted to {objname}:\n{message}")
|
||||||
else:
|
else:
|
||||||
caller.msg("You are not allowed to emit to %s." % objname)
|
caller.msg(f"You are not allowed to emit to {objname}.")
|
||||||
|
|
||||||
|
|
||||||
class CmdNewPassword(COMMAND_DEFAULT_CLASS):
|
class CmdNewPassword(COMMAND_DEFAULT_CLASS):
|
||||||
|
|
@ -407,11 +405,11 @@ class CmdNewPassword(COMMAND_DEFAULT_CLASS):
|
||||||
|
|
||||||
account.set_password(newpass)
|
account.set_password(newpass)
|
||||||
account.save()
|
account.save()
|
||||||
self.msg("%s - new password set to '%s'." % (account.name, newpass))
|
self.msg(f"{account.name} - new password set to '{new pass}'.")
|
||||||
if account.character != caller:
|
if account.character != caller:
|
||||||
account.msg("%s has changed your password to '%s'." % (caller.name, newpass))
|
account.msg(f"{caller.name} has changed your password to '{newpass}'.")
|
||||||
logger.log_sec(
|
logger.log_sec(
|
||||||
"Password Changed: %s (Caller: %s, IP: %s)." % (account, caller, self.session.address)
|
f"Password Changed: {account} (Caller: {caller}, IP: {self.session.address})."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -464,7 +462,7 @@ class CmdPerm(COMMAND_DEFAULT_CLASS):
|
||||||
caller.msg("You are not allowed to examine this object.")
|
caller.msg("You are not allowed to examine this object.")
|
||||||
return
|
return
|
||||||
|
|
||||||
string = "Permissions on |w%s|n: " % obj.key
|
string = f"Permissions on |{obj.key}s|n: "
|
||||||
if not obj.permissions.all():
|
if not obj.permissions.all():
|
||||||
string += "<None>"
|
string += "<None>"
|
||||||
else:
|
else:
|
||||||
|
|
@ -483,8 +481,7 @@ class CmdPerm(COMMAND_DEFAULT_CLASS):
|
||||||
locktype = "edit" if accountmode else "control"
|
locktype = "edit" if accountmode else "control"
|
||||||
if not obj.access(caller, locktype):
|
if not obj.access(caller, locktype):
|
||||||
caller.msg(
|
caller.msg(
|
||||||
"You are not allowed to edit this %s's permissions."
|
f"You are not allowed to edit this {'account' if accountmode else 'object'}'s permissions."
|
||||||
% ("account" if accountmode else "object")
|
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -496,18 +493,17 @@ class CmdPerm(COMMAND_DEFAULT_CLASS):
|
||||||
obj.permissions.remove(perm)
|
obj.permissions.remove(perm)
|
||||||
if obj.permissions.get(perm):
|
if obj.permissions.get(perm):
|
||||||
caller_result.append(
|
caller_result.append(
|
||||||
"\nPermissions %s could not be removed from %s." % (perm, obj.name)
|
f"\nPermissions {perm} could not be removed from {obj.name}."
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
caller_result.append(
|
caller_result.append(
|
||||||
"\nPermission %s removed from %s (if they existed)." % (perm, obj.name)
|
f"\nPermission {perm} removed from {obj.name} (if they existed)."
|
||||||
)
|
)
|
||||||
target_result.append(
|
target_result.append(
|
||||||
"\n%s revokes the permission(s) %s from you." % (caller.name, perm)
|
f"\n{caller.name} revokes the permission(s) {perm} from you."
|
||||||
)
|
)
|
||||||
logger.log_sec(
|
logger.log_sec(
|
||||||
"Permissions Deleted: %s, %s (Caller: %s, IP: %s)."
|
f"Permissions Deleted: {perm}, {obj} (Caller: {caller}, IP: {self.session.address})."
|
||||||
% (perm, obj, caller, self.session.address)
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# add a new permission
|
# add a new permission
|
||||||
|
|
@ -518,7 +514,7 @@ class CmdPerm(COMMAND_DEFAULT_CLASS):
|
||||||
# don't allow to set a permission higher in the hierarchy than
|
# don't allow to set a permission higher in the hierarchy than
|
||||||
# the one the caller has (to prevent self-escalation)
|
# the one the caller has (to prevent self-escalation)
|
||||||
if perm.lower() in PERMISSION_HIERARCHY and not obj.locks.check_lockstring(
|
if perm.lower() in PERMISSION_HIERARCHY and not obj.locks.check_lockstring(
|
||||||
caller, "dummy:perm(%s)" % perm
|
caller, f"dummy:perm({perm})"
|
||||||
):
|
):
|
||||||
caller.msg(
|
caller.msg(
|
||||||
"You cannot assign a permission higher than the one you have yourself."
|
"You cannot assign a permission higher than the one you have yourself."
|
||||||
|
|
@ -527,21 +523,19 @@ class CmdPerm(COMMAND_DEFAULT_CLASS):
|
||||||
|
|
||||||
if perm in permissions:
|
if perm in permissions:
|
||||||
caller_result.append(
|
caller_result.append(
|
||||||
"\nPermission '%s' is already defined on %s." % (perm, obj.name)
|
f"\nPermission '{perm}' is already defined on {obj.name}."
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
obj.permissions.add(perm)
|
obj.permissions.add(perm)
|
||||||
plystring = "the Account" if accountmode else "the Object/Character"
|
plystring = "the Account" if accountmode else "the Object/Character"
|
||||||
caller_result.append(
|
caller_result.append(
|
||||||
"\nPermission '%s' given to %s (%s)." % (perm, obj.name, plystring)
|
f"\nPermission '{perm}' given to {obj.name} ({plystring})."
|
||||||
)
|
)
|
||||||
target_result.append(
|
target_result.append(
|
||||||
"\n%s gives you (%s, %s) the permission '%s'."
|
f"\n{caller.name} gives you ({obj.name}, {plystring}) the permission '{perm}'."
|
||||||
% (caller.name, obj.name, plystring, perm)
|
|
||||||
)
|
)
|
||||||
logger.log_sec(
|
logger.log_sec(
|
||||||
"Permissions Added: %s, %s (Caller: %s, IP: %s)."
|
f"Permissions Added: {perm}, {obj} (Caller: {caller}, IP: {self.session.address})."
|
||||||
% (obj, perm, caller, self.session.address)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
caller.msg("".join(caller_result).strip())
|
caller.msg("".join(caller_result).strip())
|
||||||
|
|
@ -569,7 +563,7 @@ class CmdWall(COMMAND_DEFAULT_CLASS):
|
||||||
if not self.args:
|
if not self.args:
|
||||||
self.caller.msg("Usage: wall <message>")
|
self.caller.msg("Usage: wall <message>")
|
||||||
return
|
return
|
||||||
message = '%s shouts "%s"' % (self.caller.name, self.args)
|
message = f'{self.caller.name} shouts "{self.args}"'
|
||||||
self.msg("Announcing to all connected sessions ...")
|
self.msg("Announcing to all connected sessions ...")
|
||||||
SESSIONS.announce_all(message)
|
SESSIONS.announce_all(message)
|
||||||
|
|
||||||
|
|
@ -599,7 +593,7 @@ class CmdForce(COMMAND_DEFAULT_CLASS):
|
||||||
if not targ:
|
if not targ:
|
||||||
return
|
return
|
||||||
if not targ.access(self.caller, self.perm_used):
|
if not targ.access(self.caller, self.perm_used):
|
||||||
self.caller.msg("You don't have permission to force them to execute commands.")
|
self.caller.msg(f"You don't have permission to force {targ} to execute commands.")
|
||||||
return
|
return
|
||||||
targ.execute_cmd(self.rhs)
|
targ.execute_cmd(self.rhs)
|
||||||
self.caller.msg("You have forced %s to: %s" % (targ, self.rhs))
|
self.caller.msg(f"You have forced {targ} to: {self.rhs}")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue