Skip to content

Instantly share code, notes, and snippets.

@jasonblewis
Created November 1, 2018 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonblewis/dd5e316c7aa2fbf053a8aa25dbb7a6df to your computer and use it in GitHub Desktop.
Save jasonblewis/dd5e316c7aa2fbf053a8aa25dbb7a6df to your computer and use it in GitHub Desktop.
def print_response():
while(client.connected):
client.last_response = client.get_response()
if(client.last_response != ''):
logging.debug("RAW: {}".format(client.last_response))
if "PING" in client.last_response: # Respond to pongs from the server
client.send_pong(client.last_response) # Give the server the timestamped PONG
if "Closing Link" in client.last_response: # Server said goodbye
client.connected = False # So we're disconnected now, thread ends.
try:
msg = client.last_response.strip().split(":") # remove leading :
host = msg[1]
nick = host.split("!")[0]
hostarray = host.split(" ")
message = msg[2].strip()
if hostarray[1] == "PRIVMSG":
if hostarray[2].startswith("#"):
print("{}: < {}> {}".format(hostarray[2],nick, message))
else:
print("PRIVMSG from {}: < {}> {}".format(hostarray[2],nick, message))
else:
print("some other message:< {}> {}".format(nick, message))
logging.debug("RAW: {}".format(msg))
except IndexError:
print("RAW: {}".format(msg)) # Something went wrong with the next few lines...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment