Skip to content

Instantly share code, notes, and snippets.

@Wollw
Created August 12, 2012 07:07
Show Gist options
  • Save Wollw/3330337 to your computer and use it in GitHub Desktop.
Save Wollw/3330337 to your computer and use it in GitHub Desktop.
IRC bot in written in bash
#!/usr/bin/env bash
# Open a connection to canternet
exec 3<>/dev/tcp/irc.canternet.org/6667;
# Login and join the channel.
printf "NICK BashBot\r\n" >&3;
printf "USER bashbot 8 * :IRC Bot in Bash\r\n" >&3;
sleep 2;
printf "JOIN #HackingIsMagic\r\n" >&3;
# Main loop
while [ true ]; do
read msg_in <&3;
# UGLY ping response. Sends a PONG whenever PING shows up.
if [[ $msg_in =~ "PING" ]] ; then
printf "PONG %s\n" "${msg_in:5}";
printf "PONG %s\r\n" "${msg_in:5}" >&3;
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment