-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathikachan_client
executable file
·116 lines (97 loc) · 2.14 KB
/
ikachan_client
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env perl
use strict;
use warnings;
use 5.008001;
use File::Spec;
use File::Basename;
use lib File::Spec->catdir(dirname(__FILE__), '..', 'lib');
use App::Ikachan;
use Getopt::Long ();
use LWP::UserAgent;
my $parser = Getopt::Long::Parser->new(
config => [ "no_ignore_case", "pass_through" ],
);
my $ikachan_server = 'http://127.0.0.1:4979/';
$parser->getoptions(
's|server=s' => \$ikachan_server,
);
sub usage {
print "ikachan_client
$0 [-s ikachan_server] join #channel
$0 [-s ikachan_server] leave #channel
$0 [-s ikachan_server] notice #channel message
$0 [-s ikachan_server] privmsg #channel message
";
}
my $command = shift @ARGV;
my $channel = shift @ARGV;
unless ($channel) {
usage();
exit;
}
my @params;
if ($command eq 'join') {
@params = (
"${ikachan_server}join",
+{
channel => $channel,
},
);
} elsif ($command eq 'leave') {
@params = (
"${ikachan_server}leave",
+{
channel => $channel,
},
);
} elsif ($command eq 'notice') {
my $message = shift @ARGV;
unless ($message) {
usage();
exit;
}
@params = (
"${ikachan_server}notice",
+{
channel => $channel,
message => $message,
},
);
} elsif ($command eq 'privmsg') {
my $message = shift @ARGV;
unless ($message) {
usage();
exit;
}
@params = (
"${ikachan_server}privmsg",
+{
channel => $channel,
message => $message,
},
);
} else {
usage();
exit;
}
my $ua = LWP::UserAgent->new(
agent => "IkachanClient/$App::Ikachan::VERSION",
);
my $res = $ua->post(@params);
print $res->content . "\n";
__END__
=head1 NAME
ikachan - IRC message delivery by HTTP
=head1 SYNOPSIS
# join channel
ikachan -s http://127.0.0.1:4979/ join \#channel
# leave channel
ikachan -s http://127.0.0.1:4979/ leave \#channel
# sent message
ikachan -s http://127.0.0.1:4979/ notice \#channel message
ikachan -s http://127.0.0.1:4979/ privmsg \#channel message
=head1 OPTIONS
=over 4
=item -s, --server
ikachan server url.
=cut