diff --git a/piebot/irc.py b/piebot/irc.py index a74a00b..8f78ece 100644 --- a/piebot/irc.py +++ b/piebot/irc.py @@ -288,3 +288,15 @@ class Topic(Message, metaclass=register_derivative): self.source = self.get("nick") self.channel = self.get("params")[0] self.topic = self.get("trailing") + +class Quit(Message, metaclass=register_derivative): + def __init__(self, message="QUIT", *args, **kwargs): + super().__init__(*args, **kwargs) + if "data" not in kwargs: + self.update({ + "command": "QUIT", + "trailing": message + }) + def parse(self): + self.nick = self.get("nick") + self.message = self.get("trailing") diff --git a/tests/test_message.py b/tests/test_message.py index 582c78b..9e2a6ef 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -156,4 +156,17 @@ class Message(unittest.TestCase): def test_construct_topic(self): msg = irc.Topic(channel="#politics", topic="Yes, we can!") - self.assertEqual(str(msg), "TOPIC #politics :Yes, we can!") \ No newline at end of file + self.assertEqual(str(msg), "TOPIC #politics :Yes, we can!") + + + def test_parse_quit(self): + raw = ":worker!~frustrated@company.com QUIT :This is it!" + msg = irc.Message.from_string(raw) + self.assertIsInstance(msg, irc.Quit, msg="Not a Quit!") + self.assertEqual(msg.nick, "worker") + self.assertEqual(msg.message, "This is it!") + + def test_construct_quit(self): + msg = irc.Quit(message="Good bye!") + self.assertEqual(str(msg), "QUIT :Good bye!") +