1# infobot :: Kevin Lenzo (c) 1999
2
3use Socket;
4
5$| = 1;
6
7$SIG{'INT'}  = 'killed';
8$SIG{'KILL'} = 'killed';
9$SIG{'TERM'} = 'killed';
10
11$updateCount = 0;
12$questionCount = 0;
13$autorecon = 0;
14
15$label = "(?:[a-zA-Z\d](?:(?:[a-zA-Z\d\-]+)?[a-zA-Z\d])?)";
16$dmatch = "(?:(?:$label\.?)*$label)";
17$ipmatch = "\d+\.\d+\.\d+\.\d";
18$ischan = "[\#\&].*?";
19$isnick = "[a-zA-Z]{1}[a-zA-Z0-9\_\-]+";
20
21sub TimerAlarm {
22    &status("$TimerWho's timer ended. sending wakeup");
23    &say("$TimerWho: this is your wake up call, foobar.");
24}
25
26sub killed {
27    my $quitMsg = $param{'quitMsg'} || "regrouping";
28    &quit($quitMsg);
29    &closeDBMAll();
30	# MUHAHAHAHA.
31    exit(1);
32}
33
34sub joinChan {
35    foreach (@_) {
36	&status("joined $_");
37	rawout("JOIN $_");
38    }
39}
40
41sub invite {
42    my($who, $chan) = @_;
43    rawout("INVITE $who $chan");
44}
45
46sub notice {
47    my($who, $msg) = @_;
48    foreach (split(/\n/, $msg)) {
49	rawout("NOTICE $who :$_");
50    }
51}
52
53sub say {
54    my @what = @_;
55    my ($line, $each, $count);
56
57    foreach $line (@what) {
58	for $each (split /\n/, $line) {
59	    sleep 1 if $count++;
60	    if (getparam("msgonly")) {
61		&msg ($who, $each);
62	    } else {
63		&status("</$talkchannel> $each");
64		rawout("PRIVMSG $talkchannel :$each");
65	    }
66	}
67    }
68}
69
70sub msg {
71    my $nick = shift;
72    my @what = @_;
73
74    my ($line, $each, $count);
75
76    foreach $line (@what) {
77	for $each (split /\n/, $line) {
78	    sleep 1 if $count++;
79	    &status(">$nick< $each");
80	    rawout("PRIVMSG $nick :$each");
81	}
82    }
83
84}
85
86sub quit {
87    my $quitmsg = $_[0];
88    rawout("QUIT :$quitmsg");
89    &status("QUIT $param{nick} has quit IRC ($quitmsg)");
90    close(SOCK);
91}
92
93sub nick {
94    $nick = $_[0];
95    rawout("NICK ".$nick);
96}
97
98sub part {
99    foreach (@_) {
100	status("left $_");
101	rawout("PART $_");
102	delete $channels{$_};
103    }
104}
105
106sub mode {
107    my ($chan, @modes) = @_;
108    my $modes = join(" ", @modes);
109    rawout("MODE $chan $modes");
110}
111
112sub op {
113    my ($chan, $arg) = @_;
114    $arg =~ s/^\s+//;
115    $arg =~ s/\s+$//;
116    $arg =~ s/\s+/ /;
117    my @parts = split(/\s+/, $arg);
118    my $os = "o" x scalar(@parts);
119    mode($chan, "+$os $arg");
120}
121
122sub deop {
123    my ($chan, $arg) = @_;
124    $arg =~ s/^\s+//;
125    $arg =~ s/\s+$//;
126    $arg =~ s/\s+/ /;
127    my @parts = split(/\s+/, $arg);
128    my $os = "o" x scalar(@parts);
129    &mode($chan, "-$os $arg");
130}
131
132sub timer {
133    ($t, $timerStuff) = @_;
134    # alarm($t);
135}
136
137$SIG{"ALRM"} = \&doTimer;
138
139sub doTimer {
140    rawout($timerStuff);
141}
142
143sub channel {
144    if (scalar(@_) > 0) {
145	$talkchannel = $_[0];
146    }
147    $talkchannel;
148}
149
150sub rawout {
151    $buf = $_[0];
152    $buf =~ s/\n//gi;
153    select(SOCK); $| = 1;
154    print SOCK "$buf\n";
155    select(STDOUT);
156}
157
1581;
159