From 13381bc12504eb0c2afcf193de6754666213739c Mon Sep 17 00:00:00 2001 From: Matt Arnold Date: Sun, 20 Feb 2022 18:33:55 -0500 Subject: Major rewrite to use a proper irc tokenizer json for configuration, and other such QOL improvements --- client.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'client.py') 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) -- cgit 1.4.1-2-gfad0