Commit a2699ac8 authored by Mindiell's avatar Mindiell

modifications have been made in production.

parent b62e04e8
......@@ -2,3 +2,5 @@ wantzel.ini
config.py
*.pyc
db.sqlite3
wantzel.log
ve/
......@@ -39,7 +39,8 @@ Permet de gérer la liste des utilisateurs ayant un accès privilégié. Il n'y
Utilisations:
!admin list => Fournit la liste des utilisateurs privilégiés
!admin add user[, user]> => Ajoute un ou plusieurs utilisateurs à la liste
!admin del user[, user] => Supprime un ou plusieurs utilisateurs de la liste""",
!admin del user[, user] => Supprime un ou plusieurs utilisateurs de la liste
!admin timer => Relance un timer pour gérer le topic et les tweets""",
"rp_http":
"""Merci %s, mais je prends en compte uniquement les adresses internet qui commencent par http ou https""",
......@@ -57,7 +58,7 @@ Utilisations:
"""%s n'existe pas dans la base de données""",
"kill_done":
"""%s mit à -100""",
"""%s mis à -100""",
"stats_bravo":
"""Bravo les neurones, rien en retard depuis ces %s derniers jours!""",
......
#!/usr/bin/perl
use strict;
use diagnostics;
use warnings;
use Config::Simple;
use Net::IRC;
use DBI;
my %config;
Config::Simple->import_from('/var/www/site/rp/bots/wantzel.ini', \%config);
my $dsn = $config{'dsn'};
my $db_user_name = $config{'db_user_name'};
my $db_password = $config{'db_password'};
my $dbh = 0;
# Configuration des options de connexion (serveur, login) :
my $server = $config{'server'};
my $nick = $config{'nick'};
# Informations concernant le Bot :
my $ircname = $config{'ircname'};
my $username = $config{'username'};
my $version = $config{'version'};
# Channel sur lequel on veut que le Bot aille :
my $channel = $config{'channel'};
my $irc = new Net::IRC;
# On cre l'objet de connexion IRC :
my $conn = $irc->newconn(
'Server' => $server,
'Port' => 6667,
'Nick' => $nick,
'Ircname' => $ircname,
'Username' => $username
);
# On installe les fonctions de Hook :
$conn->add_handler('376', \&on_connect); # Fin du MOTD => on est connect
$conn->add_handler('public', \&on_public); # Sur le chan
$conn->add_handler('msg', \&on_private); # En priv
# On lance la connexion et la boucle de gestion des vnements :
$irc->start();
sub on_connect
{
my ($conn, $event) = @_;
$conn->join($channel);
$conn->privmsg($channel, 'Bonjour, je suis le bot de la Quadrature du Net, vous pouvez me demander de l\'aide si besoin. (wantzel help)');
print "<$nick>\t| Hi all, Pi\'s salutations\n";
$conn->{'connected'} = 1;
} # Fin on_connect
sub on_public
{
my ($conn, $event) = @_;
my $text = $event->{'args'}[0];
print "<" . $event->{'nick'} . ">\t| $text\n";
# Search for a url and store it ;)
my $s=$text;
my $who=$event->{'nick'};
if ($s =~ "wantzel" && ($s =~ "help" || $s =~ "aide")) {
$conn->privmsg($channel, "Toute l'aide se trouve ici : http://www.laquadrature.net/wiki/Wantzel");
}
if ($s =~ "!rp") {
if ($s =~ /(http[^\s)<\"]*)/) {
my $url=$1;
$url =~ s/\$/\\\$/g;
# Let's get rid of the trackers part to ensure uniq urls
$url =~ s/[?&](utm_medium|utm_source|utm_campaign|xtor)=[^&]*//g;
# Remove /#!/ part
$url =~ s=/#!/=/=g;
# Remove anchors
$url =~ s/#[^#]$//;
print "READ URL : $url\n";
my $sql=q{
SELECT * FROM presse WHERE url= ? ;
};
my $dbh = DBI->connect($dsn, $db_user_name, $db_password);
my $sth = $dbh->prepare($sql);
if (! $sth->execute($url) ) {
$conn->privmsg($channel, "oups, je n'ai pas pu la mettre en base, dsol ...");
die "Fatal: cannot RECONNECT !\n";
}
my @found = $sth->fetchrow_array();
$sth->finish(); # we're done with this query
if (!@found) {
my $cite=0;
if ($s =~ "!rpc" || $s =~ "!rpdc") {
$cite+=2;
}
if ($s =~ "!rpp" || $s =~ "!rpcp") {
$cite+=4;
}
$sth = $dbh->prepare(q{
INSERT INTO presse SET url= ?, provenance= ?, cite= ?, note= ?, datec=NOW();
});
my $note = 0;
if (($who =~ '^vinci$') ||
($who =~ '^gibus') ||
($who =~ 'theo.rite$') ||
# ($who =~ '^tekoo') ||
# ($who =~ '^ali?xc?$') ||
($who =~ '^Siltaar$') ||
($who =~ '^yost.d$') ||
0
) {
$note=3;
}
if (($who =~ '^.?jz$') ||
0
) {
$note=42;
}
# to archive the url
if ($s =~ "!rppa" || $s =~ "!rpcpa" || $s =~ "!rpa" || $s =~ '!rpca') {
$note=-2;
}
$sth->execute($url,"IRC(".$event->{'nick'}.")",$cite,$note);
my $id=$dbh->last_insert_id(undef, undef, undef, undef);
print "NOT FOUND, INSERTED AS $id\n";
if ($who =~ "alxc") {
$conn->privmsg($channel, "Merci alix, j'ai ajoute ce bel article a notre fabuleuse memoire presse !");
} else {
$conn->privmsg($channel, 'Merci, cette url a ete ajoutee a la revue de presse ;)');
}
} else {
if ($found['provenance'] != "IRC(".$event->{'nick'}.")") {
$sth = $dbh->prepare(q{
UPDATE presse SET note=note+1 WHERE id = ?
});
$sth->execute($found['id']);
}
print "FOUND\n";
if ($who =~ "alxc") {
$conn->privmsg($channel, "Merci alix, j'avais deja cet article dans la revue de presse, mais merci tout de meme de me l'avoir signale a nouveau, c'est utile.");
} else {
$conn->privmsg($channel, 'Merci, mais cette url etait deja dans la revue de presse.');
}
}
$url=~s/[\?\/\\\(\)\+]/./g;
$s=~s/$url//;
$dbh->disconnect();
} # cherche les urls
} # a-t-on "!rp" dans le message
elsif ($s =~ "!stats") {
my @period=(1, 3, 7, 15);
my @note=(0, 3, 4);
my $msg='stats rp';
my $notnull=0;
my $somethingatall=0;
my $tmpmsg='';
foreach my $note (@note)
{
$notnull=0;
$tmpmsg=' => note >= '.$note;
foreach my $period (@period)
{
my $sql='SELECT COUNT(id) AS cid
FROM presse
WHERE nid=0
AND datec>(NOW()-INTERVAL ? DAY)
AND note>=?';
my $dbh = DBI->connect($dsn, $db_user_name, $db_password);
my $sth = $dbh->prepare($sql);
die "Fatal: cannot RECONNECT !\n" unless ($sth->execute($period, $note));
my @found=$sth->fetchrow_array();
$sth->finish(); # we're done with this query
if ($found['cid']>0) {
$tmpmsg.=", ${period}j:$found['cid']";
$notnull=1;
$somethingatall=1;
}
}
if ($notnull!=0) {
$msg.=$tmpmsg;
$msg.='\n';
}
}
if ($somethingatall==0) {
$msg.=" Bravo les gars, rien en retard depuis ces ".$period[$#period-1]." derniers jours ! felicitation !";
}
$conn->privmsg($channel, $msg);
} # !stats
if ($s =~ '!tc help') {
$conn->privmsg($channel, "Pour signaler un vnement dans les dbats l'Assemble Nationale, tapez !tc<espace>suivi du texte decrivant l'vnement : n'oubliez pas le Nom de l'intervenant ainsi que le verbe dcrivant son action.");
$conn->privmsg($channel, "Par exemple : !tc Albanel parle de fabrication d'adresses IP");
$conn->privmsg($channel, "Ou encore : !tc Billard / Brard dfendent les auteurs plutt que les majors");
} else {
if ($s =~ '!tc (.*)$') {
my $TC=$1;
print "READ TIMECODE : $TC\n";
my $dbh = DBI->connect($dsn, $db_user_name, $db_password);
my $sth = $dbh->prepare(q{
INSERT INTO tclive SET user= ?, description= ?;
});
$sth->execute($event->{'nick'},$TC);
$conn->privmsg($channel, 'timecode recorded');
} # a-t-on "!tc" dans le message
if ($s =~ /^\!quote/)
{
if (my($quote, $author, $url, $source)=($s =~ /^\!quote\s+"(.+)"\s+(.+)\s+(https?\:\/\/[\S]+)\s+(.+)/))
{
#$conn->privmsg($channel, "quote: $quote");
#$conn->privmsg($channel, "auteur: $auteur");
#$conn->privmsg($channel, "url: $url");
#$conn->privmsg($channel, "source: $source");
my $sql='INSERT INTO quotes
(submited_by, quote, author, url, source, date, note)
VALUES
( ?, ?, ?, ?, ?, NOW(), ?)';
my $dbh = DBI->connect($dsn, $db_user_name, $db_password);
my $sth = $dbh->prepare($sql);
die "Fatal: cannot RECONNECT !\n" unless
($sth->execute($who, $quote, $author, $url, $source,1));
$sth->finish();
$conn->privmsg($channel, "C'est dans la boite !");
}
else
{
$conn->privmsg($channel, "Pour ajouter une citation tapez : !quote \"la citation\" l'auteur http://url la source");
}
} # a-t-on "!quote" dans le message
}
} # Fin on_public
sub on_private
{
my ($conn, $event) = @_;
my $text = $event->{'args'}[0];
$conn->print("PRIVE<" . $event->nick() . ">\t| $text");
} # Fin on_private
#!/usr/bin/perl
use strict;
use diagnostics;
use warnings;
use Net::IRC;
use DBI;
my $dsn = 'DBI:mysql:pi_prod:localhost';
my $db_user_name = 'root';
my $db_password = 'poipoi';
my $dbh = 0;
# Configuration des options de connexion (serveur, login) :
my $server = 'irc.freenode.net';
my $nick = 'wantzel';
# Informations concernant le Bot :
my $ircname = 'Squaring the net mathematician expert';
my $username = 'wantzel';
my $version = '1.0';
# Channel sur lequel on veut que le Bot aille :
my $channel = '#laquadrature';
my $irc = new Net::IRC;
# On crée l'objet de connexion à IRC :
my $conn = $irc->newconn(
'Server' => $server,
'Port' => 6667,
'Nick' => $nick,
'Ircname' => $ircname,
'Username' => $username
);
# On installe les fonctions de Hook :
$conn->add_handler('376', \&on_connect); # Fin du MOTD => on est connecté
$conn->add_handler('public', \&on_public); # Sur le chan
$conn->add_handler('msg', \&on_private); # En privé
# On lance la connexion et la boucle de gestion des événements :
$irc->start();
sub on_connect
{
my ($conn, $event) = @_;
$conn->join($channel);
$conn->privmsg($channel, 'Bonjour, je suis le BOT de la quadrature du net, vous pouvez me demander de l\'aide si besoin. (wantzel help)');
print "<$nick>\t| Hi all, Pi\'s salutation\n";
$conn->{'connected'} = 1;
} # Fin on_connect
sub on_public
{
my ($conn, $event) = @_;
my $text = $event->{'args'}[0];
print "<" . $event->{'nick'} . ">\t| $text\n";
# Search for a url and store it ;)
my $s=$text;
my $who=$event->{'nick'};
if ($s =~ "wantzel" && ($s =~ "help" || $s =~ "aide")) {
# $conn->privmsg($channel, "Alors, tapez !rp puis une url pour l'inclure a la revue de presse. Si elle cite la quadrature, ajoutez c, si elle en parle, ajoutez p (!rpcp)");
# $conn->privmsg($channel, "Pour des stats sur les dernières revues de presse non publiés, essyez !stats");
# $conn->privmsg($channel, "enfin, pour signaler un évènement dans les débats à l'Assemblée Nationale, tapez !tc<espace>suivi du texte decrivant l'évènement : n'oubliez pas le Nom de l'intervenant ainsi que le verbe décrivant son action.");
# $conn->privmsg($channel, "Par exemple : !tc Albanel parle de fabrication d'adresses IP");
}
if ($s =~ "!rp") {
while ($s =~ "(http[^ \)\<\"\n\t\r]*)") {
my $url=$1;
print "READ URL : $url\n";
my $sql=q{
SELECT * FROM presse WHERE url= ? ;
};
my $dbh = DBI->connect($dsn, $db_user_name, $db_password);
my $sth = $dbh->prepare($sql);
if (! $sth->execute($url) ) {
$conn->privmsg($channel, "oups, je n'ai pas pu la mettre en base, désolé ...");
die "Fatal: cannot RECONNECT !\n";
}
my @found = $sth->fetchrow_array();
$sth->finish(); # we're done with this query
if (!@found) {
my $cite=0;
if ($s =~ "!rpc" || $s =~ "!rpdc") {
$cite+=1;
}
if ($s =~ "!rpp" || $s =~ "!rpcp") {
$cite+=2;
}
$sth = $dbh->prepare(q{
INSERT INTO presse SET url= ?, provenance= ?, cite= ?, note= ?, datec=NOW();
});
my $note = 0;
if (($who =~ '^.?jz$') ||
($who =~ '^vinci$') ||
($who =~ '^gibus') ||
($who =~ 'theo.rite$') ||
($who =~ '^tekoo') ||
($who =~ '^ali?xc?$') ||
0
) {
$note=3;
}
$sth->execute($url,"IRC(".$event->{'nick'}.")",$cite,$note);
my $id=$dbh->last_insert_id(undef, undef, undef, undef);
print "NOT FOUND, INSERTED AS $id\n";
if ($who =~ "alxc") {
$conn->privmsg($channel, "Merci alix, j'ai ajoute ce bel article a notre fabuleuse memoire presse !");
} else {
$conn->privmsg($channel, 'Merci, cette url a ete ajoutee a la revue de presse ;)');
}
} else {
if ($found['provenance'] != "IRC(".$event->{'nick'}.")") {
$sth = $dbh->prepare(q{
UPDATE presse SET note=note+1 WHERE id = ?
});
$sth->execute($found['id']);
}
print "FOUND\n";
if ($who =~ "alxc") {
$conn->privmsg($channel, "Merci alix, j'avais deja cet article dans la revue de presse, mais merci tout de meme de me l'avoir signale a nouveau, c'est utile.");
} else {
$conn->privmsg($channel, 'Merci, mais cette url etait deja dans la revue de presse.');
}
}
$url=~s/[\?\/\\\(\)\+]/./g;
$s=~s/$url//;
$dbh->disconnect();
} # cherche les urls
} # a-t-on "!rp" dans le message
elsif ($s =~ "!stats") {
my @period=(1, 3, 7, 15);
my @note=(2, 5, 10);
my $msg='stats rp';
my $notnull=0;
my $somethingatall=0;
my $tmpmsg='';
foreach my $note (@note)
{
$notnull=0;
$tmpmsg=' => note>'.$note;
foreach my $period (@period)
{
my $sql='SELECT COUNT(id) AS cid
FROM presse
WHERE nid=0
AND datec>(NOW()-INTERVAL ? DAY)
AND note>?';
my $dbh = DBI->connect($dsn, $db_user_name, $db_password);
my $sth = $dbh->prepare($sql);
die "Fatal: cannot RECONNECT !\n" unless ($sth->execute($period, $note));
my @found=$sth->fetchrow_array();
$sth->finish(); # we're done with this query
if ($found['cid']>0) {
$tmpmsg.=", ${period}j:$found['cid']";
$notnull=1;
$somethingatall=1;
}
}
if ($notnull!=0) {
$msg.=$tmpmsg;
}
}
if ($somethingatall==0) {
$msg.=" Bravo les gars, rien en retard depuis ces ".$period[$#period-1]." derniers jours ! felicitation !";
}
$conn->privmsg($channel, $msg);
} # !stats
if ($s =~ '!tc help') {
$conn->privmsg($channel, "Pour signaler un évènement dans les débats à l'Assemblée Nationale, tapez !tc<espace>suivi du texte decrivant l'évènement : n'oubliez pas le Nom de l'intervenant ainsi que le verbe décrivant son action.");
$conn->privmsg($channel, "Par exemple : !tc Albanel parle de fabrication d'adresses IP");
$conn->privmsg($channel, "Ou encore : !tc Billard / Brard défendent les auteurs plutôt que les majors");
} else {
if ($s =~ '!tc (.*)$') {
my $TC=$1;
print "READ TIMECODE : $TC\n";
my $dbh = DBI->connect($dsn, $db_user_name, $db_password);
my $sth = $dbh->prepare(q{
INSERT INTO tclive SET user= ?, description= ?;
});
$sth->execute($event->{'nick'},$TC);
$conn->privmsg($channel, 'timecode recorded');
} # a-t-on "!tc" dans le message
}
} # Fin on_public
sub on_private
{
my ($conn, $event) = @_;
my $text = $event->{'args'}[0];
$conn->print("PRIVE<" . $event->nick() . ">\t| $text");
} # Fin on_private
205a206,229
> if ($s =~ /^\!quote/)
> {
> if (my($quote, $auteur, $url, $source)=($s =~ /^\!quote\s+"(.+)"\s+(.+)\s+(https?\:\/\/[\S]+)\s+(.+)/))
> {
> #$conn->privmsg($channel, "quote: $quote");
> #$conn->privmsg($channel, "auteur: $auteur");
> #$conn->privmsg($channel, "url: $url");
> #$conn->privmsg($channel, "source: $source");
> my $sql='INSERT INTO Quote
> (User_Quote, Quote_Quote, Auteur_Quote, URL_Quote, Source_Quote, Date_Quote, Note_Quote)
> VALUES
> ( ?, ?, ?, ?, ?, NOW(), ?)';
> my $dbh = DBI->connect($dsn, $db_user_name, $db_password);
> my $sth = $dbh->prepare($sql);
> die "Fatal: cannot RECONNECT !\n" unless
> ($sth->execute($who, $quote, $auteur, $url, $source,1));
> $sth->finish();
> $conn->privmsg($channel, "C'est dans la boite !");
> }
> else
> {
> $conn->privmsg($channel, "Pour ajoutter une citation tapez : !quote \"la citation\" l'auteur http://url la source");
> }
> } # a-t-on "!quote" dans le message
......@@ -39,7 +39,14 @@ class Utils(object):
@classmethod
def log(cls, message):
with open(LOG_FILE, 'a') as f:
f.write("%s: %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), message.encode("utf-8")))
try:
f.write("%s: %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), message.encode("utf-8")))
except:
f.write("%s: Erreur de log\n" % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
try:
f.write("%s: %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), message))
except:
f.write("%s: Seconde erreur de log\n" % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
@classmethod
def debug(cls, message):
......@@ -146,6 +153,7 @@ class Wantzel(object):
row[0].encode("utf-8"),
"%Y-%m-%d %H:%M:%S %Z"
)
Utils.debug("Dernier tweet: %s" % self.last_entry_published)
self.irc = IrcClientFactory(config)
self.irc.set_privmsg = self.set_privmsg
reactor.connectTCP(config.server, config.port, self.irc)
......@@ -196,6 +204,8 @@ class Wantzel(object):
Add a new moderator to list
- moderate remove (*)
Remove a moderator from list
- moderate timer
Relaunch a timer
"""
# Cleaning user name
user = re.search("([^!]*)!", user).group(1)
......@@ -234,6 +244,8 @@ class Wantzel(object):
elif command=="admin":
Utils.debug("Calling self.admin")
self.admin(user, channel, msg)
elif command=="timer":
self.admin_timer(user, channel, msg)
# No more giving the title of an url
#if title and website:
# self.send_message(channel, messages["title"] % (title, website))
......@@ -452,6 +464,20 @@ class Wantzel(object):
else:
self.send_message(channel, messages["not_moderator"])
def admin_timer(self, user, channel, msg):
"""
Relaunch a timer.
"""
Utils.debug("admin_timer command")
if is_moderator(user):
try:
# Recalling the timer
reactor.callLater(config.timer, self.timer)
except:
pass
else:
self.send_message(channel, messages["not_moderator"])
def count_articles(self):
"""
Count number of articles not done in RP and updates the topic of the
......@@ -490,6 +516,7 @@ class Wantzel(object):
language = "en"
entries = feedparser.parse(rss)['entries']
entries.reverse()
Utils.debug(self.last_entry_published)
for entry in entries:
# if date of publication is greater than today, midnight, and
# lesser than future
......@@ -515,6 +542,9 @@ class Wantzel(object):
connection.commit()
# Tweet only one message in order not to spam
return
else:
Utils.debug(entry.title)
Utils.debug(entry.published_parsed)
def tweet(self, message):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment