summaryrefslogtreecommitdiff
path: root/d
diff options
context:
space:
mode:
Diffstat (limited to 'd')
-rwxr-xr-xd/sys/lampion/local/sbin/apbteambot123
-rwxr-xr-xd/sys/lampion/local/sbin/apbteambot-say17
-rwxr-xr-xd/sys/lampion/local/sbin/post-commit11
3 files changed, 151 insertions, 0 deletions
diff --git a/d/sys/lampion/local/sbin/apbteambot b/d/sys/lampion/local/sbin/apbteambot
new file mode 100755
index 0000000..2188254
--- /dev/null
+++ b/d/sys/lampion/local/sbin/apbteambot
@@ -0,0 +1,123 @@
+#!/usr/bin/perl -w
+# apbteambot
+use strict;
+use Net::IRC;
+use IO::Socket::UNIX;
+use POSIX;
+
+#
+# Config.
+#
+
+my $server = 'irc.freenode.net';
+my $nick = 'APBTeamBot';
+my $username = 'apbteambot';
+my $chan = '#apbteam';
+
+my $socketname = '/var/run/apbteambot/sock';
+my $pidname = '/var/run/apbteambot/pid';
+
+#
+# Create the IRC and Connection objects
+#
+
+my $irc = new Net::IRC;
+
+print "Creating connection to $server as $nick...\n";
+
+my $conn = $irc->newconn(Server => $server,
+ Nick => $nick,
+ Username => $username)
+ or die "can not connect to $server: $!\n";
+
+#
+# Here are the handler subroutines.
+#
+
+# What to do when the bot successfully connects.
+sub on_connect {
+ my $self = shift;
+ #print "Joining $chan...\n";
+ $self->join($chan);
+ $self->privmsg($chan, "Coucou");
+}
+
+# Handles some messages you get when you connect
+sub on_init {
+ my ($self, $event) = @_;
+ my (@args) = ($event->args);
+ shift (@args);
+ #print "*** @args\n";
+}
+
+# Prints the names of people in a channel when we enter.
+sub on_names {
+ my ($self, $event) = @_;
+ my (@list, $channel) = ($event->args);
+ ($channel, @list) = splice @list, 2;
+ #print "Users on $channel: @list\n";
+}
+
+# Quit if taken.
+sub on_nick_taken {
+ die "Nick taken";
+}
+
+# Reconnect to the server when we die.
+sub on_disconnect {
+ my ($self, $event) = @_;
+ #print "Disconnected from ", $event->from(), " (",
+ #($event->args())[0], "). Attempting to reconnect...\n";
+ $self->connect();
+}
+
+print "Installing handler routines...";
+
+$conn->add_global_handler([ 251,252,253,254,302,255 ], \&on_init);
+$conn->add_global_handler('disconnect', \&on_disconnect);
+$conn->add_global_handler(376, \&on_connect);
+$conn->add_global_handler(433, \&on_nick_taken);
+$conn->add_global_handler(353, \&on_names);
+
+print " done.\n";
+
+# Server socket.
+
+unlink $socketname;
+my $socket = new IO::Socket::UNIX (Local => $socketname,
+ Listen => 5)
+ or die $!;
+chmod 0664, $socketname;
+
+sub on_socket {
+ my $client = $socket->accept ();
+ while (<$client>)
+ {
+ chomp;
+ $conn->privmsg($chan, $_);
+ }
+ $client->close ();
+}
+
+$irc->addfh ($socket, \&on_socket, "r");
+
+# Daemonize.
+
+print "starting...\n";
+
+my $pid = fork;
+die $! unless defined $pid;
+if ($pid)
+{
+ open PID, ">$pidname" or die $!;
+ print PID "$pid\n";
+ close PID;
+ exit 0;
+}
+POSIX::setsid ();
+close STDIN;
+close STDOUT;
+close STDERR;
+chdir "/";
+
+$irc->start;
diff --git a/d/sys/lampion/local/sbin/apbteambot-say b/d/sys/lampion/local/sbin/apbteambot-say
new file mode 100755
index 0000000..47c3ea6
--- /dev/null
+++ b/d/sys/lampion/local/sbin/apbteambot-say
@@ -0,0 +1,17 @@
+#!/usr/bin/perl -w
+# apbteambot-say
+use strict;
+use IO::Socket::UNIX;
+
+my $socketname = '/var/run/apbteambot/sock';
+
+# Client socket.
+
+my $socket = new IO::Socket::UNIX (Peer => $socketname)
+ or die $!;
+
+while (<STDIN>)
+{
+ print $socket $_;
+}
+$socket->close ();
diff --git a/d/sys/lampion/local/sbin/post-commit b/d/sys/lampion/local/sbin/post-commit
new file mode 100755
index 0000000..18cc328
--- /dev/null
+++ b/d/sys/lampion/local/sbin/post-commit
@@ -0,0 +1,11 @@
+#!/usr/bin/zsh
+
+REPOS=$1
+REV=$2
+AUTHOR=$(svnlook author -r $REV $REPOS)
+
+(
+echo "SVN commit r$REV by $AUTHOR in $REPOS:"
+svnlook log -r $REV $REPOS | sed -e '/^$/d' -e 's/^/| /'
+svnlook dirs-changed -r $REV $REPOS | sed -e 's/^/> /'
+) | /usr/local/sbin/apbteambot-say