Compare commits
16 Commits
master
...
april-welc
Author | SHA1 | Date | |
---|---|---|---|
58d727b70b | |||
b0d3227ba7 | |||
89663f991b | |||
5f0d1c435b | |||
|
e5d1d76a7d | ||
|
bccfb520d7 | ||
|
b4b89d57f4 | ||
a690a9feb3 | |||
b91280c9e0 | |||
0477fe4358 | |||
fad2d01ca9 | |||
137eb4732a | |||
f0ced9cb1f | |||
01a5963fad | |||
|
c9d4a64dac | ||
|
fd09e1e4d7 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -8,4 +8,6 @@ lib
|
|||||||
local
|
local
|
||||||
bin
|
bin
|
||||||
error.log
|
error.log
|
||||||
|
nohup.out
|
||||||
nicks.csv
|
nicks.csv
|
||||||
|
bot_settings.py
|
||||||
|
21
bot_settings-example.py
Normal file
21
bot_settings-example.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# -*- coding: utf-8 -1 -*-
|
||||||
|
# Replace these default settings with your own personal settings
|
||||||
|
|
||||||
|
# IRC configuration
|
||||||
|
channel = "#april-accueil"
|
||||||
|
botnick = "bot_d_accueil"
|
||||||
|
server = "irc.freenode.net"
|
||||||
|
registered = False
|
||||||
|
|
||||||
|
# Bot behavior
|
||||||
|
wait_time = 60
|
||||||
|
channel_greeters = ["madix", "cioccolisa", "cpm_screen", "lonugem" ]
|
||||||
|
nick_source = "nicks.csv"
|
||||||
|
|
||||||
|
# Bot text
|
||||||
|
hello_list = ["hello", "yo", "bonjour", "salut"]
|
||||||
|
help_list = ["help", "info", "faq", "explain_yourself", "aide"]
|
||||||
|
|
||||||
|
# Bot welcome message. In fact, never used.
|
||||||
|
welcome_message = "Welcome! The channel is pretty quiet right now, so I thought I'd say hello, and ping some people that you're here. If no one responds for a whle, try emailing us at contact@april.org or just try coming back later. FYI, you're now on my list of known nicknames, so I won't bother you again."
|
||||||
|
|
@ -1,17 +0,0 @@
|
|||||||
# Replace these default settings with your own personal settings
|
|
||||||
|
|
||||||
# IRC configuration
|
|
||||||
channel = "#openhatch"
|
|
||||||
botnick = "welcomebot"
|
|
||||||
server = "irc.freenode.net"
|
|
||||||
registered = False
|
|
||||||
|
|
||||||
# Bot behavior
|
|
||||||
wait_time = 60
|
|
||||||
channel_greeters = ["shauna", "paulproteus", "marktraceur"]
|
|
||||||
nick_source = "nicks.csv"
|
|
||||||
|
|
||||||
# Bot text
|
|
||||||
hello_list = ["hello", "hi", "hey", "yo", "sup"]
|
|
||||||
help_list = ["help", "info", "faq", "explain_yourself"]
|
|
||||||
welcome_message = "Welcome! The channel is pretty quiet right now, so I thought I'd say hello, and ping some people that you're here. If no one responds for a whle, 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."
|
|
1
bot_settings.py
Symbolic link
1
bot_settings.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
/etc/welcomebot/bot_settings.py
|
49
init.d.deprecated/welcomebot
Executable file
49
init.d.deprecated/welcomebot
Executable file
@ -0,0 +1,49 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
#
|
||||||
|
### BEGIN INIT INFO
|
||||||
|
# Provides: welcomebot
|
||||||
|
# Required-Start: $remote_fs $syslog $local_fs $network
|
||||||
|
# Required-Stop: $remote_fs $syslog $local_fs $network
|
||||||
|
# Default-Start: 2 3 4 5
|
||||||
|
# Default-Stop: 0 1 6
|
||||||
|
# Short-Description: Bot irc de l'April.
|
||||||
|
# Description: welcomebt est un bot irc, il est ici installé pour son pluging
|
||||||
|
# MeetBot qui sert à réaliser des rapports de réunion.
|
||||||
|
### END INIT INFO
|
||||||
|
|
||||||
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
||||||
|
DAEMON=/srv/welcomebot/git/bot.sh
|
||||||
|
NAME=welcomebot
|
||||||
|
DESC=welcomebot
|
||||||
|
|
||||||
|
test -f $DAEMON || exit 0
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
echo -n "Starting $DESC: "
|
||||||
|
start-stop-daemon --start --quiet --make-pidfile --pidfile /var/run/$NAME.pid \
|
||||||
|
--chuid welcomebot --exec $DAEMON -- --daemon $DAEMON \
|
||||||
|
|| return 2
|
||||||
|
echo "$NAME."
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
echo -n "Stopping $DESC: "
|
||||||
|
rm -f /var/run/$NAME.pid
|
||||||
|
pkill -9 -f bot.py
|
||||||
|
echo "$NAME."
|
||||||
|
;;
|
||||||
|
restart)
|
||||||
|
$0 stop
|
||||||
|
$0 start
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {start|stop|restart}" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
|
39
bot.py → welcomebot.py
Normal file → Executable file
39
bot.py → welcomebot.py
Normal file → Executable file
@ -1,7 +1,10 @@
|
|||||||
|
#!/usr/bin/python -u
|
||||||
|
# -*- coding: utf-8 -1 -*-
|
||||||
|
|
||||||
# Welcome to WelcomeBot. Find source, documentation, etc here: https://github.com/shaunagm/WelcomeBot/ Licensed https://creativecommons.org/licenses/by-sa/2.0/
|
# Welcome to WelcomeBot. Find source, documentation, etc here: https://github.com/shaunagm/WelcomeBot/ Licensed https://creativecommons.org/licenses/by-sa/2.0/
|
||||||
|
|
||||||
# Import some necessary libraries.
|
# Import some necessary libraries.
|
||||||
import socket, sys, time, csv, Queue, random, re, pdb, select, os.path
|
import socket, sys, time, csv, Queue, random, re, pdb, select, os.path, datetime
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
# To configure bot, please make changes in bot_settings.py
|
# To configure bot, please make changes in bot_settings.py
|
||||||
@ -65,7 +68,7 @@ def irc_start(server): # pragma: no cover (this excludes this function from tes
|
|||||||
return ircsock
|
return ircsock
|
||||||
|
|
||||||
def join_irc(ircsock, botnick, channel):
|
def join_irc(ircsock, botnick, channel):
|
||||||
ircsock.send("USER {0} {0} {0} :This is http://openhatch.org/'s greeter bot"
|
ircsock.send("USER {0} {0} {0} :Robot d'accueil de https://april.org."
|
||||||
".\n".format(botnick)) # bot authentication
|
".\n".format(botnick)) # bot authentication
|
||||||
ircsock.send("NICK {}\n".format(botnick)) # Assign the nick to the bot.
|
ircsock.send("NICK {}\n".format(botnick)) # Assign the nick to the bot.
|
||||||
if os.path.isfile("password.txt"):
|
if os.path.isfile("password.txt"):
|
||||||
@ -80,7 +83,8 @@ def join_irc(ircsock, botnick, channel):
|
|||||||
def msg_handler(ircsock): # pragma: no cover (this excludes this function from testing)
|
def msg_handler(ircsock): # pragma: no cover (this excludes this function from testing)
|
||||||
new_msg = ircsock.recv(2048) # receive data from the server
|
new_msg = ircsock.recv(2048) # receive data from the server
|
||||||
new_msg = new_msg.strip('\n\r') # removing any unnecessary linebreaks
|
new_msg = new_msg.strip('\n\r') # removing any unnecessary linebreaks
|
||||||
print(new_msg) #### Potentially make this a log instead?
|
if new_msg != '':
|
||||||
|
print(datetime.datetime.now().isoformat() + " " + new_msg) #### Potentially make this a log instead?
|
||||||
return new_msg
|
return new_msg
|
||||||
|
|
||||||
# Called by bot on startup. Builds a regex that matches one of the options + (space) botnick.
|
# Called by bot on startup. Builds a regex that matches one of the options + (space) botnick.
|
||||||
@ -100,14 +104,21 @@ def get_regex(options, botnick):
|
|||||||
|
|
||||||
# Welcomes the "person" passed to it.
|
# Welcomes the "person" passed to it.
|
||||||
def welcome_nick(newcomer, ircsock, channel, channel_greeters):
|
def welcome_nick(newcomer, ircsock, channel, channel_greeters):
|
||||||
ircsock.send("PRIVMSG {0} :Welcome {1}! The channel is pretty quiet "
|
ircsock.send("PRIVMSG {0} :Bonjour {1} Je suis un robot IRC. Ce salon est tranquille actuellement, "
|
||||||
"right now, so I thought I'd say hello, and ping some people "
|
"je me permets donc de vous dire bonjour. Je signale à des actifs de l'April "
|
||||||
"(like {2}) that you're here. If no one responds for a "
|
"(comme {2}) que vous êtes là."
|
||||||
"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, greeter_string(channel_greeters)))
|
"\n".format(channel, newcomer, greeter_string(channel_greeters)))
|
||||||
|
|
||||||
|
ircsock.send("PRIVMSG {0} :{1} Si personne ne répond d'ici quelques minutes, "
|
||||||
|
"vous pouvez nous envoyer un courriel à contact@april.org (vous recevrez une demande "
|
||||||
|
"de confirmation, merci d'y répondre pour diffuser votre message) ou revenir plus tard."
|
||||||
|
"\n".format(channel, newcomer))
|
||||||
|
|
||||||
|
ircsock.send("PRIVMSG {0} :{1} Vous êtes désormais dans ma liste d'identifiants connus. "
|
||||||
|
"Je ne vous enverrai plus de message."
|
||||||
|
"\n".format(channel, newcomer))
|
||||||
|
|
||||||
|
|
||||||
# Checks and manages the status of newcomers.
|
# Checks and manages the status of newcomers.
|
||||||
def process_newcomers(bot, newcomerlist, ircsock, channel, greeters, welcome=1):
|
def process_newcomers(bot, newcomerlist, ircsock, channel, greeters, welcome=1):
|
||||||
for person in newcomerlist:
|
for person in newcomerlist:
|
||||||
@ -127,7 +138,7 @@ def parse_messages(ircmsg):
|
|||||||
# Cleans a nickname of decorators/identifiers
|
# Cleans a nickname of decorators/identifiers
|
||||||
def clean_nick(actor):
|
def clean_nick(actor):
|
||||||
if actor: # In case an empty string gets passed
|
if actor: # In case an empty string gets passed
|
||||||
if actor.find("openhatch") != -1: # If nick is like "openhatch_1234" don't clean.
|
if actor.find("april") != -1: # If nick is like "openhatch_1234" don't clean.
|
||||||
return actor
|
return actor
|
||||||
actor = actor.replace("_", "") # Strip out trailing _ characters
|
actor = actor.replace("_", "") # Strip out trailing _ characters
|
||||||
while(actor[-1]) in "1234567890": # Remove trailing numbers
|
while(actor[-1]) in "1234567890": # Remove trailing numbers
|
||||||
@ -198,9 +209,9 @@ def greeter_string(greeters):
|
|||||||
if len(greeters) > 2:
|
if len(greeters) > 2:
|
||||||
for name in greeters[:-1]:
|
for name in greeters[:-1]:
|
||||||
greeterstring += "{}, ".format(name)
|
greeterstring += "{}, ".format(name)
|
||||||
greeterstring += "and {}".format(greeters[-1])
|
greeterstring += "et {}".format(greeters[-1])
|
||||||
elif len(greeters) == 2:
|
elif len(greeters) == 2:
|
||||||
greeterstring = "{0} and {1}".format(greeters[0], greeters[1])
|
greeterstring = "{0} et {1}".format(greeters[0], greeters[1])
|
||||||
else:
|
else:
|
||||||
greeterstring = greeters[0]
|
greeterstring = greeters[0]
|
||||||
return greeterstring
|
return greeterstring
|
||||||
@ -232,6 +243,7 @@ def pong(ircsock, ircmsg):
|
|||||||
##########################
|
##########################
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
print datetime.datetime.now().isoformat() + " WelcomeBot starting…"
|
||||||
ircsock = irc_start(settings.server)
|
ircsock = irc_start(settings.server)
|
||||||
join_irc(ircsock, settings.botnick, settings.channel)
|
join_irc(ircsock, settings.botnick, settings.channel)
|
||||||
WelcomeBot = Bot()
|
WelcomeBot = Bot()
|
||||||
@ -239,10 +251,13 @@ def main():
|
|||||||
ready_to_read, b, c = select.select([ircsock],[],[], 1) # b&c are ignored here
|
ready_to_read, b, c = select.select([ircsock],[],[], 1) # b&c are ignored here
|
||||||
process_newcomers(WelcomeBot, [i for i in WelcomeBot.newcomers if i.around_for() > WelcomeBot.wait_time], ircsock,settings.channel, settings.channel_greeters)
|
process_newcomers(WelcomeBot, [i for i in WelcomeBot.newcomers if i.around_for() > WelcomeBot.wait_time], ircsock,settings.channel, settings.channel_greeters)
|
||||||
if ready_to_read:
|
if ready_to_read:
|
||||||
|
last_read = datetime.datetime.utcnow()
|
||||||
ircmsg = msg_handler(ircsock) # gets message from ircsock
|
ircmsg = msg_handler(ircsock) # gets message from ircsock
|
||||||
ircmsg, actor = parse_messages(ircmsg) # parses it or returns None
|
ircmsg, actor = parse_messages(ircmsg) # parses it or returns None
|
||||||
if ircmsg is not None: # If we were able to parse it
|
if ircmsg is not None: # If we were able to parse it
|
||||||
message_response(WelcomeBot, ircmsg, actor, ircsock, settings.channel, settings.channel_greeters) # Respond to the parsed message
|
message_response(WelcomeBot, ircmsg, actor, ircsock, settings.channel, settings.channel_greeters) # Respond to the parsed message
|
||||||
|
if datetime.datetime.utcnow() - last_read > datetime.timedelta(minutes=10):
|
||||||
|
raise Exception('timeout: nothing to read on socket since 10 minutes')
|
||||||
|
|
||||||
if __name__ == "__main__": # This line tells the interpreter to only execute main() if the program is being run, not imported.
|
if __name__ == "__main__": # This line tells the interpreter to only execute main() if the program is being run, not imported.
|
||||||
sys.exit(main())
|
sys.exit(main())
|
15
welcomebot.service
Normal file
15
welcomebot.service
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=APRIL IRC bot for april-accueil channel
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
WorkingDirectory=/srv/welcomebot/git
|
||||||
|
ExecStart=/srv/welcomebot/bin/welcomebot.py
|
||||||
|
User=welcomebot
|
||||||
|
Group=welcomebot
|
||||||
|
Restart=always
|
||||||
|
RestartSec=10
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
13
welcomebot.sh
Executable file
13
welcomebot.sh
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
BINDIR="`dirname "$0"`"
|
||||||
|
HOMEDIR="`dirname "$BINDIR"`"
|
||||||
|
|
||||||
|
echo "BINDIR=$BINDIR"
|
||||||
|
echo "HOMEDIR=$HOMEDIR"
|
||||||
|
|
||||||
|
cd "$BINDIR"
|
||||||
|
|
||||||
|
#nohup /srv/welcomebot/git/bot.py >> /dev/null 2>>../welcomebot.log &
|
||||||
|
|
||||||
|
nohup "$BINDIR/welcomebot.py" > /dev/null 2>>"$HOMEDIR/welcomebot.log" &
|
Loading…
Reference in New Issue
Block a user