summary refs log tree commit diff
path: root/client.py
diff options
context:
space:
mode:
authorMatt Arnold2022-02-12 21:25:13 -0500
committerMatt Arnold2022-02-12 21:25:13 -0500
commit7d0300a7a428dd42d7751e0e636a42c55f2e116e (patch)
tree5ec5fbcd8f3d94808dbb603f85a60743d526b0f6 /client.py
inital commit, laugh all you want
Diffstat (limited to 'client.py')
-rw-r--r--client.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/client.py b/client.py
new file mode 100644
index 0000000..112707c
--- /dev/null
+++ b/client.py
@@ -0,0 +1,55 @@
+# 
+from IRC import *
+import os
+import random
+import ssl
+import socket
+import sys
+
+LINEEND = '\r\n'
+# IRC Config
+hostname = "irc.spartalinux.xyz"  # Provide a valid server IP/Hostname
+port = 6697
+channel = "#botdev"
+botnick = "botley"
+botnickpass = "a.password"
+botpass = "unused"
+
+# 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
+# These provide good defaults. But your milage may vary
+oursock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+context = ssl.SSLContext()
+context.check_hostname = False
+context.verify_mode = ssl.CERT_NONE
+oursock = context.wrap_socket(oursock, server_hostname=hostname)
+irc = IRCBot(oursock)
+irc.connect(hostname, port, channel, botnick, botpass, botnickpass)
+
+def generate_response(person, message):
+    print(person, message)
+    msg = message.strip(LINEEND)
+    irc.send_privmsg(channel, str(type(person)) + ' ' + str(type(message)))
+    if 'cool.person' in person and msg.lower() == "hello botley":
+        return "Greetings Master"
+    elif msg.lower() == "hello":
+        return "Greetings Human!"
+    else:
+        return None
+
+while True:
+    try:
+
+        text = irc.get_response()
+        print(text[0],text[1],text[2])
+        if text[1] == 'PRIVMSG' and text[2][0] == channel:
+            r = generate_response(text[0],text[2][1])
+            if r is not None:
+                irc.send_privmsg(channel,r)
+    except KeyboardInterrupt:
+        irc.send_quit("Ctrl-C Pressed")
+        msg = oursock.recv(4096)
+        print(msg)
+        sys.exit(0)
+
+