Skip to content

Instantly share code, notes, and snippets.

@Caaz
Created January 2, 2016 19:56
Show Gist options
  • Save Caaz/1e41905360a7a6a683f2 to your computer and use it in GitHub Desktop.
Save Caaz/1e41905360a7a6a683f2 to your computer and use it in GitHub Desktop.
An obfuscated poll bot
#!/usr/bin/perl
use warnings;
use strict;
use IO::Socket;
my %c = (
prefix => '\!',
server => 'localhost',
channel => '#TheFusion',
admin => 'Megurine',
nick => 'Poli',
);
my %p;
sub sS { my $s = shift; print $s "$_\n" for(@_); 1; }
sub cS {
my ($h,$p) = split /\:/, $c{server};
my $s = new IO::Socket::INET(PeerAddr=>$h,PeerPort=>($p)?$p:6667);
die "Can't connect: $h $p" if($@);
return $s;
}
sub pS {
my ($o,$i);
$o .= "[\cB".$i++."\cB: $_] " for(@{$_[1]{o}});
sS($_[0],"PRIVMSG $c{channel} :${$_[1]}{t}: $o");
}
sub wS {
my ($o,$i) = ('',0);
$o .= "[$_ \cB".(${$_[1]}{v}[$i++]+0)."\cB] " for(@{$_[1]{o}});
sS($_[0],"PRIVMSG $c{channel} :Poll ended!","PRIVMSG $c{channel} :${$_[1]}{t}: $o");
}
my $s = cS(); sS($s,"USER $c{nick} 0 * :made by Caaz", "NICK $c{nick}", "JOIN $c{channel}");
while($_ = readline($s)) {
$_ =~ s/\r|\n//g;
if(/^PING (.*)$/) { sS($s,"PONG $1"); }
elsif(/^\:(.+?)!(.+?)@(.+?) PRIVMSG (.+?) \:$c{prefix}(.+)$/) {
my @v = ($1,$2,$3,$4,$5);
if($v[0] =~ /^$c{admin}$/i) {
if($v[4] =~ /^poll (.+?)\? (.+)$/i) { my @o = split /,\s*/, $2; %p = (t=>$1,o=>\@o,v=>[],h=>[]); pS($s,\%p); }
elsif(($v[4] =~ /^endPoll$/i) && (%p)) { wS($s,\%p); undef %p; }
}
if(($v[4] =~ /^vote (.+)$/i) && (%p)) {
my @o = split /,\s*/, $1;
next if(($v[2] ~~ @{$p{h}}) && (sS($s,"PRIVMSG $v[3] :$v[0], you've already voted.")));
for(@o) { $p{v}[$_]++ if(($_ =~ /^\d+$/) || ($_ < @{$p{o}})); }
push(@{$p{h}},$v[2]);
sS($s,"PRIVMSG $v[3] :$v[0] placed their vote.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment