Skip to content

Commit 499f5b6

Browse files
committed
Implement multiple response messages with \n splitting
Purposefully only works for up to three messages.
1 parent 6741381 commit 499f5b6

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

messages.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ def message_handler(self, data):
123123
data["user_name"], "Please stop posting links.",
124124
method="whisper")
125125

126-
if parsed[0].startswith("!") and len(parsed) > 1:
126+
if len(parsed) > 1 and parsed[0].startswith("!"):
127127
args = parsed.split()
128128

129129
if args[0][1:] in self.commands:
130130
response = self.commands[args[0][1:]]
131131
if isinstance(response, str):
132-
message = response
132+
messages = response
133133
else:
134-
message = response(args, data)
134+
messages = response(args, data)
135135
else:
136136
options = [
137137
('-'.join(args[:2])[1:], ['-'.join(args[:2])] + args[2:]),
@@ -142,19 +142,23 @@ def message_handler(self, data):
142142
command = session.query(
143143
Command).filter_by(command=parse_method[0]).first()
144144
if command:
145-
message = command(
145+
messages = command(
146146
parse_method[1], data,
147147
channel_name=self.channel_data["token"]
148148
)
149149
break
150150
else:
151-
message = "Command not found."
151+
messages = "Command not found."
152+
153+
if isinstance(messages, str):
154+
messages = (messages,)
152155

153156
if data["message"]["meta"].get("whisper", False):
154-
return self.send_message(
155-
data["user_name"], message, method="whisper")
157+
for message in messages:
158+
self.send_message(
159+
data["user_name"], message, method="whisper")
156160
else:
157-
return self.send_message(message)
161+
self.send_message(*messages)
158162

159163
def join_handler(self, data):
160164
"""Handle user join packets from Beam."""

models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def run_command(self, args, data, channel_name=None):
9595
channel_name if channel_name else data["id"]
9696
)
9797

98-
return response
98+
return response.split('\\n', 2)
9999

100100
return run_command(self, args, data, **kwargs)
101101

0 commit comments

Comments
 (0)