Browse Source

Ajout du systeme de bot pour le topic de FDN

Julien Vaubourg 12 years ago
parent
commit
431bd7a1c0
4 changed files with 131 additions and 0 deletions
  1. 16 0
      fdnTopicAddBot/07-fdn
  2. 12 0
      fdnTopicAddBot/INSTALL
  3. 29 0
      fdnTopicAddBot/fdn-accbot
  4. 74 0
      fdnTopicAddBot/fdn-accbot.pl

+ 16 - 0
fdnTopicAddBot/07-fdn

@@ -0,0 +1,16 @@
+<VirtualHost 10.0.0.143>
+        ServerAdmin sys@listes.ldn-fai.net
+        ServerName fdn.ldn-fai.net
+        DocumentRoot /var/www/fdn
+
+        UseCanonicalName Off
+
+        <Directory /var/www/fdn>
+                Order allow,deny
+                allow from all
+        </Directory>
+
+        LogLevel warn
+        ErrorLog ${APACHE_LOG_DIR}/papillon/error-fdn.log
+        CustomLog ${APACHE_LOG_DIR}/papillon/access-fdn.log combined
+</VirtualHost>

+ 12 - 0
fdnTopicAddBot/INSTALL

@@ -0,0 +1,12 @@
+apt-get install libbot-basicbot-perl
+
+mv fdn-accbot.pl /usr/local/bin/
+mv fdn-accbot /etc/init.d/
+mv 07-fdn /etc/apache2/sites-available
+
+chmod +x /usr/local/bin/fdn-accbot.pl /etc/init.d/fdn-accbot
+update-rc.d fdn-accbot defaults
+service fdn-accbot start
+
+a2ensite 07-fdn
+service apache2 reload

+ 29 - 0
fdnTopicAddBot/fdn-accbot

@@ -0,0 +1,29 @@
+/bin/bash: q: command not found
+### BEGIN INIT INFO
+# Provides:          perl
+# Required-Start:
+# Required-Stop:
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Lance le bot qui surveille le topic de #fdn
+# Description:       Lance le bot qui surveille le topic de #fdn
+### END INIT INFO
+
+case "$1" in
+  start)
+        echo "Starting fdn-accbot.pl..."
+        /usr/local/bin/fdn-accbot.pl /var/www/fdn/index.html &
+        ;;
+
+  stop)
+        echo "Stopping fdn-accbot.pl..."
+        /bin/kill $(/bin/ps -eo '%p%a' | /bin/grep fdn-accbot | /bin/grep -v grep | /usr/bin/awk '{ print $1 }') 2> /dev/null
+        ;;
+
+  *)
+        echo "Usage: $0 {start|stop}" >&2
+        exit 1
+        ;;
+esac
+
+exit 0

+ 74 - 0
fdnTopicAddBot/fdn-accbot.pl

@@ -0,0 +1,74 @@
+#!/usr/bin/perl
+
+package Bot;
+use base qw(Bot::BasicBot);
+use warnings;
+use strict;
+
+if(! -w $ARGV[0]) {
+	print "ERREUR: $ARGV[0] est inexistant ou non-inscriptible.\n";
+	exit 1;
+}
+
+my $nick = "accbot";
+my $chan = "#fdnbottest";
+my $url = "http://fdn.ldn-fai.net";
+my $file = $ARGV[0];
+my $flag = "[ACC]";
+
+my $isacc = 0;
+my $bot;
+
+sub said {
+	my $self = shift;
+	my $message = shift;
+
+	if($message->{"address"} eq $nick || $message->{"address"} eq "msg") {
+		$self->reply($message, "$url - SYNTAXE : /topic N'importe quoi $flag Description de l'accident");
+	}
+}
+
+sub topic {
+	my $self = shift;
+	my $args = shift;
+
+	if($args->{"topic"}) {
+		if($args->{"topic"} =~ /^.*\Q$flag\E\s*(.+)$/) {
+			$isacc = 1;
+
+			open(OUT, ">$file");
+			print OUT "$1";
+			close(OUT);
+
+			$bot->emote(
+				channel => $chan,
+				body => "a bien reporté l'accident sur $url"
+			);
+		} elsif($isacc) {
+			$isacc = 0;
+
+			open(OUT, ">$file");
+			print OUT "";
+			close(OUT);
+
+			$bot->emote(
+				channel => $chan,
+				body => "a bien pris en compte la fin de l'accident ($url)"
+			);
+		}
+	}
+}
+
+$bot = Bot->new(
+	server => "irc.geeknode.org",
+	port => "6667",
+	channels => [$chan],
+	nick => $nick,
+	alt_nicks => ["${nick}_"],
+	username => $nick,
+	name => $url
+);
+
+$bot->run();
+
+exit 0;