mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
bot_lib: Raise exception when PM recipient list is empty.
We need to explicitly check for empty recipient lists in send_message to ensure that internal_send_huddle_message doesn't call Addressee.for_private with an empty recipient list.
This commit is contained in:
@@ -15,6 +15,8 @@ from zerver.lib.bot_config import get_bot_config, ConfigError
|
||||
from zerver.lib.integrations import EMBEDDED_BOTS
|
||||
from zerver.lib.topic import get_topic_from_message_info
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
import configparser
|
||||
|
||||
from mypy_extensions import NoReturn
|
||||
@@ -60,6 +62,9 @@ class StateHandler:
|
||||
class EmbeddedBotQuitException(Exception):
|
||||
pass
|
||||
|
||||
class EmbeddedBotEmptyRecipientsList(Exception):
|
||||
pass
|
||||
|
||||
class EmbeddedBotHandler:
|
||||
def __init__(self, user_profile: UserProfile) -> None:
|
||||
# Only expose a subset of our UserProfile's functionality
|
||||
@@ -84,7 +89,9 @@ class EmbeddedBotHandler:
|
||||
# usual 'to' field could be either a List[str] or a str.
|
||||
recipients = ','.join(message['to']).split(',')
|
||||
|
||||
if len(message['to']) == 1:
|
||||
if len(message['to']) == 0:
|
||||
raise EmbeddedBotEmptyRecipientsList(_('Message must have recipients!'))
|
||||
elif len(message['to']) == 1:
|
||||
recipient_user = get_active_user(recipients[0], self.user_profile.realm)
|
||||
internal_send_private_message(self.user_profile.realm, self.user_profile,
|
||||
recipient_user, message['content'])
|
||||
|
||||
Reference in New Issue
Block a user