-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrps.pl
More file actions
executable file
·98 lines (87 loc) · 2.41 KB
/
Copy pathrps.pl
File metadata and controls
executable file
·98 lines (87 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use strict;
use Irssi qw/signal_add/;
use Irssi::Irc;
use warnings;
use vars qw($VERSION %IRSSI);
$VERSION = "1";
%IRSSI = (
authors => 'Jaykob Ross',
contact => 'mosai57@gmail.com',
name => 'Rock Paper Scissors',
description => 'Plays rock paper scissors via irc',
);
my @options_rps = ( "rock", "paper", "scissors" );
my @options_rpsls = ( "rock", "paper", "scissors", "lizard", "spock" );
my %final_hash = (
'rock' => {
'rock' => 'We tied',
'paper' => 'You lose',
'scissors' => 'You win',
'lizard' => 'You win',
'spock' => 'You lose'
},
'paper' => {
'rock' => 'You win',
'paper' => 'We tied',
'scissors' => 'You lose',
'lizard' => 'You lose',
'spock' => 'You win'
},
'scissors' => {
'rock' => 'You lose',
'paper' => 'You win',
'scissors' => 'We tied',
'lizard' => 'You win',
'spock' => 'You lose'
},
'lizard' => {
'rock' => 'You lose',
'paper' => 'You win',
'scissors' => 'You lose',
'lizard' => 'We tied',
'spock' => 'You win'
},
'spock' => {
'rock' => 'You win',
'paper' => 'You lose',
'scissors' => 'You win',
'lizard' => 'You lose',
'spock' => 'We tied'
}
);
sub rps{
my ($server, $message, $nick, $address, $target) = @_;
my @arguments = split(' ', $message);
my $selection = $options_rps[int(rand(scalar(@options_rps)))];
my $final = "I choose $selection... ";
my $input = $arguments[1];
if($message =~ /^!rps\s/i){
if($input =~ /^((rock)|(paper)|(scissors))$/i){
$final .= $final_hash{$input}{$selection};
$server->command("MSG $target " . $final);
} else{
$server->command("DESCRIBE $target gives $nick a funny look");
}
}
undef $selection;
undef @arguments;
}
sub rpsls{
my ($server, $message, $nick, $address, $target) = @_;
my @arguments = split(' ', $message);
my $selection = $options_rpsls[int(rand(scalar(@options_rpsls)))];
my $final = "I choose $selection... ";
my $input = $arguments[1];
if($message =~ /^!rpsls\s/i){
if($input =~ /^((rock)|(paper)|(scissors)|(lizard)|(spock))$/i){
$final .= $final_hash{$input}{$selection};
$server->command("MSG $target " . $final);
} else{
$server->command("DESCRIBE $target gives $nick a funny look");
}
}
undef $selection;
undef @arguments;
}
Irssi::signal_add('message public', 'rps');
Irssi::signal_add('message public', 'rpsls');