summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatt Arnold <matt@thegnuguru.org>2022-02-22 14:32:06 -0500
committerMatt Arnold <matt@thegnuguru.org>2022-02-22 14:32:06 -0500
commit6d185593b351a9c229af10d8d35e413039a516a7 (patch)
treee7a2ed91df0252c1c9f0134c100157fa469f598b
parent66f447b69637160f894d04f35eac4ee4596441c9 (diff)
Add fun stuff to the sample, and error handling at protocol
-rw-r--r--IRC.py5
-rw-r--r--client.py9
2 files changed, 12 insertions, 2 deletions
diff --git a/IRC.py b/IRC.py
index a67e65d..90ef1fa 100644
--- a/IRC.py
+++ b/IRC.py
@@ -92,14 +92,17 @@ class IRCBot:
         self.send_cmd(usermsg)
         nickmsg = irctokens.build("NICK", [botnick])
         self.send_cmd(nickmsg)
+    
     def get_response(self):
         # Get the response
         resp = self.irc.recv(4096).decode("UTF-8")
         msg = parsemsg(resp)
         nwmsg = irctokens.tokenise(resp)
-        
+        printred(nwmsg.command)
         if nwmsg.command == "001":
             self.on_welcome(nwmsg.params)
+        if nwmsg.command == "ERROR":
+            raise IRCError(str(nwmsg.params[0]))
         if nwmsg.command == 'PING':
             print('Sending pong')
             self.irc.send(
diff --git a/client.py b/client.py
index bbd0649..a3ce217 100644
--- a/client.py
+++ b/client.py
@@ -16,7 +16,7 @@ with open('config.json') as f:
     jld = f.read()
     config = json.loads(jld)
 
-botpass = "unused.factor.this.out"
+
 
 # Need to pass the IRCBot class a socket the reason it doesn't do this itself is 
 # so you can set up TLS or not as you need it
@@ -39,6 +39,10 @@ def generate_response(person, message):
         return "Greetings Master"
     elif msg.lower() == "hello":
         return "Greetings Human!"
+    elif "Ground Control to Major Tom" in msg:
+        return "Put your helmet on!"
+    elif "Ziggy Stardust" in msg:
+        return "Looks good in leather pants"
     else:
         return None
 
@@ -56,5 +60,8 @@ while True:
         msg = oursock.recv(4096)
         print(msg)
         sys.exit(0)
+    except IRCError as e:
+        printred(e)
+        sys.exit(1)