forked from crawl/sequell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequell.pl
executable file
·128 lines (102 loc) · 3.45 KB
/
sequell.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
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
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/perl
use strict;
use warnings;
use Fcntl qw/:flock SEEK_END/;
use lib 'lib';
use Henzell::Config qw/%CONFIG %CMD %USER_CMD %PUBLIC_CMD/;
use Henzell::Crawl;
use Henzell::Utils;
use Henzell::IRC;
use Henzell::IRCAuth;
use Henzell::SeenService;
use Henzell::TellService;
use Henzell::CommandService;
use Henzell::ReactorService;
use Henzell::LogFetchService;
use Henzell::Bus;
use Getopt::Long;
use Cwd;
END {
kill TERM => -$$;
}
open STDOUT, '|-', q{( while read line; do echo "[$(date +'%Y-%m-%d %H:%M:%S')] $line"; done )} or die "Couldn't reopen STDOUT: $!\n";
open STDERR, '>&', \*STDOUT or die "Couldn't reopen STDERR: $!\n";
my $irc = 1;
my $config_file = Henzell::Config::default_config();
GetOptions("irc!" => \$irc,
"rc=s" => \$config_file) or die "Invalid options\n";
$ENV{LC_ALL} = 'en_US.UTF-8';
$ENV{HENZELL_ROOT} = getcwd();
$ENV{RUBYOPT} = "-I" . File::Spec->catfile(getcwd(), 'src');
local $SIG{PIPE} = 'IGNORE';
local $SIG{CHLD} = 'IGNORE';
local $| = 1;
load_config($config_file);
# The other bots on the channel that might announce milestones and logfiles.
# When Henzell sees such an announcement, it will fetch logfiles explicitly
# within $sibling_fetch_delay seconds.
my @sibling_bots = Henzell::Config::array('sibling_bots');
my $nickname = $CONFIG{bot_nick};
my $ircname = "$nickname the Crawl Bot";
my $ircserver = $CONFIG{irc_server};
my $port = $CONFIG{irc_port} || 6667;
my @CHANNELS = Henzell::Config::array('channels');
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';
Henzell::Utils::lock(verbose => 1,
lock_name => $ENV{HENZELL_LOCK} || $CONFIG{lock_name});
if ($CONFIG{startup_services}) {
Henzell::Utils::spawn_services($CONFIG{startup_services});
}
my $HENZELL;
my %AUTHENTICATED_USERS;
my %PENDING_AUTH;
unless ($irc) {
print STDERR "Waiting, hit Enter to exit\n";
<STDIN>;
exit 0;
}
print "Connecting to $ircserver as $nickname, channels: @CHANNELS\n";
$HENZELL = Henzell::IRC->new(nick => $nickname,
server => $ircserver,
port => $port,
name => $ircname,
channels => [ @CHANNELS ],
flood => 1,
charset => "utf-8")
or die "Unable to create Henzell IRC bot\n";
$HENZELL->configure_services(
services => irc_services($HENZELL));
$HENZELL->run();
exit 0;
sub irc_services {
my $irc_bot = shift;
my @services;
my $reg = sub { push @services, shift() };
my $feat = sub { Henzell::Config::feat_enabled(shift()) };
my $bus = Henzell::Bus->new;
$reg->(Henzell::SeenService->new(irc => $irc_bot)) if $feat->('seen_update');
if ($CONFIG{sql_store}) {
$reg->(
Henzell::LogFetchService->new(
irc => $irc_bot,
siblings => [Henzell::Config::array('sibling_bots')]));
}
$reg->(Henzell::TellService->new(irc => $irc_bot));
my $auth = Henzell::IRCAuth->new(irc => $irc_bot);
my $executor = Henzell::CommandService->new(
irc => $irc_bot,
auth => $auth,
config => $config_file,
bus => $bus);
$reg->(Henzell::ReactorService->new(irc => $irc_bot,
auth => $auth,
executor => $executor,
bus => $bus));
\@services
}
sub load_config {
my $config_file = shift;
my $loaded = Henzell::Config::read($config_file);
$loaded
}