diff --git a/.gitignore b/.gitignore index 349a42b..e73d769 100644 --- a/.gitignore +++ b/.gitignore @@ -127,4 +127,6 @@ dmypy.json # Pyre type checker .pyre/ -test.json \ No newline at end of file +test.json + +stream-*.json \ No newline at end of file diff --git a/simple_bot.py b/simple_bot.py index 2e9cc85..29b5b93 100644 --- a/simple_bot.py +++ b/simple_bot.py @@ -1,10 +1,14 @@ import socket from irc import rinIRC +import json +import sys +import time class Simplebot(): def __init__(self) -> None: self.sock = socket.socket() + self.SetMessage = [] pass def connect(self) -> None: @@ -17,7 +21,7 @@ def connect(self) -> None: self.sock.send(bytes("CAP REQ :twitch.tv/membership\r\n", "UTF-8")) self.sock.send(bytes("CAP REQ :twitch.tv/commands\r\n", "UTF-8")) - self.sock.send("JOIN #twitchmedia_qs_10\r\n".encode("utf-8")) + self.sock.send("JOIN #djclancy\r\n".encode("utf-8")) return @@ -38,7 +42,7 @@ def readfuntion(self): print("Connected!") else: print(ircTranslate[0]) - + self.SetMessage.append(ircTranslate[0]) except Exception as e: print(e) @@ -48,7 +52,12 @@ def readfuntion(self): def run(self): self.connect() while True: - self.readfuntion() + try: + self.readfuntion() + except KeyboardInterrupt: + with open(f"stream-{round(time.time() * 1000)}.json", 'w', encoding='utf-8') as f: + json.dump(self.SetMessage, f, ensure_ascii=False, indent=4) + sys.exit(0) if __name__ == "__main__": Simplebot().run() \ No newline at end of file diff --git a/test_rinIRC.py b/test_rinIRC.py new file mode 100644 index 0000000..4209a35 --- /dev/null +++ b/test_rinIRC.py @@ -0,0 +1,33 @@ +import unittest +from irc import rinIRC + +class TestRinIRC(unittest.TestCase): + + def setUp(self): + # Sample raw IRC messages for testing + self.test_cases = [ + ":tmi.twitch.tv 002 justinfan123 :Your host is tmi.twitch.tv", + ":tmi.twitch.tv 003 justinfan123 :This server is rather new", + ":tmi.twitch.tv 004 justinfan123 :-", + ":tmi.twitch.tv 375 justinfan123 :-", + ":tmi.twitch.tv 372 justinfan123 :You are in a maze of twisty passages, all alike.", + ":tmi.twitch.tv 376 justinfan123 :>", + ":tmi.twitch.tv CAP * ACK :twitch.tv/tags", + ":justinfan123!justinfan123@justinfan123.tmi.twitch.tv JOIN #djclancy", + "@emote-only=0;followers-only=-1;r9k=0;room-id=268669435;slow=0;subs-only=0 :tmi.twitch.tv ROOMSTATE #djclancy", + ":justinfan123.tmi.twitch.tv 353 justinfan123 = #djclancy :justinfan123", + ":justinfan123.tmi.twitch.tv 366 justinfan123 #djclancy :End of /NAMES list", + "@badge-info=;badges=;client-nonce=214e9aa84441647bfe07b1906158474c;color=#FF7F50;display-name=kinged1130;emotes=emotesv2_e50f8b815384472b899de8fdd470fb19:7-18,20-31,33-44,46-57,59-70,72-83,85-96;first-msg=0;flags=;id=799bc3d8-9add-4866-ae31-8c32ec766bd4;mod=0;returning-chatter=0;room-id=268669435;subscriber=0;tmi-sent-ts=1726799771057;turbo=0;user-id=124995234;user-type= :kinged1130!kinged1130@kinged1130.tmi.twitch.tv PRIVMSG #djclancy :orange thatoneDance thatoneDance thatoneDance thatoneDance thatoneDance thatoneDance thatoneDance", + "@badge-info=;badges=glhf-pledge/1;client-nonce=d51e31a25b2d22aba5b79ce57d702022;color=#79F8C3;display-name=senibaj;emotes=;first-msg=1;flags=;id=05519ebc-6d80-45f1-8fb0-0c10a1b6c50e;mod=0;returning-chatter=0;room-id=268669435;subscriber=0;tmi-sent-ts=1726799771574;turbo=0;user-id=145985397;user-type= :senibaj!senibaj@senibaj.tmi.twitch.tv PRIVMSG #djclancy :loquacious", + "@badge-info=;badges=raging-wolf-helm/1;client-nonce=85668a10856f2deb2f099bb45f73c2f4;color=#8A2BE2;display-name=ToxicTaco11;emotes=;first-msg=0;flags=;id=ef9a046d-54f9-4503-94d6-c612df7a21f3;mod=0;returning-chatter=0;room-id=268669435;subscriber=0;tmi-sent-ts=1726799771784;turbo=0;user-id=45681683;user-type= :toxictaco11!toxictaco11@toxictaco11.tmi.twitch.tv PRIVMSG #djclancy :perfect esfand", + ] + + def test_parseIRCMessage(self): + for raw_message in self.test_cases: + irc = rinIRC(raw_message) + message, error = irc.parseIRCMessage() + self.assertIsNone(error) + self.assertEqual(message["Raw"], raw_message) + +if __name__ == '__main__': + unittest.main()