Dbot
Published:
Revised:
in
bcd6a62
So I made a small irc bot in 294 characters in code-golfing language #1: Perl.
Usage
perl Dbot
Commands
.name
- Echo the bots name.hello
- Output “hello world!”.src
- Dump the source code
Code
use IO::Socket;$s=IO::Socket::INET->new("158.38.8.251:6667");sub o{print$s "$_[0]\n"}o("NICK $0");o("USER b * * :b");while(<$s>){o("PONG$1")if/^PING(.*)$/;o("JOIN #$0")if/004/;if(($p,$h)=/(P.+)\.(.*)./){o("$p$h world!")if$h=~"h";o($p.$0)if$h=~"n";if($h=~"s"){open F,$0;o($p.do{local$/=<F>})}}}
Well uh let’s try that again, without minimize shall we?
use IO::Socket;
$s = IO::Socket::INET->new("158.38.8.251:6667");
print$s "$_[0]\n" }
{
o("NICK $0");
o("USER b * * :b");
while(<$s>) {
# Play a bit of ping-pong
"PONG$1") if /^PING(.*)$/;
o(
# Join when ping-pong has completed
"JOIN #$0") if /004/;
o(
# Parse a message our channel with message ".<cmd>"
# so example:
# :<user-info> PRIVMSG #<channel> :.<cmd>
# (P.+) Match 'PRIVMSG #<channel> :'
# \. Cmd prefix
# (.*) Cmd
# . Trailing \r
if(($p,$h) = /(P.+)\.(.*)./) {
# .hello Echo hello world! Unless an abuser appears!
"$p$h world!") if $h =~ "h";
o(# .name Echo name of bot
$p.$0) if $h =~ "n";
o(
# .src Output whole source code
if($h =~ "s") {
# Open running script file handler
open F,$0;
# Echo contents of running script
# file slurping
$p . do{ local$/ = <F> })
o( }
}
}
All hacky, but I had some fun with it.