From e92de19b2129af59080a18363dffabe5e656fd1c Mon Sep 17 00:00:00 2001 From: "james.bertino" Date: Sat, 3 May 2014 19:46:56 -0400 Subject: [PATCH 1/2] Minor tweeks to Issue #14 fix. --- bot.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/bot.py b/bot.py index b648dc4..6dbe777 100644 --- a/bot.py +++ b/bot.py @@ -15,7 +15,7 @@ from re import search server = "irc.freenode.net" channel = "#openhatch" botnick = 'WelcomeBot' -channel_admins = ('shauna', 'paulproteus', 'marktraceur') +channel_greeters = ['shauna', 'paulproteus', 'marktraceur'] wait_time = 60 # amount of time after joining before bot replies to someone change_wait = botnick + " --wait-time " @@ -66,19 +66,34 @@ def bot_hello(greeting): def bot_help(): ircsock.send("PRIVMSG {} :I'm a bot! I'm from here . You can change my behavior by " - "submitting a pull request or by talking to 'fill in " - "the blank'.\n".format(channel)) + "submitting a pull request or by talking to shauna" + ".\n".format(channel)) + + +# Returns a grammatically correct string of the channel_greeters. +def greeter_string(conjunction): + greeters = "" + if len(channel_greeters) > 2: + for name in channel_greeters[:-1]: + greeters += "{}, ".format(name) + greeters += "{0} {1}".format(conjunction, channel_greeters[-1]) + elif len(channel_greeters) == 2: + greeters = "{0} {1} {2}".format(channel_greeters[0], conjunction, + channel_greeters[1]) + else: + greeters = channel_greeters[0] + return greeters # 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 " - "(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 " "coming back later. FYI, you're now on my list of known " "nicknames, so I won't bother you again." - "\n".format(channel, newcomer, channel_admins)) + "\n".format(channel, newcomer, greeter_string("and"))) # Adds the current NewComer's nick to nicks.csv and known_nicks. @@ -106,7 +121,7 @@ def get_welcome_regex(string_array): # It confirms that the attempt is allowed and then returns the requested value. # If the attempt is not allowed, a message is sent to help def wait_time_change(): - for admin in channel_admins: + for admin in channel_greeters: if actor == admin: finder = search(r'\d\d*', search(r'--wait-time \d\d*', ircmsg) .group()) @@ -114,8 +129,8 @@ def wait_time_change(): "seconds.\n".format(channel, actor, finder.group())) return finder.group() ircsock.send("PRIVMSG {0} :{1} you are not authorized to make that " - "change. Please contact one of the channel admins {2} for " - "assistance.\n".format(channel, actor, channel_admins)) + "change. Please contact one of the channel greeters, like {2}, for " + "assistance.\n".format(channel, actor, greeter_string("or"))) #################### Startup #################### From 4ad322b03087fb19257b4cab5bc16a0062350db3 Mon Sep 17 00:00:00 2001 From: "james.bertino" Date: Mon, 5 May 2014 17:57:46 -0400 Subject: [PATCH 2/2] Changed the return value of wait_time_change() to an int and updated the README. --- README.md | 2 +- bot.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c0ec230..fab5bf8 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ staying in touch bot.py is the project's main file. It uses the socket module to communicate and gathers a list of known IRC nicknames, stored in nicks.csv. Its basic functions include: -1. If someone enters the channel, the bot checks to see if they are a known nick. If not, it adds them to a list of people to greet. If no one else has spoken into the channel after 60 seconds, it greets them. If someone else (not the new nick) speaks into the channel within 60 seconds, or if the nick is known, the bot remains silent. The bots response text includes the nicks of channel maintainers/frequent contributors so that they are pinged. +1. If someone enters the channel, the bot checks to see if they are a known nick. If not, it adds them to a list of people to greet. If no one else has spoken into the channel after a period of time, 60 seconds by default, it greets them. If someone else (not the new nick) speaks into the channel within the set wait time, or if the nick is known, the bot remains silent. The bots response text includes the nicks of channel maintainers/frequent contributors so that they are pinged. Channel maintainers can change the wait time of the bot by using the following command in the irc channel: *Botname* --wait-time *new wait time in seconds*. 2. If someone says hello to the bot, the bot says hello back. 3. If someone asks the bot for information (via key phrases like "help", "faq", etc) the bot explains what it is and links to this repository. diff --git a/bot.py b/bot.py index 6dbe777..454a750 100644 --- a/bot.py +++ b/bot.py @@ -12,7 +12,7 @@ from threading import Thread from re import search # Some basic variables used to configure the bot. -server = "irc.freenode.net" +server = "irc.freenode.net" channel = "#openhatch" botnick = 'WelcomeBot' channel_greeters = ['shauna', 'paulproteus', 'marktraceur'] @@ -127,7 +127,7 @@ def wait_time_change(): .group()) ircsock.send("PRIVMSG {0} :{1} the wait time is changing to {2} " "seconds.\n".format(channel, actor, finder.group())) - return 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 " "assistance.\n".format(channel, actor, greeter_string("or")))