|
@@ -0,0 +1,231 @@
|
|
|
+# This script responds with a comment each time someone in the channel says "clockbot"
|
|
|
+#
|
|
|
+# This script requires you to have the text file "clockbot" in your /home/user/.irssi/ directory
|
|
|
+#
|
|
|
+# cat ~/signatures/sig-natures | sed 's/^%$/####/;'| tr '\n' ' ' | sed 's/[[:space:]]\+/ /g;s/[[:space:]]####[[:space:]]/\n/g;' > ../../clockbot
|
|
|
+
|
|
|
+use Irssi;
|
|
|
+
|
|
|
+use vars qw($VERSION %IRSSI);
|
|
|
+use POSIX qw(strftime);
|
|
|
+
|
|
|
+use LWP::UserAgent;
|
|
|
+
|
|
|
+$VERSION = "1.2.2";
|
|
|
+
|
|
|
+%IRSSI = (
|
|
|
+ author => 'pleia2',
|
|
|
+ contact => 'lyz@princessleia.com ',
|
|
|
+ name => 'TC-14',
|
|
|
+ description => 'Protocol Droid, dedicated to Lautre.roots',
|
|
|
+ license => 'GNU GPL v2 or later',
|
|
|
+ url => 'http://www.lautre.net/',
|
|
|
+);
|
|
|
+open ( CLOCKPO, "<.irssi/quotes" ) or die "can't open clockbot:$!\n";
|
|
|
+chomp( @clockpo = <CLOCKPO> );
|
|
|
+close CLOCKPO;
|
|
|
+
|
|
|
+srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip -f`);
|
|
|
+
|
|
|
+my $changefile="/home/tc-14/var/changelog";
|
|
|
+my $last_tweet="";
|
|
|
+my $debug=0;
|
|
|
+my $bingo=0;
|
|
|
+my $last='';
|
|
|
+my $warn='';
|
|
|
+my @dad=("asr", "asr`", "asr_", "asr\\", "asr`_");
|
|
|
+
|
|
|
+my $timeout=30;
|
|
|
+my $warndate=time()-$timeout;
|
|
|
+
|
|
|
+Irssi::settings_add_str($IRSSI{name}, # default fifo_remote_file
|
|
|
+ 'tc_chans', '#flood #starwars'); #
|
|
|
+Irssi::settings_add_str($IRSSI{name}, # default fifo_remote_file
|
|
|
+ 'tc_admins', 'asr coin plop'); #
|
|
|
+Irssi::settings_add_str($IRSSI{name}, # default fifo_remote_file
|
|
|
+ 'tc_changefile', '/home/tc-14/var/last.log'); #
|
|
|
+
|
|
|
+my @chan=split m/ /, Irssi::settings_get_str("tc_chan");
|
|
|
+my @admin_chan=split m/ /, Irssi::settings_get_str("tc_admins");
|
|
|
+my $change=Irssi::settings_get_str("tc_changefile");
|
|
|
+
|
|
|
+sub in_array {
|
|
|
+ my ($arr,$search_for) = @_;
|
|
|
+ return grep {$search_for eq $_} @$arr;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+sub gazouille {
|
|
|
+ my ( $user, $pass ) = qw ( lautrenet OoD0aiph );
|
|
|
+ my $message = $_[0];
|
|
|
+ my $url = 'http://identi.ca/api/statuses/update.xml';
|
|
|
+ my $ua = LWP::UserAgent->new ();
|
|
|
+ my $req = HTTP::Request->new ( POST => $url );
|
|
|
+
|
|
|
+ $req->headers->authorization_basic( $user, $pass );
|
|
|
+ $req->content("status=$message");
|
|
|
+ $req->content_type('application/x-www-form-urlencoded');
|
|
|
+ my $res = $ua->request ($req);
|
|
|
+
|
|
|
+ return $res->is_success;
|
|
|
+}
|
|
|
+
|
|
|
+sub event_privmsg {
|
|
|
+
|
|
|
+my ($server, $data, $nick, $mask) =@_;
|
|
|
+my ($target, $text) = $data =~ /^(\S*)\s:(.*)/;
|
|
|
+
|
|
|
+ #print ( "C:$target X:$text A:$admin D:$warndate L:$last W:$warn N:$nick D:$data" );
|
|
|
+
|
|
|
+ sub send_server($$$$) {
|
|
|
+ my ($action,$cible,$pseudo,$msg)=@_;
|
|
|
+ $server->command ( "msg $target SWarn C:$cible X:$action A:$admin D:$warndate L:$last W:$warn N:$pseudo T:$msg" ) unless ($debug == 0);
|
|
|
+ if (in_array(@chan,$target) || in_array(@admin_chan,$pseudo))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+ if (($warndate + $timeout) < time()) {
|
|
|
+ $warn='';
|
|
|
+ $last='';
|
|
|
+ }
|
|
|
+ if (!($warn eq $pseudo)) {
|
|
|
+ if ($last eq $pseudo) {
|
|
|
+ $server->command ( "msg $cible $pseudo: Chut.");
|
|
|
+ $warn=$nick;
|
|
|
+ } else {
|
|
|
+ $server->command ( "$action $cible $msg" );
|
|
|
+ $last=$nick;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $server->command ( "msg $cible $pseudo bloque pour $timeout" ) unless $debug=0;
|
|
|
+ }
|
|
|
+ $warndate=time();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ my $admin=0;
|
|
|
+
|
|
|
+ if (in_array(@chan,$target) || in_array(@admin_chan,$target))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach $father (@dad) {
|
|
|
+ if ($father eq $nick) {
|
|
|
+ $admin=1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( $text =~ /^!tweet\s*(.*)/) {
|
|
|
+ if (in_array(@admin_chan, $target)) { return ; }
|
|
|
+ if ($1 eq '') { $server->command("msg $target $nick: Usage: !tweet <<message>>"); } #$server->command ( "msg $target $nick: !tweet <<mesage>>" ); }
|
|
|
+ elsif ($1 eq 'changelog') {
|
|
|
+ open ( CHANGL, "tail -n1 $changefile |" ) or $server->command ( "msg $target $nick: fichier vide" );
|
|
|
+ #chomp( @temp = <CHANGL> );
|
|
|
+ #foreach $line (@temp) {
|
|
|
+ # $last_tweet=$line;
|
|
|
+ # if (gazouille ($line)) {
|
|
|
+ # $clocky = $clockpo[rand @clockpo];
|
|
|
+ # $server->command("msg $target Gazouilli posté! $clocky") unless ($nick =~ /edgard/i);
|
|
|
+ # }
|
|
|
+ # else
|
|
|
+ # {
|
|
|
+ # $server->command ("msg $target $nick: Erreur lors du post du message");
|
|
|
+ # }
|
|
|
+ #}
|
|
|
+ close ( CHANGL );
|
|
|
+ }
|
|
|
+ elsif ($1 eq 'last') {
|
|
|
+ $server->command("msg $target $nick: Last tweet was:");
|
|
|
+ $server->command("msg $target $nick: $last_tweet");
|
|
|
+ }
|
|
|
+ elsif (length($1)>139) { $server->command("msg $target $nick: Message trop long, plus de 139 caractères." ); }
|
|
|
+ else {
|
|
|
+ # $server->command("msg $target Message: $nick |$1|");
|
|
|
+ $last_tweet=$1;
|
|
|
+ if (gazouille ($1)) {
|
|
|
+ $clocky = $clockpo[rand @clockpo];
|
|
|
+ $server->command("msg $target Gazouilli posté! $clocky") unless ($nick =~ /edgard/i);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $server->command ("msg $target $nick: Erreur lors du post du message");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ elsif ( $text =~ /^!changelog( .+)?/ ) {
|
|
|
+ if (in_array(@admin_chan,$target))
|
|
|
+ { return; }
|
|
|
+ if ($1 eq '') { $server->command ( "msg $target $nick: !changelog (list|add) [<serveur> [<liste d'actions>]]" );
|
|
|
+ } elsif ($1 =~ /^ last( .+)?/) {
|
|
|
+ open ( CHANGL, "tail -n1 $changefile |" ) or $server->command ( "msg $target $nick: fichier vide" );
|
|
|
+ chomp( @temp = <CHANGL> );
|
|
|
+ foreach $line (@temp) {
|
|
|
+ $server->command ( "msg $target $nick: $line" );
|
|
|
+ }
|
|
|
+ close ( CHANGL );
|
|
|
+ } elsif ($1 =~ /^ list( .+)?/) {
|
|
|
+ undef @temp;
|
|
|
+ if ($1 eq '') {
|
|
|
+ $server->command ( "msg $target $nick: changelog total (20 lignes) en pv." );
|
|
|
+ open ( CHANGL, "tail $changefile |" ) or $server->command ( "msg $target $nick: fichier vide" );
|
|
|
+ } else {
|
|
|
+ my $pattern = $1;
|
|
|
+ $pattern =~ s/^ //;
|
|
|
+ $pattern =~ s/['"\$]/_/g;
|
|
|
+ $server->command ( "msg $target $nick: changelog pour '$pattern' (20 lignes) en pv" );
|
|
|
+ open ( CHANGL, "/home/tc-14/bin/tailgrep $changefile '$pattern' |" ) or $server->command ( "msg $target $nick: erreur de pattern ou fichier vide" );
|
|
|
+ }
|
|
|
+ chomp( @temp = <CHANGL> );
|
|
|
+ close CHANGL;
|
|
|
+ foreach $line (@temp) {
|
|
|
+ $server->command ( "msg $nick $line" );
|
|
|
+ }
|
|
|
+ } elsif ($1 =~ /^ add ([^ ]+) (.+)/) {
|
|
|
+ my $locdate=strftime "%d/%m/%Y %H:%M", localtime;;
|
|
|
+ open ( CHANGL, ">> $changefile" ) or $server->command ( "msg $target $nick: erreur de fichier... (O)" );
|
|
|
+ printf CHANGL "%s", "$locdate : $1 - $nick - $2\n" or $server->command ( "msg $target $nick: erreur de fichier... (W)" );
|
|
|
+
|
|
|
+ close CHANGL or $server->command ( "msg $target $nick: erreur de fichier... (C)" );
|
|
|
+ $clocky = $clockpo[rand @clockpo];
|
|
|
+ send_server("msg", $target, $nick, $clocky) unless ($nick =~ /edgard/i);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ $server->command ( "msg $target $nick: !changelog (list|add|last) [<serveur> [<liste d'actions>]]" );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ elsif ( $text =~ /^!lastlog( .+)?/ ) {
|
|
|
+ if (in_array(@admin_chan,$target))
|
|
|
+ { return; }
|
|
|
+ if ($1 eq '') { $server->command ( "msg $target $nick: !lastlog list [<liste d'actions>]" );
|
|
|
+ } elsif ($1 =~ /^ list( .+)?/) {
|
|
|
+ undef @temp;
|
|
|
+ if ($1 eq '') {
|
|
|
+ $server->command ( "msg $target $nick: lastlog total (20 lignes) en pv." );
|
|
|
+ open ( CHANGL, "tail $logfile |" ) or $server->command ( "msg $nick fichier vide" );
|
|
|
+ } else {
|
|
|
+ my $pattern = $1;
|
|
|
+ $pattern =~ s/^ //;
|
|
|
+ $pattern =~ s/['"\$]/_/g;
|
|
|
+ $server->command ( "msg $target $nick: lastlog pour '$pattern' (20 lignes) en pv." );
|
|
|
+ open ( CHANGL, "/homet/tc-14/bin/tailgrep $logfile '$pattern' |" ) or $server->command ( "msg $target $nick: erreur de pattern ou fichier vide" );
|
|
|
+ }
|
|
|
+ chomp( @temp = <CHANGL> );
|
|
|
+ close CHANGL;
|
|
|
+ foreach $line (@temp) {
|
|
|
+ $server->command ( "msg $nick $line" );
|
|
|
+ }
|
|
|
+ } else { $server->command ( "msg $target $nick: !lastlog list [<liste d'actions>]" );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($debug == 1) {
|
|
|
+ $server->command ( "msg $target D1 A:$admin L:$last W:$warn N:$nick B:$bingo" );
|
|
|
+ my $locdate=time()-$warndate;
|
|
|
+ $server->command ( "msg $target D2 W:$warndate T1:".time." T2:$locdate" );
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+Irssi::signal_add('event privmsg', 'event_privmsg');
|
|
|
+Irssi::signal_add("message public", "event_privmsg");
|
|
|
+
|
|
|
+print $IRSSI{"name"}." loaded $VERSION.";
|