does not greet nicks who leave quickly

This commit is contained in:
Shauna 2014-01-30 15:20:41 -05:00
parent 32812dd656
commit c3f6f90c33

25
bot.py
View File

@ -29,7 +29,7 @@ class newcomer(object): # Newcomer class created when someone joins the room
# Functions!
def joinchan(chan): # Joins channels
ircsock.send("JOIN "+ chan +"\n")
ircsock.send("JOIN " + chan + "\n")
def getIRC(): # Creates separate thread for reading messages from the server
while True:
@ -41,14 +41,14 @@ def getIRC(): # Creates separate thread for reading messages from the
def ping(): # Responds to server Pings.
ircsock.send("PONG :pingis\n")
def hello(actor,greeting, chan=channel): # This function responds to a user that inputs "Hello Mybot"
ircsock.send("PRIVMSG " + chan +" :" + greeting + " " + actor + "\n")
def hello(actor, greeting, chan=channel): # This function responds to a user that inputs "Hello Mybot"
ircsock.send("PRIVMSG " + chan + " :" + greeting + " " + actor + "\n")
def help(actor, chan=channel): # This function explains what the bot is when queried.
ircsock.send("PRIVMSG " + chan +" :I'm a bot! I'm from here: https://github.com/shaunagm/oh-irc-bot. You can change my behavior by submitting a pull request or by talking to shauna. \n")
ircsock.send("PRIVMSG " + chan + " :I'm a bot! I'm from here: https://github.com/shaunagm/oh-irc-bot. You can change my behavior by submitting a pull request or by talking to shauna. \n")
def welcome(newcomer): # This welcomes a specific person.
ircsock.send("PRIVMSG "+ channel +" :Welcome "+ newcomer + "! The channel's pretty quiet right now, so I thought I'd say hello, and ping some people (like shauna, paulproteus, marktraceur) that you're here. If no one responds for a while, try emailing us at hello@openhatch.org or just coming back later. FYI, you're now on my list of known nicknames, so I won't bother you again.\n")
ircsock.send("PRIVMSG " + channel + " :Welcome " + newcomer + "! The channel's pretty quiet right now, so I thought I'd say hello, and ping some people (like shauna, paulproteus, marktraceur) that you're here. If no one responds for a while, try emailing us at hello@openhatch.org or just coming back later. FYI, you're now on my list of known nicknames, so I won't bother you again.\n")
def makeNickArray(): # On startup, makes array of nicks from Nicks.txt. New info will be written to both array and txt file.
nickArray = []
@ -57,12 +57,10 @@ def makeNickArray(): # On startup, makes array of nicks from Nicks.txt. New in
for row in nicksData:
nickArray.append(row)
return nickArray
# Do I need to explicitly close this file?
def addPerson(person): # Adds newcomer to list of known nicks
person = person.replace("_","")
nickArray.append([person])
print nickArray
with open('nicks.csv', 'a') as csvfile:
nickwriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
nickwriter.writerow([person])
@ -70,8 +68,8 @@ def addPerson(person): # Adds newcomer to list of known nicks
# Startup
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ircsock.connect((server, 6667)) # Here we connect to the server using the port 6667
ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :This is http://openhatch.org/'s greeter bot.\n") # user authentication
ircsock.send("NICK "+ botnick +"\n") # here we actually assign the nick to the bot
ircsock.send("USER " + botnick + " " + botnick + " " + botnick + " :This is http://openhatch.org/'s greeter bot.\n") # user authentication
ircsock.send("NICK " + botnick + "\n") # here we actually assign the nick to the bot
joinchan(channel)
# Starts a separate thread to get messages from server
@ -100,7 +98,7 @@ while 1: # Loop forever
actor = ircmsg.split(":")[1].split("!")[0]
# Welcome functions
if ircmsg.find("PRIVMSG "+ channel) != -1: # If someone has spoken into the channel
if ircmsg.find("PRIVMSG " + channel) != -1: # If someone has spoken into the channel
for i in newList:
if actor != i.nick: # Don't turn off response if the person speaking is the person who joined.
i.updateStatus() # Sets status to 1
@ -108,12 +106,17 @@ while 1: # Loop forever
newList.remove(i)
## Else: Do we want to do something extra if the person who joined the chat says something with no response?
if ircmsg.find("JOIN "+ channel) != -1: # If someone joins #channel
if ircmsg.find("JOIN " + channel) != -1: # If someone joins #channel
if actor != botnick: # Remove the case where the bot gets a message that the bot has joined.
if [actor.replace("_","")] not in nickArray:
if actor not in (i.nick for i in newList):
newList.append(newcomer(actor))
if ircmsg.find("PART " + channel) != -1 or ircmsg.find("QUIT") != -1: # If someone parts or quits the #channel
for i in newList: # And that person is on the newlist (has entered channel within last 60 seconds)
if actor == i.nick:
newList.remove(i) # Remove them from the list
# Unwelcome functions
if ircmsg.find(botnick) != -1 and ircmsg.find("PRIVMSG") != -1: # If someone talks to (or refers to) the bot
chan = channel