Allow sending channel message without = for non-space targets
This commit is contained in:
parent
858d00c853
commit
43651ac867
2 changed files with 55 additions and 27 deletions
|
|
@ -135,8 +135,8 @@ class CmdChannel(COMMAND_DEFAULT_CLASS):
|
||||||
|
|
||||||
if handle_errors:
|
if handle_errors:
|
||||||
if not channels:
|
if not channels:
|
||||||
self.msk(f"No channel found matching '{channelname}' "
|
self.msg(f"No channel found matching '{channelname}' "
|
||||||
"could also be due to missing access).")
|
"(could also be due to missing access).")
|
||||||
return None
|
return None
|
||||||
elif len(channels) > 1:
|
elif len(channels) > 1:
|
||||||
self.msg("Multiple possible channel matches/alias for "
|
self.msg("Multiple possible channel matches/alias for "
|
||||||
|
|
@ -701,7 +701,6 @@ class CmdChannel(COMMAND_DEFAULT_CLASS):
|
||||||
|
|
||||||
#from evennia import set_trace;set_trace()
|
#from evennia import set_trace;set_trace()
|
||||||
|
|
||||||
if not channel_names:
|
|
||||||
if 'all' in switches:
|
if 'all' in switches:
|
||||||
# show all available channels
|
# show all available channels
|
||||||
subscribed, available = self.list_channels()
|
subscribed, available = self.list_channels()
|
||||||
|
|
@ -711,7 +710,8 @@ class CmdChannel(COMMAND_DEFAULT_CLASS):
|
||||||
"\n|wAvailable channels|n (use /list to "
|
"\n|wAvailable channels|n (use /list to "
|
||||||
f"only show subscriptions)\n{table}")
|
f"only show subscriptions)\n{table}")
|
||||||
return
|
return
|
||||||
else:
|
|
||||||
|
if not channel_names:
|
||||||
# (empty or /list) show only subscribed channels
|
# (empty or /list) show only subscribed channels
|
||||||
subscribed, _ = self.list_channels()
|
subscribed, _ = self.list_channels()
|
||||||
table = self.display_subbed_channels(subscribed)
|
table = self.display_subbed_channels(subscribed)
|
||||||
|
|
@ -754,14 +754,34 @@ class CmdChannel(COMMAND_DEFAULT_CLASS):
|
||||||
self.msg(err)
|
self.msg(err)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
possible_lhs_message = ""
|
||||||
|
if not self.rhs and self.args and " " in self.args:
|
||||||
|
# since we want to support messaging with `channel name text` (for
|
||||||
|
# channels without a space in their name), we need to check if the
|
||||||
|
# first 'channel name' is in fact 'channelname text'
|
||||||
|
no_rhs_channel_name = self.args.split(" ", 1)[0]
|
||||||
|
possible_lhs_message = self.args[len(no_rhs_channel_name):]
|
||||||
|
channel_names.append(no_rhs_channel_name)
|
||||||
|
|
||||||
|
|
||||||
channels = []
|
channels = []
|
||||||
|
errors = []
|
||||||
for channel_name in channel_names:
|
for channel_name in channel_names:
|
||||||
# find a channel by fuzzy-matching. This also checks
|
# find a channel by fuzzy-matching. This also checks
|
||||||
# 'listen/control' perms.
|
# 'listen/control' perms.
|
||||||
channel = self.search_channel(channel_name, exact=False)
|
found_channels = self.search_channel(channel_name, exact=False, handle_errors=False)
|
||||||
if not channel:
|
if not found_channels:
|
||||||
|
errors.append(f"No channel found matching '{channel_name}' "
|
||||||
|
"(could also be due to missing access).")
|
||||||
|
elif len(found_channels) > 1:
|
||||||
|
errors.append("Multiple possible channel matches/alias for "
|
||||||
|
"'{channel_name}':\n" + ", ".join(chan.key for chan in found_channels))
|
||||||
|
else:
|
||||||
|
channels.append(found_channels[0])
|
||||||
|
|
||||||
|
if not channels:
|
||||||
|
self.msg('\n'.join(errors))
|
||||||
return
|
return
|
||||||
channels.append(channel)
|
|
||||||
|
|
||||||
# we have at least one channel at this point
|
# we have at least one channel at this point
|
||||||
channel = channels[0]
|
channel = channels[0]
|
||||||
|
|
@ -770,6 +790,9 @@ class CmdChannel(COMMAND_DEFAULT_CLASS):
|
||||||
if self.rhs:
|
if self.rhs:
|
||||||
# send message to channel
|
# send message to channel
|
||||||
self.msg_channel(channel, self.rhs.strip())
|
self.msg_channel(channel, self.rhs.strip())
|
||||||
|
elif channel and possible_lhs_message:
|
||||||
|
# called on the form channelname message without =
|
||||||
|
self.msg_channel(channel, possible_lhs_message.strip())
|
||||||
else:
|
else:
|
||||||
# inspect a given channel
|
# inspect a given channel
|
||||||
subscribed, available = self.list_channels()
|
subscribed, available = self.list_channels()
|
||||||
|
|
@ -1215,6 +1238,7 @@ class CmdAllCom(CmdChannel):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = "allcom"
|
key = "allcom"
|
||||||
|
aliases = [] # important to not inherit parent's aliases
|
||||||
locks = "cmd: not pperm(channel_banned)"
|
locks = "cmd: not pperm(channel_banned)"
|
||||||
help_category = "Comms"
|
help_category = "Comms"
|
||||||
|
|
||||||
|
|
@ -1286,6 +1310,7 @@ class CmdCdestroy(CmdChannel):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = "cdestroy"
|
key = "cdestroy"
|
||||||
|
aliases = []
|
||||||
help_category = "Comms"
|
help_category = "Comms"
|
||||||
locks = "cmd: not pperm(channel_banned)"
|
locks = "cmd: not pperm(channel_banned)"
|
||||||
|
|
||||||
|
|
@ -1334,6 +1359,7 @@ class CmdCBoot(CmdChannel):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = "cboot"
|
key = "cboot"
|
||||||
|
aliases = []
|
||||||
switch_options = ("quiet",)
|
switch_options = ("quiet",)
|
||||||
locks = "cmd: not pperm(channel_banned)"
|
locks = "cmd: not pperm(channel_banned)"
|
||||||
help_category = "Comms"
|
help_category = "Comms"
|
||||||
|
|
@ -1394,6 +1420,7 @@ class CmdCWho(CmdChannel):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = "cwho"
|
key = "cwho"
|
||||||
|
aliases = []
|
||||||
locks = "cmd: not pperm(channel_banned)"
|
locks = "cmd: not pperm(channel_banned)"
|
||||||
help_category = "Comms"
|
help_category = "Comms"
|
||||||
|
|
||||||
|
|
@ -1475,8 +1502,8 @@ class CmdClock(CmdChannel):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = "clock"
|
key = "clock"
|
||||||
locks = "cmd:not pperm(channel_banned)"
|
|
||||||
aliases = ["clock"]
|
aliases = ["clock"]
|
||||||
|
locks = "cmd:not pperm(channel_banned)"
|
||||||
help_category = "Comms"
|
help_category = "Comms"
|
||||||
|
|
||||||
# this is used by the COMMAND_DEFAULT_CLASS parent
|
# this is used by the COMMAND_DEFAULT_CLASS parent
|
||||||
|
|
@ -1523,6 +1550,7 @@ class CmdCdesc(CmdChannel):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = "cdesc"
|
key = "cdesc"
|
||||||
|
aliases = []
|
||||||
locks = "cmd:not pperm(channel_banned)"
|
locks = "cmd:not pperm(channel_banned)"
|
||||||
help_category = "Comms"
|
help_category = "Comms"
|
||||||
|
|
||||||
|
|
@ -1562,9 +1590,9 @@ class CmdPage(COMMAND_DEFAULT_CLASS):
|
||||||
last - shows who you last messaged
|
last - shows who you last messaged
|
||||||
list - show your last <number> of tells/pages (default)
|
list - show your last <number> of tells/pages (default)
|
||||||
|
|
||||||
Send a message to target user (if online). If no argument is given, you will
|
Send a message to target user (if online). If no argument is given, you
|
||||||
get a list of your latest messages. The equal sign is needed for multiple
|
will get a list of your latest messages. The equal sign is needed for
|
||||||
targets or if sending to target with space in the name.
|
multiple targets or if sending to target with space in the name.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -1616,6 +1644,7 @@ class CmdPage(COMMAND_DEFAULT_CLASS):
|
||||||
if target_obj:
|
if target_obj:
|
||||||
# a proper target
|
# a proper target
|
||||||
targets = [target_obj[0]]
|
targets = [target_obj[0]]
|
||||||
|
message = message[0].strip()
|
||||||
else:
|
else:
|
||||||
# a message with a space in it - put it back together
|
# a message with a space in it - put it back together
|
||||||
message = target + " " + (message[0] if message else "")
|
message = target + " " + (message[0] if message else "")
|
||||||
|
|
|
||||||
|
|
@ -445,7 +445,6 @@ class DefaultChannel(ChannelDB, metaclass=TypeclassBase):
|
||||||
for receiver in receivers:
|
for receiver in receivers:
|
||||||
# send to each individual subscriber
|
# send to each individual subscriber
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
message = receiver.at_pre_channel_msg(message, self, **send_kwargs)
|
message = receiver.at_pre_channel_msg(message, self, **send_kwargs)
|
||||||
if message in (None, False):
|
if message in (None, False):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue