summaryrefslogtreecommitdiff
path: root/client.py
diff options
context:
space:
mode:
authorMatt Arnold2022-02-20 18:33:55 -0500
committerMatt Arnold2022-02-20 18:33:55 -0500
commit13381bc12504eb0c2afcf193de6754666213739c (patch)
treebce8e9941a9a357f2a83a3989f5e859be85e4f78 /client.py
parent6938bd4862d8a934044b27277eab1773c0805819 (diff)
Major rewrite to use a proper irc tokenizer json for configuration, and other such QOL improvements
Diffstat (limited to 'client.py')
-rw-r--r--client.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/client.py b/client.py
index 112707c..bbd0649 100644
--- a/client.py
+++ b/client.py
@@ -1,19 +1,22 @@
-#
+# Part of rabbitears See LICENSE for permissions
+# Copyright (C) 2022 Matt Arnold
from IRC import *
import os
import random
import ssl
import socket
import sys
+import irctokens
+import json
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"
+config = None
+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
@@ -22,14 +25,16 @@ 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)
+oursock = context.wrap_socket(oursock, server_hostname=config['hostname'])
irc = IRCBot(oursock)
-irc.connect(hostname, port, channel, botnick, botpass, botnickpass)
+irc.connect(config['hostname'],
+ config['port'],
+ config['channel'],
+ config['nick'],
+ config['nickpass'])
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":
@@ -42,10 +47,10 @@ while True:
text = irc.get_response()
print(text[0],text[1],text[2])
- if text[1] == 'PRIVMSG' and text[2][0] == channel:
+ if text[1] == 'PRIVMSG' and text[2][0] == config['channel']:
r = generate_response(text[0],text[2][1])
if r is not None:
- irc.send_privmsg(channel,r)
+ irc.send_privmsg(config['channel'],r)
except KeyboardInterrupt:
irc.send_quit("Ctrl-C Pressed")
msg = oursock.recv(4096)