Created
January 24, 2016 12:11
-
-
Save Caaz/97d42c51f1e98da72f0c to your computer and use it in GitHub Desktop.
A simple as hell perl bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
use IO::Socket; | |
my %config = (prefix => '\!', server => 'localhost', channel => '#TheFusion', nick => 'Poli'); | |
sub sendServer { my $socket = shift; print $socket "$_\n" for(@_); } | |
sub connectServer { | |
my ($host,$port) = split /\:/, $config{server}; | |
my $socket = new IO::Socket::INET(PeerAddr=>$host, PeerPort=>($port)?$port:6667); | |
die "Can't connect: $host $port" if($@); | |
return $socket; | |
} | |
my $socket = connectServer(); | |
sendServer($socket, "USER $config{nick} 0 * :made by Caaz", "NICK $config{nick}", "JOIN $config{channel}"); | |
while(($_ = readline($socket)) =~ s/\r|\n//g) { | |
if(/^PING (.*)$/) { sendServer($socket,"PONG $1"); } | |
elsif(/^\:(?<nick>.+?)!(?<user>.+?)@(?<host>.+?) PRIVMSG (?<channel>.+?) \:$config{prefix}(?<command>.+)$/) { | |
my %data = %+; $_ = $data{command}; | |
if(/^test$/i) { sendServer($socket,"PRIVMSG $data{channel} :JAPH."); } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment