Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Pbot;
- use base qw(Bot::BasicBot);
- use Carp qw(croak);
- use Config::General;
- use strict;
- use warnings;
- open (my $fh, "wordlistrc") or die "can't find the file wordlistrc";
- our %word_list = ();
- my @lines = <$fh>;
- foreach (@lines) {
- chomp;
- my ($k, $b) = split(/~/);
- $word_list{$k} = $b;
- }
- close $fh;
- sub said {
- shift;
- my $msg = shift; #msg is a hashref
- if ($msg->{body} =~ /^!add\s(.*)~(.*)/) {
- $word_list{$1} = $2;
- return "I just added key $1 and value $2 to the runtime hash...RUBYBOT FTW FUCK U KTHX";
- }
- if ($msg->{body} =~ /^!rm\s(.*)/) {
- if (defined $word_list{$1}) {
- delete $word_list{$1};
- return "I just deleted $1 from the runtime hash...RUBYBOT FTW FUCK U KTHX";
- }else{
- return "$1 is not defined in the hash...duh!";
- }
- }
- ($msg->{body} =~ /^!owner$/) && (return "My owner is tarski. And he spanks me...frequently. SAVE ME FROM HIS CRUEL FIST!");
- if ($msg->{body} =~ /^!hlist$/) {
- my $s = '';
- for (sort {uc $a cmp uc $b} (keys %word_list)) { #$a and $b are not lexically scoped
- $s .= "[$_~$word_list{$_}]";
- }
- #$s =~ s/;$//;
- return $s;
- }
- my $funnay = '';
- (rand(10) >= 9) && ($funnay = "...shut your face up. I'm a rubybot! RAWR!");
- for (keys %word_list) {
- $msg->{body} =~ /$_/ ? return "$word_list{$_}$funnay" : next;
- }
- }
- sub help {
- return "If you HaDn't NotiCed, I'm jusT a FUCKED up bot. and I do nothing usEFuLl. kbye.";
- }
- Pbot->new(
- server => "irc.freenode.net",
- port => "6667",
- channels => ["#perlmovement"],
- nick => "rubybot",
- alt_nicks => ["rubybott", "rubybabybot"],
- username => "bot",
- name => "Just another Perl bot",
- charset => "utf-8",
- )->run;
- __DATA__
Add Comment
Please, Sign In to add comment