Add useful hooks for the say and whisper commands #1288
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Brief overview of PR changes/additions
The say and whisper commands now have hooks to control and display messages, which makes updating the behavior of these commands quite simple without overriding them.
Motivation for adding to Evennia
The say command already used a hook: this hook,
object.at_say, was called before the say and was used to change the content of the message to be displayed. However, it didn't allow to display the content in another format. Moreover, it used%ssymbols instead of relying on mappings, which meant it didn't useget_display_nameon objects.There's now two different hooks for the say command:
object.at_before_say: it can be used much likeobject.location.at_say(notice that this change invalids the latterat_sayhook). It can be used to modify the text to be said in the location. It can also prevent the say by returning a None value.object.at_after_say: this hook is responsible for displaying the said message in the location. The say command doesn't do anything but calling these hooks, which means changing the format of the say command is quite easy without re-writing the say command. This second hook allows for simple overriding of messages to display, mapping (withget_display_name) and simple extensions by users' sub-classing.The whisper command adds these two hooks on objects too, since it didn't use any hook at all.
A warning on compatibility
This PR breaks compatibility of the
at_sayhook. The hook isn't used anymore. Beforehand, it was used on the location (that is, more likely than not, on the room of the character speaking). This, however, didn't seem to allow the greatest flexibility, and theat_before_sayhook, like theat_after_sayone, are put on the object speaking, not on its location.Therefore, there's a deprecated warning in the
at_sayhook. I'm not sure whether it should be removed or simply re-mapped toat_before_say. If the latter, then it can be somewhat misleading to users, because they don't do the exact same thing, but it depends on Evennia's policy on hook compatibility.