I am trying to create an irc bot using python, but I'm getting an error. When I try to check for a message sent, the PRIVMSG doesn't send a message to the chat, but the test print statement outputs. If I just try to send a message when anything is received it sends the message. I commented in the code where this happens. This is my first time trying to do this, so sorry if I'm a bit inexperienced using python sockets.
#connect.py
#connects to twitch irc and presents a class to b
import cfg
import socket
import time
def ban(sock, user):
chat(sock, ".ban {}".format(user))
def timeout(sock, user, secs=600):
chat(sock, ".timeout {}".format(user, secs))
# network functions go here
s = socket.socket()
s.connect((cfg.HOST, cfg.PORT))
s.send("PASS {}\r\n".format(cfg.PASS).encode("utf-8"))
s.send("NICK {}\r\n".format(cfg.NICK).encode("utf-8"))
s.send("JOIN {}\r\n".format(cfg.CHAN).encode("utf-8"))
while True:
time.sleep(0.1)
response = s.recv(1024).decode("utf-8")
print(response)
if response == "PING :tmi.twitch.tv\r\n":
s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
elif "hi" in response:
#prints Condition Worked but doesn't send message
print("Condition Worked")
s.send(("PRIVMSG #garrett_the_savage :hello"+"\r\n").encode('utf-8'))
else
#sends a message when anything is received from the socket
s.send(("PRIVMSG #garrett_the_savage :hello"+"\r\n").encode('utf-8'))
EDIT: I have a separate file called cfg.py that houses some variables for connecting.