From d9f994ae98bb9ed65f6a12577b44a2297a45e09a Mon Sep 17 00:00:00 2001 From: "james.bertino" Date: Fri, 23 May 2014 16:03:34 -0400 Subject: [PATCH 1/2] Added try and except statements to fix Issue #18 --- bot.py | 25 +++++++++++++++++-------- error.log | 2 ++ 2 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 error.log diff --git a/bot.py b/bot.py index 8bd900e..93c2892 100644 --- a/bot.py +++ b/bot.py @@ -3,12 +3,13 @@ ######################################################################### # Import some necessary libraries. -import socket +import socket import time import csv import Queue import random import re +from sys import exc_info from threading import Thread @@ -57,7 +58,7 @@ def msg_handler(): # Responds to server Pings. def pong(): - ircsock.send("PONG :pingis\n") + ircsock.send("PONG :pingis\n") # This function responds to a user that inputs "Hello Mybot". @@ -126,13 +127,13 @@ def get_regex(options): def wait_time_change(): for admin in channel_greeters: if actor == admin: - finder = re.search(r'\d\d*', re.search(r'--wait-time \d\d*', ircmsg) - .group()) + finder = re.search(r'\d\d*', re.search(r'--wait-time \d\d*', + ircmsg).group()) ircsock.send("PRIVMSG {0} :{1} the wait time is changing to {2} " "seconds.\n".format(channel, actor, finder.group())) return int(finder.group()) - ircsock.send("PRIVMSG {0} :{1} you are not authorized to make that " - "change. Please contact one of the channel greeters, like {2}, for " + ircsock.send("PRIVMSG {0} :{1} you are not authorized to make that change" + ". Please contact one of the channel greeters, like {2}, for " "assistance.\n".format(channel, actor, greeter_string("or"))) @@ -191,7 +192,15 @@ while 1: # loop forever # get the next msg in the queue ircmsg = q.get() # and get the nick of the msg sender - actor = ircmsg.split(":")[1].split("!")[0] + try: + actor = ircmsg.split(":")[1].split("!")[0] + except IndexError: + err_log = open('./error.log', 'a') + err_log.write('\nError occurred: {0}.\nircmsg was: {1}.\nSystem ' + 'error was: {2}' + '\n'.format(time.strftime('%x %X %Z'), + ircmsg, exc_info()[0])) + err_log.close() ##### Welcome functions ##### # If someone has spoken into the channel... @@ -231,4 +240,4 @@ while 1: # loop forever # If the server pings us then we've got to respond! if ircmsg.find("PING :") != -1: - pong() + pong() \ No newline at end of file diff --git a/error.log b/error.log new file mode 100644 index 0000000..06b50fa --- /dev/null +++ b/error.log @@ -0,0 +1,2 @@ +This log was created to help catch an error when a 'mystery message' is received by the bot: + From 90e1ed35a7ac5fbe7d92c0eef53f9c54ae9b370d Mon Sep 17 00:00:00 2001 From: Lindsey Kuper Date: Sat, 16 Aug 2014 17:06:13 -0700 Subject: [PATCH 2/2] Update bot.py Typo fix. --- bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index 93c2892..95b799a 100644 --- a/bot.py +++ b/bot.py @@ -92,7 +92,7 @@ def greeter_string(conjunction): # This welcomes the "person" passed to it. def welcome(newcomer): ircsock.send("PRIVMSG {0} :Welcome {1}! The channel is pretty quiet " - "right now, so I though I'd say hello, and ping some people " + "right now, so I thought I'd say hello, and ping some people " "(like {2}) that you're here. If no one responds for a " "while, try emailing us at hello@openhatch.org or just try " "coming back later. FYI, you're now on my list of known " @@ -240,4 +240,4 @@ while 1: # loop forever # If the server pings us then we've got to respond! if ircmsg.find("PING :") != -1: - pong() \ No newline at end of file + pong()