|
7 | 7 |
|
8 | 8 | from cloudbot.client import Client |
9 | 9 | from cloudbot.event import Event, EventType, IrcOutEvent |
| 10 | +from cloudbot.util.parsers.irc import Message |
10 | 11 |
|
11 | 12 | logger = logging.getLogger("cloudbot") |
12 | 13 |
|
@@ -288,18 +289,37 @@ def send(self, line): |
288 | 289 | if not self._connected: |
289 | 290 | yield from self._connected_future |
290 | 291 |
|
| 292 | + old_line = line |
| 293 | + filtered = bool(self.bot.plugin_manager.out_sieves) |
| 294 | + |
291 | 295 | 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 | + |
293 | 300 | ok, new_line = yield from self.bot.plugin_manager.internal_launch(out_sieve, event) |
294 | 301 | 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") |
296 | 303 | logger.debug("Line was: %s", line) |
297 | | - return |
| 304 | + filtered = False |
| 305 | + break |
298 | 306 |
|
299 | 307 | line = new_line |
| 308 | + if line is not None and not isinstance(line, bytes): |
| 309 | + line = str(line) |
| 310 | + |
300 | 311 | if not line: |
301 | 312 | return |
302 | 313 |
|
| 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 | + |
303 | 323 | self._transport.write(line) |
304 | 324 |
|
305 | 325 | def data_received(self, data): |
|
0 commit comments