#!/usr/bin/perl # -*- cperl -*- package Misc; use cybot; register_command("fortune", sub{ my ($bot,$chan,$nick,$host,@cmd) = @_; my @fortune = `fortune`; for (@fortune) { $bot->message($chan,$_); } }, "shows a random fortune from the unix fortune command"); register_command("whoami", sub{ my ($bot,$chan,$nick,$host,@cmd) = @_; $bot->message($chan,"$nick with mask $host"); }, "debug function. Says who are you!"); register_command("help",sub { my ($bot,$chan,$nick,$host,@cmd) = @_; my @msg; if (@cmd) { if (defined($bot->{help}{$cmd[0]})) { @msg = split/\n/,"$cmd[0]: $bot->{help}{$cmd[0]}"; } else { @msg = ("$cmd[0]: command unkown."); } } else { @msg = (join(" - ", sort keys %{$bot->{commands}})); } for (@msg) { $bot->message($chan, $_); } },"gives some help. Try 'help '"); register_command("uptime",sub { my ($bot,$chan) = @_; $bot->message($chan, `uptime`); },"shows system uptime"); register_command("time",sub { my ($bot,$chan,$nick,$host) = @_; if ($host =~ m!\.(gov|edu|com|org|net|mil|\d+)$!) { $bot->message($chan, "Where are you? "); } else { $host =~ m!\.([^.]*)$!; my $country = $1; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); if ($country eq "au") { $hour += 8; time_show($bot,$chan,"$country west",$hour,$min); $min+=30; time_show($bot,$chan,"$country center",$hour,$min); $min+=30; time_show($bot,$chan,"$country east",$hour,$min); } else { if ($country eq "no") { $hour += 1; } if ($country eq "fr") { $hour += 1; } if ($country eq "dk") { $hour += 1; } if ($country eq "jp") { $hour += 8; } time_show($bot,$chan,$country,$hour,$min); } } },"shows user date"); register_command("uname", sub { my ($bot,$chan) = @_; $bot->message($chan, `uname -a`); },"shows system information"); register_command("ping", sub { my ($bot,$chan,$nick,$host) = @_; my $sock = $bot->{sock}; $ctcpchan = $chan; $pinged = 1; my $stamp = time; printf $sock ("PRIVMSG $nick :%cPING $stamp%c\r\n", 1, 1); },"pings you"); register_command("die", sub { my ($bot,$chan,$nick,$host, @args) = @_; my $msg = @args?join(" ",@args):"Quitting on command of $nick"; my $sock = $bot->{sock}; if ($nick eq $bot->{boss} && $bot->{chost} eq $bot->{bossmask}) { print $sock "QUIT :$msg\r\n"; } else { $bot->message($chan, "$nick: You die first!"); } },"kills you!"); register_command("say", sub{ my ($b,$c,$n,$host,@a) = @_; $b->message($c, join(" ",@a)); },"says something"); register_command("kick", sub{ my ($b,$c,$n,$host,$v,@a) = @_; my $s = $b->{sock}; my $r = (@a)?join(" ",@a):"Requested by $n"; print $s "KICK $c $v :$r\r\n"; },"kick the user (kick )"); register_command("op", sub{ my ($bot,$c,$n,$host,@a) = @_; my $s = $bot->{sock}; if (get_userlevel($n, $userhosts{$n}) >= 25) { if (!@a || grep {$_ eq "me"} @a) { print $s "MODE $c +oooo $n\r\n"; } else { print $s "MODE $c +oooo @a\r\n"; } } },"gives op flag to... (op )"); register_command("deop", sub{ my ($b,$c,$n,$host,@a) = @_; my $s = $b->{sock}; @a = ($n) unless @a; print $s "MODE $c -oooo @a\r\n"; },"takes op flag from... (deop )"); register_command("raw", sub{ my ($b,$c,$n,$host,@a) = @_; my $s = $b->{sock}; print $s join(" ",@a),"\r\n"; },"sends a raw IRC command (raw )"); register_command("part", sub{ my ($b,$c,$n,$host,@a) = @_; my $sock = $b->{sock}; print $sock "PART $c :Parting ",join(" ",@a),"\r\n"; },"Sends me out of the channel"); register_command("me", sub{ my ($b,$c,$n,$host,@a) = @_; $b->action($c, join(" ",@a)); },"does an action (me s)"); register_command("topic", sub { my ($b,$c,$n,$host,$cmd,@a) = @_; my $sock = $b->{sock}; $c = lc($c); if ($cmd eq "add") { $topic = "$topics{$c} | ".join(" ",@a); } elsif ($cmd eq "netsplit") { $topic = $topics{$c}; } else { $topic = "$cmd".join(" ",@a); } print $sock "TOPIC $c :$topic\r\n"; $topics{$chan} = $topic; }, "sets the topic (topic add ) (topic ) (topic netplit)"); sub time_show { my ($bot,$chan,$country,$hour,$min) = @_; if ($min > 59) { $min-=60; $hour ++; } if ($hour > 23) { $hour = $hour - 24; $day++; } $bot->message($chan, ".$country: $hour:$min"); } 1;