1#8-ball / decision ball 2# 3#What is this? 4# 5#The 8-ball (Eight-ball) is a decision ball which i bought 6#in a gadget shop when i was in London. I then came up with 7#the idea to make an irc-version of this one :) 8#There are 16 possible answers that the ball may give you. 9# 10# 11#usage 12# 13#Anyone in the same channel as the one who runs this script may 14#write "8-ball: question ?" without quotes and where question is 15#a question to ask the 8-ball. 16#An answer is given randomly. The possible answers are the exact 17#same answers that the real 8-ball gives. 18# 19#Write "8-ball" without quotes to have the the ball tell you 20#how money questions it've got totally. 21# 22#Write "8-ball version" without quotes to have him tell what 23#his version is. 24# 25# 26use strict; 27use warnings; 28use vars qw($VERSION %IRSSI); 29 30use Irssi qw(command_bind signal_add); 31use IO::File; 32$VERSION = '0.22'; 33%IRSSI = ( 34 authors => 'Patrik Akerfeldt', 35 contact => 'patrik.akerfeldt@gmail.com', 36 name => '8-ball', 37 description => 'Dont like to take decisions? Have the 8-ball do it for you instead.', 38 license => 'GPL', 39); 40 41sub own_question { 42 my ($server, $msg, $target) = @_; 43 question($server, $msg, "", $target); 44} 45 46sub public_question { 47 my ($server, $msg, $nick, $address, $target) = @_; 48 question($server, $msg, $nick.": ", $target); 49} 50sub question { 51 my ($server, $msg, $nick, $target) = @_; 52 $_ = $msg; 53 if (!/^8-ball/i) { return 0; } 54 55 if (/^8-ball:.+\?$/i) { 56 # From: "The 8-Ball Answers", http://8ball.ofb.net/answers.html 57 my @answers = ( 58 'Signs point to yes.', 59 'Yes.', 60 'Reply hazy, try again.', 61 'Without a doubt.', 62 'My sources say no.', 63 'As I see it, yes.', 64 'You may rely on it.', 65 'Concentrate and ask again.', 66 'Outlook not so good.', 67 'It is decidedly so.', 68 'Better not tell you now.', 69 'Very doubtful.', 70 'Yes - definitely.', 71 'It is certain.', 72 'Cannot predict now.', 73 'Most likely.', 74 'Ask again later.', 75 'My reply is no.', 76 'Outlook good.', 77 'Don\'t count on it.' 78 ); 79 80 $server->command('msg '.$target.' '.$nick.'8-ball says: '.$answers[rand @answers]); 81 82 my ($fh, $count); 83 $fh = new IO::File; 84 $count = 0; 85 if ($fh->open("< .8-ball")){ 86 $count = <$fh>; 87 $fh->close; 88 } 89 $count++; 90 $fh = new IO::File; 91 if ($fh->open("> .8-ball")){ 92 print $fh $count; 93 $fh->close; 94 }else{ 95 print "Couldn't open file for output. The value $count couldn't be written."; 96 return 1; 97 } 98 return 0; 99 } elsif (/^8-ball$/i) { 100 101 my ($fh, $count); 102 $fh = new IO::File; 103 $count = 0; 104 if ($fh->open("< .8-ball")){ 105 $count = <$fh>; 106 $server->command('msg '.$target.' 8-ball says: I\'ve got '.$count.' questions so far.'); 107 $fh->close; 108 }else{ 109 print "Couldn't open file for input"; 110 return 1; 111 } 112 return 0; 113 114 } elsif (/^8-ball version$/i){ 115 $server->command('msg '.$target.' My version is: '.$VERSION); 116 return 0; 117 } else { 118 if(!/^8-ball says/i){ 119 $server->command('msg '.$target.' '.$nick.'A question please.'); 120 return 0; 121 } 122 } 123 124} 125 126signal_add("message public", "public_question"); 127signal_add("message own_public", "own_question"); 128