/var/www/www.irssi.org-old/scripts/html/8-ball.pl
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 #
26 use strict;
27 use vars qw($VERSION %IRSSI);
28
29 use Irssi qw(command_bind signal_add);
30 use IO::File;
31 $VERSION = '0.20';
32 %IRSSI = (
33 authors => 'Patrik Jansson',
34 contact => 'gein@knivby.nu',
35 name => '8-ball',
36 description => 'Dont like to take decisions? Have the 8-ball do it for you instead.',
37 license => 'GPL',
38 );
39
40 sub own_question {
41 my ($server, $msg, $target) = @_;
42 question($server, $msg, "", $target);
43 }
44
45 sub public_question {
46 my ($server, $msg, $nick, $address, $target) = @_;
47 question($server, $msg, $nick.": ", $target);
48 }
49 sub question($server, $msg, $nick, $target) {
50 my ($server, $msg, $nick, $target) = @_;
51 $_ = $msg;
52 if (!/^8-ball/i) { return 0; }
53
54 if (/^8-ball:.+\?$/i) {
55 my $ia = int(rand(16));
56 my $answer = "";
57 SWITCH: {
58 if ($ia==0) { $answer = "Yes"; last SWITCH; }
59 if ($ia==1) { $answer = "No"; last SWITCH; }
60 if ($ia==2) { $answer = "Outlook so so"; last SWITCH; }
61 if ($ia==3) { $answer = "Absolutely"; last SWITCH; }
62 if ($ia==4) { $answer = "My sources say no"; last SWITCH; }
63 if ($ia==5) { $answer = "Yes definitely"; last SWITCH; }
64 if ($ia==6) { $answer = "Very doubtful"; last SWITCH; }
65 if ($ia==7) { $answer = "Most likely"; last SWITCH; }
66 if ($ia==8) { $answer = "Forget about it"; last SWITCH; }
67 if ($ia==9) { $answer = "Are you kidding?"; last SWITCH; }
68 if ($ia==10) { $answer = "Go for it"; last SWITCH; }
69 if ($ia==11) { $answer = "Not now"; last SWITCH; }
70 if ($ia==12) { $answer = "Looking good"; last SWITCH; }
71 if ($ia==13) { $answer = "Who knows"; last SWITCH; }
72 if ($ia==14) { $answer = "A definite yes"; last SWITCH; }
73 if ($ia==15) { $answer = "You will have to wait"; last SWITCH; }
74 if ($ia==16) { $answer = "Yes, in due time"; last SWITCH; }
75 if ($ia==17) { $answer = "I have my doubts"; last SWITCH; }
76 }
77 $server->command('msg '.$target.' '.$nick.'8-ball says: '.$answer);
78
79 my ($fh, $count);
80 $fh = new IO::File;
81 $count = 0;
82 if ($fh->open("< .8-ball")){
83 $count = <$fh>;
84 $fh->close;
85 }
86 $count++;
87 $fh = new IO::File;
88 if ($fh->open("> .8-ball")){
89 print $fh $count;
90 $fh->close;
91 }else{
92 print "Couldn't open file for output. The value $count couldn't be written.";
93 return 1;
94 }
95 return 0;
96 } elsif (/^8-ball$/i) {
97
98 my ($fh, $count);
99 $fh = new IO::File;
100 $count = 0;
101 if ($fh->open("< .8-ball")){
102 $count = <$fh>;
103 $server->command('msg '.$target.' 8-ball says: I\'ve got '.$count.' questions so far.');
104 $fh->close;
105 }else{
106 print "Couldn't open file for input";
107 return 1;
108 }
109 return 0;
110
111 } elsif (/^8-ball version$/i){
112 $server->command('msg '.$target.' My version is: '.$VERSION);
113 return 0;
114 } else {
115 if(!/^8-ball says/i){
116 $server->command('msg '.$target.' '.$nick.'A question please.');
117 return 0;
118 }
119 }
120
121 }
122
123 signal_add("message public", "public_question");
124 signal_add("message own_public", "own_question");