forked from crawl/sequell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruncmd.pl
executable file
·69 lines (58 loc) · 1.61 KB
/
runcmd.pl
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
#! /usr/bin/perl
use strict;
use warnings;
use lib 'lib';
use Henzell::Cmd qw/load_all_commands execute_cmd/;
use Henzell::IRCStub;
use Henzell::CommandService;
use Henzell::SeenService;
use Henzell::TellService;
use Henzell::ReactorService;
use Henzell::Bus;
use utf8;
do 'sqllog.pl';
do 'game_parser.pl';
my $DEFAULT_NICK = $ENV{NICK} || 'greensnark';
my $CHANNEL = $ENV{CHANNEL} || '##crawl';
my $CONFIG = $ENV{RC} || 'rc/sequell.rc';
$ENV{IRC_NICK_AUTHENTICATED} = 'y';
$ENV{HENZELL_SQL_QUERIES} = 'y';
$ENV{RUBYOPT} = '-rubygems -Isrc';
$ENV{PERL_UNICODE} = 'AS';
$ENV{HENZELL_ROOT} = '.';
$ENV{HENZELL_ALL_COMMANDS} = 'y';
my $irc = Henzell::IRCStub->new(channel => $CHANNEL);
my $bus = Henzell::Bus->new;
my $cmd_service =
Henzell::CommandService->new(irc => $irc,
config => $CONFIG,
bus => $bus);
my @services = (
Henzell::SeenService->new(irc => $irc),
Henzell::TellService->new(irc => $irc),
Henzell::ReactorService->new(irc => $irc,
executor => $cmd_service,
bus => $bus)
);
$irc->configure_services(services => \@services);
sub runcmd($) {
chomp(my $cmd = shift);
my $nick = $DEFAULT_NICK;
my $pm;
return unless $cmd =~ /\S/;
if ($cmd =~ /^(\w*): (.*)/) {
$nick = $1 || $DEFAULT_NICK;
$pm = 'msg' unless $1;
$cmd = $2;
}
$irc->tick();
$irc->said({ who => $nick, channel => $pm || $CHANNEL, body => $cmd });
}
if (@ARGV > 0) {
runcmd(join(' ', @ARGV));
exit 0;
}
print "Henzell command runner\n";
while ( my $cmd = do { print "> "; <STDIN> } ) {
runcmd($cmd);
}