Skip to content

Commit 9695e58

Browse files
committed
Handle case where no filters are loaded
1 parent 416454a commit 9695e58

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

cloudbot/clients/irc.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from cloudbot.client import Client
99
from cloudbot.event import Event, EventType, IrcOutEvent
10+
from cloudbot.util.parsers.irc import Message
1011

1112
logger = logging.getLogger("cloudbot")
1213

@@ -288,18 +289,37 @@ def send(self, line):
288289
if not self._connected:
289290
yield from self._connected_future
290291

292+
old_line = line
293+
filtered = bool(self.bot.plugin_manager.out_sieves)
294+
291295
for out_sieve in self.bot.plugin_manager.out_sieves:
292-
event = IrcOutEvent(bot=self.bot, hook=out_sieve, conn=self.conn, irc_raw=line)
296+
event = IrcOutEvent(
297+
bot=self.bot, hook=out_sieve, conn=self.conn, irc_raw=line
298+
)
299+
293300
ok, new_line = yield from self.bot.plugin_manager.internal_launch(out_sieve, event)
294301
if not ok:
295-
logger.warning("Error occurred in outgoing sieve, not sending line")
302+
logger.warning("Error occurred in outgoing sieve, falling back to old behavior")
296303
logger.debug("Line was: %s", line)
297-
return
304+
filtered = False
305+
break
298306

299307
line = new_line
308+
if line is not None and not isinstance(line, bytes):
309+
line = str(line)
310+
300311
if not line:
301312
return
302313

314+
if not filtered:
315+
# No outgoing sieves loaded or one of the sieves errored, fall back to old behavior
316+
line = old_line[:510] + "\r\n"
317+
line = line.encode("utf-8", "replace")
318+
319+
if not isinstance(line, bytes):
320+
# the line must be encoded before we send it, one of the sieves didn't encode it, fall back to the default
321+
line = line.encode("utf-8", "replace")
322+
303323
self._transport.write(line)
304324

305325
def data_received(self, data):

0 commit comments

Comments
 (0)