This repository has been archived by the owner on May 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
poco-input.pl
executable file
·267 lines (229 loc) · 9.7 KB
/
poco-input.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/usr/bin/env perl
## only 3 cpan modules installed: POE::Components::IRC,
## POE::Components::Omegle, and REST::Google::Translate
## there are a few "settings" that can be changed
## like nick, the nick to change to during omegle chat
## and server and channel...
##
## license: i am not responsible for anything. ever. or whatever.
##
##
## TO RUN:
## execute this script with 4 arguments in this order:
## $ perl omegle-bot.pl <botname> <strangername> <ircserver> <ircchannel>
##
##
use strict;
use warnings;
use Switch;
use POE qw(Component::IRC Component::Omegle Wheel::ReadLine);
####### #######
####### #######
my $ORIGINALNICK = shift || 'nullbot';
my $OMEGLENICK = shift || 'stranger';
my $NICK = $ORIGINALNICK;
my $USERNAME = 'banana';
my $IRCNAME = 'ask me for help';
my $SERVER = shift || 'irc.foonetic.net';
my $CHANNEL = shift || '#boats';
my $perl_location = `which perl`; chomp $perl_location;
my $script_location = "$0";
####### #######
my $IRC_ALIAS = 'butt';
my $OMEGLE_SESSION = 0;
my $omegle;
my $rl;
my $LAZY = 0;
my @NAMES = ();
my @FOCUS = ();
sleep 1; #time to respawn
my $irc = POE::Component::IRC->spawn(
nick => $NICK,
ircname => $IRCNAME,
username => $USERNAME,
server => $SERVER,
alias => $IRC_ALIAS, ) or die "uhhhhhh $!";
POE::Session->create( inline_states => {
_start => sub {
$_[KERNEL]->post( $IRC_ALIAS => register => 'all' );
$_[KERNEL]->post( $IRC_ALIAS => connect => {} );
$_[HEAP]->{readline} = POE::Wheel::ReadLine->new(InputEvent => 'got_input');
$rl = $_[HEAP]->{readline};
},
irc_001 => sub {
$_[KERNEL]->post( $IRC_ALIAS => join => $CHANNEL );
$rl->put("Joined channel $CHANNEL on $SERVER");
$rl->addhistory("respawn");
$rl->get("$NICK> ");
},
got_input => sub {
my ($input,$exception) = @_[ARG0,ARG1];
if( $input eq 'respawn' ){
exec $perl_location, $script_location, $ORIGINALNICK, $OMEGLENICK, $SERVER, $CHANNEL;
exit 0;
}
if( defined $input ){
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $CHANNEL => $input );
$rl->addhistory($input);
}
if( $exception eq 'interrupt'){
delete $_[HEAP]->{readline};
undef $rl;
$_[KERNEL]->yield(unregister => 'all');
$_[KERNEL]->yield('shutdown');
exit 0;
}
$rl->get("$NICK> ");
},
irc_public => sub {
my ($kernel, $heap, $who, $where, $msg) = @_[KERNEL, HEAP, ARG0, ARG1, ARG2];
my $nick = (split /!/, $who)[0];
my $channel = $where->[0];
my $ts = scalar localtime;
$rl->put( "$ts <$nick> $msg");
if (my ($what) = $msg =~ /^$NICK[:,] (.+)/) {
$omegle->say($what) if $OMEGLE_SESSION;
push @FOCUS, $nick if $OMEGLE_SESSION; # they have focus, so whatever they say, goes to stranger
$rl->put("(( @FOCUS )) { @NAMES }");
if( !$OMEGLE_SESSION and $what =~ /^help/i ){
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $CHANNEL => "commands are ;start, ;stop, ;respawn. after ;start-ing and inviting an omegle stranger, the conversation can be ;stop-ped. if i become unresponsive, try ;respawn-ing me.");
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $CHANNEL => "during a conversation, the omegle stranger can only hear you if you speak to $OMEGLENICK");
}
} elsif (my ($cmd) = $msg =~ /^;(\w+)/){
if( $cmd eq "start" and ! $OMEGLE_SESSION){
$LAZY = 0;
$LAZY = 1 if $msg =~ /lazy/;
$_[KERNEL]->yield( "my_omegle" );
}elsif ( $cmd eq "start" and $OMEGLE_SESSION ){
#$omegle->{async}->poke;
$omegle->flush_events;
$omegle->disconnect();
$_[KERNEL]->post($IRC_ALIAS => ctcp => $CHANNEL => "ACTION disconnects" );
$OMEGLE_SESSION = 0;
@FOCUS = ();
undef $omegle;
sleep 2;
$LAZY = 0;
$LAZY = 1 if $msg =~ /lazy/;
$_[KERNEL]->yield( "my_omegle" );
}elsif ( $cmd eq "stop" and $OMEGLE_SESSION ){
#$omegle->{async}->poke;
$omegle->flush_events;
$omegle->disconnect();
$_[KERNEL]->post($IRC_ALIAS => ctcp => $CHANNEL => "ACTION disconnects" );
# change nick :D so its OBVIOUS we're in omegle mode
$_[KERNEL]->post( $IRC_ALIAS => nick => $ORIGINALNICK );
$NICK = $ORIGINALNICK;
$OMEGLE_SESSION = 0;
@FOCUS = ();
undef $omegle;
}elsif ( $cmd eq "respawn" ){
exec $perl_location, $script_location, $ORIGINALNICK, $OMEGLENICK, $SERVER, $CHANNEL;
exit 0;
}elsif ( $cmd eq "die" ){
exit 0;
}elsif ( $cmd eq "help" ){
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $CHANNEL => "commands are ;start, ;stop, ;respawn. after ;start-ing and inviting an omegle stranger, the conversation can be ;stop-ped. if i become unresponsive, try ;respawn-ing me.");
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $CHANNEL => "during a conversation, the omegle stranger can only hear you if you speak to $OMEGLENICK");
}
} elsif ( $LAZY and grep { $nick eq $_ } @FOCUS ) {
$rl->put("i'm listening to $nick");
if( my ($who, $what) = $msg =~ /^([^:, ]+)[:,] (.+)/ and grep { $1 eq $_ } @NAMES){
$rl->put("who is this \"$who\" he think he's talking to");
$rl->put("aww, he doesn't love us");
foreach (0 .. $#FOCUS){
delete $FOCUS[$_] if $FOCUS[$_] eq $nick;
$rl->put("lets delete him, he's not talking to me");
}
} else {
$rl->put("he has something good to say");
$rl->put("(( @FOCUS )) { @NAMES }");
$omegle->say($msg);
}
}
},
irc_433 => sub {
$_[KERNEL]->post( $IRC_ALIAS => nick => $NICK . $$%1000 );
},
# 353 part quit kick join
irc_353 => sub {
@NAMES = split / /, (split /:/, $_[ARG1])[1];
s/^[@%+]// foreach @NAMES;
$rl->put("(( @FOCUS )) { @NAMES }");
},
irc_join => sub {
push @NAMES, (split /!/, $_[ARG0])[0];
$rl->put("(( @FOCUS )) { @NAMES }");
},
( map { ; "irc_$_" => sub {
my $nick = (split /!/, $_[ARG0])[0];
foreach (0 .. $#NAMES){
delete $NAMES[$_] if $NAMES[$_] eq $nick;
}
$rl->put("(( @FOCUS )) { @NAMES }");
}} qw(part quit) ),
irc_kick => sub {
my $was_kicked = $_[ARG2];
my $kicked_by = $_[ARG3];
exit 0 if $was_kicked eq $NICK;
foreach (0 .. $#NAMES){
delete $NAMES[$_] if $NAMES[$_] eq $was_kicked;
}
$rl->put("(( @FOCUS )) { @NAMES }");
},
( map { ; "$_" => sub {} } qw(_child irc_ping) ),
_default => sub {
$rl->put(sprintf "%s: session %s caught an unhandled %s event.", scalar localtime(), $_[SESSION]->ID, $_[ARG0]);
$rl->put("$_[ARG0]: ".join(" ", map({"ARRAY" eq ref $_ ? "[@$_]" : "$_"} @{$_[ARG1]})));
0; # false for signals
},
my_omegle => sub {
my $session = $_[SESSION];
POE::Session->create(
inline_states => {
_start => sub {
my ($heap) = $_[HEAP];
my $om = POE::Component::Omegle->new;
$om->set_callback(connect => 'om_connect');
$om->set_callback(chat => 'om_chat');
$om->set_callback(disconnect => 'om_disconnect');
$heap->{om} = $om;
$om->start_chat;
$poe_kernel->delay_add( poke => 0.1, $om );
},
poke => sub {
my ($kernel, $heap, $om) = @_[KERNEL, HEAP, ARG0];
$om->poke;
$poe_kernel->delay_add( poke => 0.1, $om );
},
om_connect => sub {
my $om = $_[HEAP]->{om};
$rl->put( "Omegle: Stranger connected");
# change nick :D so its OBVIOUS we're in omegle mode
$_[KERNEL]->post( $IRC_ALIAS => nick => $OMEGLENICK );
$_[KERNEL]->post($IRC_ALIAS => ctcp => $CHANNEL => "ACTION has connected" );
$NICK = $OMEGLENICK;
$OMEGLE_SESSION = 1;
$omegle = $om;
},
om_chat => sub {
my ($cb_args) = $_[ARG1];
my ($om, $chat) = @$cb_args;
$rl->put( "Omegle: STRANGER >> $chat" );
$_[KERNEL]->post($IRC_ALIAS => privmsg => $CHANNEL => "$chat" );
},
om_disconnect => sub {
$rl->put( "Omegle: Stranger disconnected" );
$_[KERNEL]->post($IRC_ALIAS => ctcp => $CHANNEL => "ACTION disconnects" );
# change nick :D so its OBVIOUS we're in omegle mode
$_[KERNEL]->post( $IRC_ALIAS => nick => $ORIGINALNICK );
$NICK = $ORIGINALNICK;
@FOCUS = ();
$OMEGLE_SESSION = 0;
undef $omegle;
},
},
);
},
},);
POE::Kernel->run;