Merge branch 'master' of github.com:shaunagm/oh-irc-bot

This commit is contained in:
Shauna 2014-09-13 13:21:06 -04:00
commit 3f590c227d
2 changed files with 19 additions and 8 deletions

25
bot.py
View File

@ -3,12 +3,13 @@
######################################################################### #########################################################################
# Import some necessary libraries. # Import some necessary libraries.
import socket import socket
import time import time
import csv import csv
import Queue import Queue
import random import random
import re import re
from sys import exc_info
from threading import Thread from threading import Thread
@ -57,7 +58,7 @@ def msg_handler():
# Responds to server Pings. # Responds to server Pings.
def pong(): def pong():
ircsock.send("PONG :pingis\n") ircsock.send("PONG :pingis\n")
# This function responds to a user that inputs "Hello Mybot". # This function responds to a user that inputs "Hello Mybot".
@ -91,7 +92,7 @@ def greeter_string(conjunction):
# This welcomes the "person" passed to it. # This welcomes the "person" passed to it.
def welcome(newcomer): def welcome(newcomer):
ircsock.send("PRIVMSG {0} :Welcome {1}! The channel is pretty quiet " 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 " "(like {2}) that you're here. If no one responds for a "
"while, try emailing us at hello@openhatch.org or just try " "while, try emailing us at hello@openhatch.org or just try "
"coming back later. FYI, you're now on my list of known " "coming back later. FYI, you're now on my list of known "
@ -126,13 +127,13 @@ def get_regex(options):
def wait_time_change(): def wait_time_change():
for admin in channel_greeters: for admin in channel_greeters:
if actor == admin: if actor == admin:
finder = re.search(r'\d\d*', re.search(r'--wait-time \d\d*', ircmsg) finder = re.search(r'\d\d*', re.search(r'--wait-time \d\d*',
.group()) ircmsg).group())
ircsock.send("PRIVMSG {0} :{1} the wait time is changing to {2} " ircsock.send("PRIVMSG {0} :{1} the wait time is changing to {2} "
"seconds.\n".format(channel, actor, finder.group())) "seconds.\n".format(channel, actor, finder.group()))
return int(finder.group()) return int(finder.group())
ircsock.send("PRIVMSG {0} :{1} you are not authorized to make that " ircsock.send("PRIVMSG {0} :{1} you are not authorized to make that change"
"change. Please contact one of the channel greeters, like {2}, for " ". Please contact one of the channel greeters, like {2}, for "
"assistance.\n".format(channel, actor, greeter_string("or"))) "assistance.\n".format(channel, actor, greeter_string("or")))
@ -191,7 +192,15 @@ while 1: # loop forever
# get the next msg in the queue # get the next msg in the queue
ircmsg = q.get() ircmsg = q.get()
# and get the nick of the msg sender # 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 ##### ##### Welcome functions #####
# If someone has spoken into the channel... # If someone has spoken into the channel...

2
error.log Normal file
View File

@ -0,0 +1,2 @@
This log was created to help catch an error when a 'mystery message' is received by the bot: