How to write a really simple IRC bot

Noah Slater of semtard vapourware fame recently demonstrated to me how to write and extremely simple IRC bot in shell scripting.
The bot below is extremely simple, it simply identifies itself, joins a channel then sends a message to a channel.

If you are interested in using IRC bots, you may enjoy Phenny, which has a Debian package.

To use the code below to create your own bot, first you should copy the bot into a file called bot.sh
then run:

chmod a+x bot.sh

then run the bot with

./bot.sh

If you wanted to run the bot in the background for an extended period of time, you might want to do something like:

nohup /bot.sh 2> ~/mybotlog.txt &

For more information about learning shell scripting have a look on google



Based on Shellbot, by Sean B. Palmer

#!/bin/sh -e
# Based on Shellbot by Sean B. Palmer, inamidst.com
# Modified 2008, Noah Slater < nslater@bytesexual.org >
# Modified 2008, Tim Dobson, tdobson.net

echo "NICK pingbot" > pingbot.input # what nick
echo "USER pingbot +iw pingbot :$0" >> pingbot.input
echo "JOIN #tdobson.net" >> pingbot.input # what channel

tail -f pingbot.input | telnet irc.freenode.net 6667 | while true; do # what network

echo "PRIVMSG #tdobson.net :tdobson is cool" >> pingbot.input # what to say.
sleep 30 # number of seconds to wait before saying it again

done



My shell says telnet command not found

Anonymous Fool (not verified) | Fri, 26/09/2008 - 20:39

Use netcat?
Replace telnet with nc.

JStoker (not verified) | Fri, 28/08/2009 - 21:50

I'd rename this to how to make a spam bot :)

Stephen Mount (not verified) | Thu, 05/06/2008 - 22:25

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options