Guest User

Untitled

a guest
Jul 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. package Pbot;
  2.  
  3. use base qw(Bot::BasicBot);
  4. use Carp qw(croak);
  5. use Config::General;
  6. use strict;
  7. use warnings;
  8.  
  9.  
  10. open (my $fh, "wordlistrc") or die "can't find the file wordlistrc";
  11. our %word_list = ();
  12. my @lines = <$fh>;
  13.  
  14. foreach (@lines) {
  15. chomp;
  16. my ($k, $b) = split(/~/);
  17. $word_list{$k} = $b;
  18. }
  19.  
  20. close $fh;
  21.  
  22. sub said {
  23.  
  24. shift;
  25. my $msg = shift; #msg is a hashref
  26. if ($msg->{body} =~ /^!add\s(.*)~(.*)/) {
  27. $word_list{$1} = $2;
  28. return "I just added key $1 and value $2 to the runtime hash...RUBYBOT FTW FUCK U KTHX";
  29. }
  30. if ($msg->{body} =~ /^!rm\s(.*)/) {
  31. if (defined $word_list{$1}) {
  32. delete $word_list{$1};
  33. return "I just deleted $1 from the runtime hash...RUBYBOT FTW FUCK U KTHX";
  34. }else{
  35. return "$1 is not defined in the hash...duh!";
  36. }
  37. }
  38. ($msg->{body} =~ /^!owner$/) && (return "My owner is tarski. And he spanks me...frequently. SAVE ME FROM HIS CRUEL FIST!");
  39. if ($msg->{body} =~ /^!hlist$/) {
  40. my $s = '';
  41. for (sort {uc $a cmp uc $b} (keys %word_list)) { #$a and $b are not lexically scoped
  42. $s .= "[$_~$word_list{$_}]";
  43. }
  44. #$s =~ s/;$//;
  45. return $s;
  46. }
  47. my $funnay = '';
  48. (rand(10) >= 9) && ($funnay = "...shut your face up. I'm a rubybot! RAWR!");
  49.  
  50. for (keys %word_list) {
  51. $msg->{body} =~ /$_/ ? return "$word_list{$_}$funnay" : next;
  52. }
  53. }
  54.  
  55. sub help {
  56. return "If you HaDn't NotiCed, I'm jusT a FUCKED up bot. and I do nothing usEFuLl. kbye.";
  57. }
  58.  
  59. Pbot->new(
  60. server => "irc.freenode.net",
  61. port => "6667",
  62. channels => ["#perlmovement"],
  63. nick => "rubybot",
  64. alt_nicks => ["rubybott", "rubybabybot"],
  65. username => "bot",
  66. name => "Just another Perl bot",
  67. charset => "utf-8",
  68. )->run;
  69.  
  70. __DATA__
Add Comment
Please, Sign In to add comment