Merge pull request #3502 from chiizujin/sethelp_locks

Add sethelp/locks command
This commit is contained in:
Griatch 2024-04-27 19:44:40 +02:00 committed by GitHub
commit 079f573d21
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -17,6 +17,7 @@ from django.conf import settings
from evennia.help.filehelp import FILE_HELP_ENTRIES from evennia.help.filehelp import FILE_HELP_ENTRIES
from evennia.help.models import HelpEntry from evennia.help.models import HelpEntry
from evennia.help.utils import help_search_with_index, parse_entry_for_subcategories from evennia.help.utils import help_search_with_index, parse_entry_for_subcategories
from evennia.locks.lockhandler import LockException
from evennia.utils import create, evmore from evennia.utils import create, evmore
from evennia.utils.ansi import ANSIString from evennia.utils.ansi import ANSIString
from evennia.utils.eveditor import EvEditor from evennia.utils.eveditor import EvEditor
@ -781,13 +782,14 @@ class CmdSetHelp(CmdHelp):
Usage: Usage:
sethelp[/switches] <topic>[[;alias;alias][,category[,locks]] sethelp[/switches] <topic>[[;alias;alias][,category[,locks]]
[= <text or new category>] [= <text or new value>]
Switches: Switches:
edit - open a line editor to edit the topic's help text. edit - open a line editor to edit the topic's help text.
replace - overwrite existing help topic. replace - overwrite existing help topic.
append - add text to the end of existing topic with a newline between. append - add text to the end of existing topic with a newline between.
extend - as append, but don't add a newline. extend - as append, but don't add a newline.
category - change category of existing help topic. category - change category of existing help topic.
locks - change locks of existing help topic.
delete - remove help topic. delete - remove help topic.
Examples: Examples:
@ -795,6 +797,7 @@ class CmdSetHelp(CmdHelp):
sethelp/append pickpocketing,Thievery = This steals ... sethelp/append pickpocketing,Thievery = This steals ...
sethelp/replace pickpocketing, ,attr(is_thief) = This steals ... sethelp/replace pickpocketing, ,attr(is_thief) = This steals ...
sethelp/edit thievery sethelp/edit thievery
sethelp/locks thievery = read:all()
sethelp/category thievery = classes sethelp/category thievery = classes
If not assigning a category, the `settings.DEFAULT_HELP_CATEGORY` category If not assigning a category, the `settings.DEFAULT_HELP_CATEGORY` category
@ -842,7 +845,7 @@ class CmdSetHelp(CmdHelp):
key = "sethelp" key = "sethelp"
aliases = [] aliases = []
switch_options = ("edit", "replace", "append", "extend", "category", "delete") switch_options = ("edit", "replace", "append", "extend", "category", "locks", "delete")
locks = "cmd:perm(Helper)" locks = "cmd:perm(Helper)"
help_category = "Building" help_category = "Building"
arg_regex = None arg_regex = None
@ -856,6 +859,7 @@ class CmdSetHelp(CmdHelp):
switches = self.switches switches = self.switches
lhslist = self.lhslist lhslist = self.lhslist
rhslist = self.rhslist
if not self.args: if not self.args:
self.msg( self.msg(
@ -1011,6 +1015,35 @@ class CmdSetHelp(CmdHelp):
self.msg(f"Category for entry '{topicstr}'{aliastxt} changed to '{category}'.") self.msg(f"Category for entry '{topicstr}'{aliastxt} changed to '{category}'.")
return return
if "locks" in switches:
# set the locks
if not old_entry:
self.msg(f"Could not find topic '{topicstr}'{aliastxt}.")
return
show_locks = not rhslist
clear_locks = rhslist and not rhslist[0]
if show_locks:
self.msg(f"Current locks for entry '{topicstr}'{aliastxt} are: {old_entry.locks}")
return
if clear_locks:
old_entry.locks.clear()
old_entry.locks.add("read:all()")
self.msg(f"Locks for entry '{topicstr}'{aliastxt} reset to: read:all()")
return
lockstring = ",".join(rhslist)
# locks.validate() does not throw an exception for things like "read:id(1),read:id(6)"
# but locks.add() does
existing_locks = old_entry.locks.all()
old_entry.locks.clear()
try:
old_entry.locks.add(lockstring)
except LockException as e:
old_entry.locks.add(existing_locks)
self.msg(str(e) + " Locks not changed.")
else:
self.msg(f"Locks for entry '{topicstr}'{aliastxt} changed to: {lockstring}")
return
if "delete" in switches or "del" in switches: if "delete" in switches or "del" in switches:
# delete the help entry # delete the help entry
if not old_entry: if not old_entry: