Skip to content

Commit

Permalink
Feat: Save file and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RingoMar committed Sep 20, 2024
1 parent 0a465bc commit 63b6a0b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/
test.json
test.json

stream-*.json
15 changes: 12 additions & 3 deletions simple_bot.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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

Expand All @@ -38,7 +42,7 @@ def readfuntion(self):
print("Connected!")
else:
print(ircTranslate[0])

self.SetMessage.append(ircTranslate[0])

except Exception as e:
print(e)
Expand All @@ -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()
33 changes: 33 additions & 0 deletions test_rinIRC.py
Original file line number Diff line number Diff line change
@@ -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",
":[email protected] 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= :[email protected] 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= :[email protected] 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= :[email protected] 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()

0 comments on commit 63b6a0b

Please sign in to comment.