Merge branch 'master' into develop2
This commit is contained in:
commit
acab64b5f7
@ -12,7 +12,7 @@ staying in touch
|
||||
|
||||
<code>bot.py</code> is the project's main file. It uses the socket module to communicate and gathers a list of known IRC nicknames, stored in <code>nicks.csv</code>. 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.
|
||||
|
||||
|
35
bot.py
35
bot.py
@ -13,10 +13,10 @@ from threading import Thread
|
||||
|
||||
|
||||
# Some basic variables used to configure the bot.
|
||||
server = "irc.freenode.net"
|
||||
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 "
|
||||
hello_list = [r'hello', r'hi', r'hey', r'yo', r'sup']
|
||||
@ -69,19 +69,34 @@ def bot_hello(greeting):
|
||||
def bot_help():
|
||||
ircsock.send("PRIVMSG {} :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 '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.
|
||||
@ -109,16 +124,16 @@ def get_regex(options):
|
||||
# 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 = 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 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 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 ####################
|
||||
|
Loading…
Reference in New Issue
Block a user