Browse Source

Only pass bytestrings (and not bytearrays) to user code

pull/1/head
Juhani Krekelä 5 years ago
parent
commit
b2ca8a0599
  1. 5
      botcmd.py
  2. 2
      ircbot.py
  3. 2
      line_handling.py

5
botcmd.py

@ -7,6 +7,7 @@ def initialize(*, config):
# on_connect(*, irc)
# Called after IRC bot has connected and sent the USER/NICk commands but not yet attempted anything else
# Called for every reconnect
# Blocks the bot until it's done, including PING/PONG handling
# irc is the IRC API object
def on_connect(*, irc):
@ -26,7 +27,7 @@ def on_quit(*, irc):
# nick is who sent the message
# channel is where you should send the response (note: in queries nick == channel)
# irc is the IRC API object
# All strings are bytestrings or bytearrays
# All strings are bytestrings
def handle_message(*, prefix, message, nick, channel, irc):
...
@ -36,6 +37,6 @@ def handle_message(*, prefix, message, nick, channel, irc):
# command is the command or number code
# arguments is rest of the arguments of the command, represented as a list. ':'-arguments are handled automatically
# irc is the IRC API object
# All strings are bytestrings or bytearrays
# All strings are bytestrings
def handle_nonmessage(*, prefix, command, arguments, irc):
...

2
ircbot.py

@ -194,6 +194,8 @@ class ServerThread(threading.Thread):
pass
else:
self.logging_channel.send((logmessage_types.received, line.decode(encoding = 'utf-8', errors = 'replace')))
# Ensure we have a bytestring, because bytearray can be annoying to deal with
line = bytes(line)
line_handling.handle_line(line, irc = self.api)
def mainloop(self):

2
line_handling.py

@ -114,7 +114,7 @@ class LineHandlerThread(threading.Thread):
try:
prefix, command, arguments = parse_line(self.line)
except LineParsingError:
irc.error("Cannot parse line" + self.line.decode(encoding = 'utf-8', errors = 'replace'))
irc.error("Cannot parse line: " + self.line.decode(encoding = 'utf-8', errors = 'replace'))
if command.upper() == b'PRIVMSG':
# PRIVMSG should have two parameters: recipient and the message

Loading…
Cancel
Save