Jason R. Coombs avatar Jason R. Coombs committed 9a0205b

Remove truncation logic - it doesn't work because the irc lib has to add 'PRIVMSG #channel' and other operation parameters. So instead, just trap the error.

Comments (0)

Files changed (1)

 		return irc.bot.SingleServerIRCBot.connect(self,
 			connect_factory = factory, *args, **kwargs)
-	@staticmethod
-	def truncate(s):
-		# the encoded payload must be no longer than 512 characters including
-		#  the extra CR/LF
-		if len(s.encode('utf-8')) > 510:
-			globals()['log'].warn(u"Truncating long message: " + s)
-			s = s[:510]
-			# that gets the message pretty close, but with encoding, it could
-			#  still exceed the limit.
-			while len(s.encode('utf-8')) > 510:
-				s = s[:-1]
-		return s
 	def out(self, channel, s, log=True):
 		func = self.c.privmsg
 		if s.startswith(u'/me '):
 			func = self.c.action
 			s = s.split(' ', 1)[-1].lstrip()
 			log = False
-		s = self.truncate(s)
-		func(channel, s)
+		try:
+			func(channel, s)
+		except ValueError as exc:
+			# some messages will fail because they're too long
+			if u'512 bytes' in unicode(exc):
+				globals()['log'].warning("Long message could not be "
+					"transmitted: %s", s)
+				return
+			raise
 		if (
 				channel in self._channels
 				and channel in pmxbot.config.log_channels
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.