Fixes to isTyping, CSS

This commit is contained in:
Griatch
2026-07-04 07:22:23 +02:00
parent 1a3e0721b9
commit aa0e19ed43
6 changed files with 41 additions and 23 deletions

View File

@ -166,15 +166,14 @@ class Command(metaclass=CommandMeta):
self.raw_string - the full raw string input, including the command name,
any args and no parsing.
self.client_live_report_typing - whether the client should report on the typing
status of a user while using a command.
defaults to false.
status of a user while using a command.
Defaults to False.
The following class properties can/should be defined on your child class:
key - identifier for command (e.g. "look")
aliases - (optional) list of aliases (e.g. ["l", "loo"])
locks - lock string (default is "cmd:all()")
help_category - how to organize this help entry in help system
(default is "General")
auto_help - defaults to True. Allows for turning off auto-help generation
@ -209,8 +208,8 @@ class Command(metaclass=CommandMeta):
is_exit = False
# define the command not only by key but by the regex form of its arguments
arg_regex = settings.COMMAND_DEFAULT_ARG_REGEX
# whether this command and its aliases should report on the typing status of the
# user.
# whether this command and its aliases should report on the typing status of the
# user.
client_live_report_typing = False
# whether self.msg sends to all sessions of a related account/object (default
# is to only send to the session sending the command).

View File

@ -30,12 +30,13 @@ def is_typing_get_audience_common_location(session, *args, **kwargs):
session: The player's current session.
"""
if session.puppet is None:
return []
puppet = session.puppet
if puppet is None or puppet.location is None:
return []
audience_including_typer = session.puppet.location.contents_get(content_type="character")
audience_including_typer = puppet.location.contents_get(content_type="character")
audience = [puppet for puppet in audience_including_typer if puppet.id != session.puppet.id]
audience = [obj for obj in audience_including_typer if obj.id != puppet.id]
return audience
@ -96,12 +97,10 @@ def is_typing_state(user_session, *args, **kwargs):
(defaults to same location).
Args:
session (Session): The player's current session.
user_session (Session): The player's current session.
**kwargs:
- state (bool): The typing state to broadcast.
"""
global audience_getter
options = user_session.protocol_flags
is_typing = options.get("ISTYPING", True)
@ -110,7 +109,7 @@ def is_typing_state(user_session, *args, **kwargs):
state = kwargs.get("state")
audience = audience_getter(session=user_session, args=args, kwargs=kwargs)
audience = audience_getter(user_session, *args, **kwargs)
# Filter out clients not interested in updates
relevant_sessions = [
@ -118,7 +117,7 @@ def is_typing_state(user_session, *args, **kwargs):
for puppet in audience
for puppet_session in puppet.sessions.all()
if puppet_session.protocol_flags.get("ISTYPING", True)
] # Potential timeout adjustment based on audience size
] # Potential timeout adjustment based on audience size
# Update relevant clients
for puppet_session in relevant_sessions:

View File

@ -333,7 +333,6 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, _BASE_SESSION_CLASS):
data = [_IDLE_COMMAND]
else:
data = _RE_LINEBREAK.split(data)
if len(data) > 2 and _HTTP_REGEX.match(data[0]):
# guard against HTTP request on the Telnet port; we
# block and kill the connection.

View File

@ -115,6 +115,18 @@ class TestIsTypingGetAudience(BaseEvenniaTest):
finally:
char3.delete()
def test_empty_when_puppet_has_no_location(self):
"""Audience is empty (no crash) when the puppet has no location."""
self.char1.location = None
audience = is_typing_get_audience_common_location(self.session)
self.assertEqual(audience, [])
def test_empty_when_no_puppet(self):
"""Audience is empty when the session has no puppet."""
self.session.puppet = None
audience = is_typing_get_audience_common_location(self.session)
self.assertEqual(audience, [])
# ---------------------------------------------------------------------------
# is_typing_setup

View File

@ -346,14 +346,21 @@ div {margin:0px;}
text-decoration: underline;
}
/* Typing indicator. Docked bottom-left (opposite the top-right #toolbar) and
anchored to the viewport so it survives GoldenLayout's pane rebuilds. */
#istyping {
position: absolute;
top: 5px;
right: 5px;
width: auto;
height: auto;
position: fixed;
left: .5rem;
bottom: 3rem;
z-index: 5;
max-width: 40%;
max-height: 30%;
overflow-y: auto;
display: none;
padding: .25rem .5rem;
color: white;
background-color: rgba(0, 0, 0, 0.6);
border-radius: .25rem;
}
#istypingdivider {

View File

@ -18,13 +18,15 @@ let is_typing = (function (){
const createDialog = function() {
const ele =[
'<div id="istyping" class="content">',
'<h5>Who\'s typing?</h4>',
'<h5>Who\'s typing?</h5>',
'<hr id="istypingdivider" />',
'<div id="typingplayers"></div>',
'</div>'
].join('\n')
$('#messagewindow').append(ele)
// Append to <body> (as popups.js does) so the indicator survives
// GoldenLayout rebuilding the message/input panes at runtime.
$('body').append(ele)
}
const playerElement =(name)=> `<div id="istyping-${name}" class="player-is-typing">${name}</div>`
@ -265,4 +267,4 @@ let is_typing = (function (){
}
})()
window.plugin_handler.add("is_typing", is_typing)
window.plugin_handler.add("is_typing", is_typing)