From jlynch@wilkes1.wilkes.edu Wed Jul 8 02:29:58 1992 Received: by wilkes1.wilkes.edu (5.57/Ultrix3.0-C) id AA15604; Tue, 7 Jul 92 14:31:52 -0400 Date: Tue, 7 Jul 92 14:31:52 -0400 From: jlynch@wilkes1.wilkes.edu (Baloo the Bear) Message-Id: <9207071831.AA15604@wilkes1.wilkes.edu> To: ktso@ws332c.ee.cuhk.hk Subject: BotDoc1.2 Status: R ************************************************************************ That Great Ursine of IRC, BalooBear, presents... '||''|. . '||''|. || || ... .||. || || ... .... ||'''|. .| '|. || || || .| '|. .| '' Version || || || || || || || || || || 1.2 .||...|' '|..|' '|.' .||...|' '|..|' '|...' The official guide to writing IRC bots !!!!! *********************************************************************** Standard Disclaimer Legal Junk ------------------------------ BalooBear cannot he held responsible for anything that happens as a result of using this document... Use at your own risk!!!! Requirements ------------ o UNIX or compatible OS o IRCII client o A little knowledge of how /on commands work o Imagination What is a bot? -------------- A 'bot' is simply a collection of commands (a script) that responds to certain key phrases and commands from its owner and other IRC participants. Popular features that people include in their bots are auto-opping of themselves and friends, deop protection for them (when someone deops them, the bot reops them), responding to certain words people say with cute responses, and the like. This manual will show you how to do all these things, and I hope it will spur you on to make bots that do even more. This manual only covers the basics, but bots can do MUCH more. Mechanics of a bot ------------------ A bot appears as a seperate person on IRC, even though it is really just a script. Your bot will have the same system address as you, and will run as a background task in your account. Bots can leave IRC when you do automatically and change channels with you. They can even be made to stay on IRC after you logout, 24-hrs/day, if so desired. A bot is just a collection of mostly /on commands (with some others thrown in sometimes) that is stored in a simple ASCII text file. This file can be loaded into IRCII in several ways. Since I assume most of you want your bot to run in the background and cause a minimum amount of hassle to you, I will show you the method I use to run my bot. This method has many advantages. But first, lets get into some actual bot code! Common commands in a bot file ----------------------------- The first thing you'll want to have in your bot file is a nickname for your bot. Usually, bot nicknames end in "bot" or "serv" or "srv". You should make your bot's nick end in one of these three ways so as to not make people think it's a person. BalooBot, my bot, is a good example. When people see that kind of ending, they know he's just a program. To specify a nickname, put this in your bot file: /nick whatever Remember, just use any text editor to make your bot file, as it is only an ASCII text file. Next you should set exec_protection to off, so that your bot can operate properly, turn the display off, and turn the beep off by doing this: /set exec_protection off /set display off /set beep off Simple, eh? Now we get to the good part - actually writing the key phrases and responses!!! Many things can be done with a bot, and here are a few: /ON PUBLIC - RESPONDING TO KEY PHRASES -------------------------------------- By using /on public commands, your bot can be made to respond to "key phrases" that anyone on the channel says. Wildcards, such as *, can be used, and case does not matter. The first form of the command responds to a key phrase only when the bot is specifically spoken to: /on public "* baloobot* hello*" / ==== Hi there, $0! ==== /on public "* hello* baloobot*" / ==== Hi there, $0! ==== This line will respond with "==== Hi there, Fred! ====" if someone named Fred says "baloobot hello" or "hello baloobot". This type of public will ONLY respond when someone specifically addresses the bot by name. Another kind of /on public is this kind: /on public "* spam*" / ==== SPAM, SPAM, SPAM, SPAMMITY SPAM! ==== ...which will output the phrase whenever the word "spam" is heard from anyone at any time. BE WARNED, however, that most people do not take kindly to this kind of /on public statement, and will usually kick your bot if he keeps it up. By making the bot only respond when addressed, you can make sure that it doesn't get people annoyed. See the listing of BalooBot after this document for more ideas. /ON MSG - RESPONDING TO MESSAGES -------------------------------- /on msg commands allow your bot to respond to /msg messages that people send to it. The format is similar to /on public : /on msg "* help*" /exec -msg $0 cat HelpFile.txt ...will, when someone types "/msg BalooBot help", msg back to that person the contents of the file HelpFile.txt in the current dir. Bascially, anything that can be done with /on publics can also be done with /on msgs, the two commands simply respond to different kinds of input. BalooBot's listing at the end of this document includes several /on msg commands, mostly for owner control. AUTO-OPS and AUTO-REOPS ------------------------ Auto-ops can be incorporated into your bot, which will make him op you or any of your friends automatically and instantly upon /join of the channel the bot is on (assuming he is opped). Auto-reops automatically reop you or friends when someone tries to deop you/them. Here is an example from BalooBot: /on join BalooBear /mode $C +o BalooBear; ==== BALOOBEAR!! ==== /on mode "* * *-O BalooBear" /mode $C +o BalooBear The first line auto-ops BalooBear upon joining the channel the bot is on (notice how $C represents the channel name). The second line reops BalooBear immediately if somebody deops him. See the listing of BalooBot for more examples. Also note how a semicolon (;) is used to separate multiple commands on the same line. SECURE (LOGIN-ID) BASED AUTO-OP ------------------------------- The previous auto-op commands will auto-op anyone with the right nickname. On small channels this is usually no problem, but on large, well-known channels (such as #hottub, which is BalooBot's home), this can become a problem, as delinquents can take someone else's nick, get auto-opped by the bot (who think's its that person of that nick), and mass-kick everyone off the channel :(.... A way to avoid this is by using secure auto-opping that is based on login-id rather than just nickname. Here's how: put this line once in your botfile, near the top: /on join * /who $0 ...then for each person you want to auto-op, put in one of these: /on who "* * * jlynch wilkes1.wilkes.edu *" /mode $C +o $1 Make sure to leave out the @ in the system address. Incidentially, the above one is just an example, but it would be nice to add to your bot (after all, I wrote this helpfile :) KICK PROTECTION (AUTO-REJOIN-ON-KICK) ------------------------------------- Add something like this to make your bot kick-proof: /on raw_irc "*KICK * * BalooBot*" /msg BalooBot rejoin /on msg "BalooBot rejoin" /join #channel BTW, you can't just do a /on raw_irc kick /join, because all operations after the raw_irc are carried out JUST BEFORE you are kicked... so having the bot msg itself to rejoin is a neccessary, if kludgy, extra step. But hey... it works! :) Of course, someone can always ban your bot, then kick him. To get around this, simply put your bot on a non-2.7 server, with the /serv command. Non-2.7 servers ignore bans, and essentially make your bot ban-proof. Along with the next section on kill- proofness, these things will make it so that NO ONE on IRC, and I do mean NO ONE, will be able to get your bot off a channel in any way (KICK doesn't work, ban doesn't either, not even KILL!). Except possibly by making the channel invite-only, but on most big public-channels like #hottub, invite-only is almost never used. KILL-PROOFNESS -------------- One simple line will make your bot kill-proof (instant reconnect upon kill): /on disconnect * /serv servername ...where you substitute your server name (for example, fairhope.andrew.cmu.edu, a good non-2.7 server) for the word "servername". OWNER COMMANDS -------------- These commands use /on public statements, but can only be activated by the owner of the bot, not by anyone else. The key is to include the owner's name as part of the statement: /on public "BalooBear bbot boot*" /kick $C $3 ...will kick the person after the word "boot" off the channel. Note that all BalooBear has to type is "bbot boot nick" to kick that person, the "BalooBear" part of the /on public is only used to make sure that the command is from BalooBear; someone else trying to use the "bbot boot" command will get no response. BalooBot also includes /on msg owner commands, for when the owner is not on the same channel as the bot. JOIN-ON-INVITE -------------- This command will make the bot join any channel its owner /invites it to (make sure to put your nick in place of "BalooBear") /on invite "BalooBear" /join $1 SWITCH SERVERS -------------- This is a special owner command that causes the bot to switch to whatever server you tell it to: /on public "BalooBear BBot serv*" /serv $3 /on msg "BalooBear serv *" /serv $2 so when BalooBear types "bbot serv lyman.pppl.gov" or "/msg BalooBot serv lyman.pppl.gov", BalooBot will switch to the lyman server. EXIT-WITH-OWNER --------------- This command will cause your bot to exit the IRC system when you do, automatically. Note that if you want a bot to be on all the time, do not use this command, you must kill the bot process from the shell to stop it. /on channel_signoff "* BalooBear" /exit STARTING YOUR BOT ----------------- OK, so you've written your bot, and now you want to try him out. Here's how, assuming you have a C-shell-based UNIX system (commands may vary for other shells): 1. From the shell prompt, simply type: irc -b -l botfile ...where you replace the full pathname of the IRCII client on your machine for the word 'irc', and the name of the ASCII text file containing your bot for the word 'botfile'. This will run your bot in the background, put up some stuff on the screen you should ignore, and then, after you hit return a few times, return your shell prompt to you. The bot is now running as a background process that will continue indefinitely until you kill it, even after you logout. 2. Now just join IRC yourself, take the nickname that your bot recognizes as its master's... and have fun! 3. If you ever want to kill the bot for any reason (to start up an improved version, for example), just do a "ps -x" from the shell prompt, note the PID number of the bot process, and from the shell type "kill -9 pidnumber", replacing the PID number for the word "pidnumber". CONCLUDING NOTE --------------- Keep in mind that MUCH more can be done with bots, so much more that we have literally only covered the proverbial "tip of the iceberg" here. So go ahead, and get your hands dirty... If you have any questions, I'm on IRC under "BalooBear", you can talk to me or leave a msgserv for me, or E-mail me at jlynch@wilkes1.wilkes.edu _ /\\_\_.-----.___ _.._ / _ _ \// \ BalooBear / / \ y-- | John Lynch | /\ /\ \ __/ jlynch@wilkes1.wilkes.edu ___________| _*/__*/_ \_ / \\ +----. ____ \_ ------------------------- \ || \__/ / / \ +---+/ / / /\\ High Byte Software \ \ / / _/ 91 Hillside Street '-+----_______---- / -- \ Wilkes-Barre, PA, USA \___________--' \ 18702 / \ / \ ================= LISTING OF BALOOBOT AS OF 4/9/92 ==================== /comment *** BalooBot V3.7, BalooBear's IRC bot *** /comment *** now running off Fizzy's account *** /comment *** jointly commanded/owned by Fizzy/BalooBear *** /comment *** Now with system-id checks (for auto-opping) *** /comment *** Also with kick protection (auto-rejoin on kick) *** /comment *** And kill-protection (instant auto-reconnect on kill) *** /comment *** running off a 2.6 server for ban protection *** /serv fairhope.andrew.cmu.edu /nick BalooBot /set novice off /set display off /set exec_protection off /set beep off /join #hottub /say ==== Hi everyone! ==== /on join * /who $0 /comment ******************** PUBLICS **************************** /on mode "* * *+O BalooBot*" /msg $0 ==== Thanks tons, $0!! ==== /on public "* hello* BalooBot" / ==== Hi there, $0!! ==== /on public "* BalooBot* hi*" / ==== Hello, $0!!! ==== /on public "* BalooBot* hello" / ==== Greetings, $0!! ==== /on public "* hi* BalooBot*" / ==== What's up, $0 ?!! ==== /on public "* baloobot* thank*" / ==== No problemo, $0 ==== /on public "* thank* baloobot*" / ==== Anytime, $0 ==== /on public "* thanx* baloobot*" / ==== Don't mention it, $0!!! ==== /on public "* baloobot* thanx*" / ==== Glad to help, $0!!! ==== /on public "* baloobot* spam*" / ==== SPAM, SPAM, SPAM, SPAM, SPAMMITY SPAM!! ==== /on public "* baloobot* amiga*" / ==== Commodore Amiga - Best PC on Earth!! ==== /on public "* baloobot* commodore*" / ==== Commodore : maker of the legendary AMIGA! ==== /on public "* baloobot* parrot*" / ==== "That parrot is NOT dead.. he's resting!" ==== /on public "* baloobot* grail*" / ==== "Grail? We've already got one!" ==== /on public "* baloobot* sir robin*" / ==== "He is brave Sir Robin, brave Sir Robin" ==== /on public "* baloobot* larch*" / ==== "AND NOW... THE LARCH" ==== /on public "* baloobot* camelot*" / ==== "It's only a model!" ==== /on public "* baloobot* floyd*" / ==== PINK FLOYD RULES! ==== /on public "* baloobot* how* is* life*" / ==== Life sucks, as usual, $0 ==== /on public "* baloobot* eat* me*" / ==== $0: I'd rather not :P ==== /on public "* baloobot* who* made* you*" / ==== BalooBear did, of course! ==== /on public "* baloobot* who* created* you*" / ==== BalooBear made me! ==== /on public "* baloobot* who* is* your* master*" / ==== My master is BalooBear! I obey him faithfully! ==== /on public "* baloobot* self*destruct*" / ==== BLAM!!!!!!! ==== /on public "* baloobot* who* is* BalooBear*" / ==== BalooBear is the bear from the Disney ====; ==== film, "The Jungle Book". And he is my master! ==== /on public "* baloobot* me* beer*" / ==== Throws a cold brewski to $0 ==== /on public "* baloobot* where* you* live*" / ==== I live on IRC, silly! :) ==== /on public "* baloobot* die*" / ==== DIE??? I AM IMMORTAL!!!! :) ==== /on public "* baloobot* sex*" / ==== *blushes* Sorry, bots can't have sex, $0 ==== /on public "* baloobot* suck*" / ==== $0, vulgarity is a crutch for the inarticulate ==== /on public "* baloobot* go* hell*" / ==== No, I think YOU should go to hell, $0!!! :) ==== /on public "* baloobot* fuck*" / ==== Watch the language, $0!!! :) ==== /on public "* baloobot* shit*" / ==== Watch the language, $0, or I'll ====; ==== get the FCC after you! :) ==== /on public "* baloobot* shut*up*" / ==== I'll shut up if you don't egg me on!! ==== /comment ******************** HELP! ********************************* /on public "* baloobot* help*" /msg $0 ==== HELP?? Call 911 !! ==== /on public "* bbot* help*" /msg $0 ==== HELP?? Call 911 !! ==== /on msg "* help*" /msg $0 ==== HELP?? Call 911 !! ==== /comment ******************* KICK / KILL PROTECTION ******************** /on raw_irc "*KICK * * BalooBot*" /msg BalooBot rejoin /on msg "BalooBot rejoin" /join #hottub /on disconnect * /serv fairhope.andrew.cmu.edu /comment ******************** AUTO RE-OPS ************************* /comment *** inactive until I can figure out how to secure them *** /comment *** from jerks who take other ppl's nicks to get opped *** /comment /on mode "* * *-O BalooBear*" / ==== NEVER DEOP MY MASTER, $0!!! ====;/mode $C +o BalooBear /comment /on mode "* * *-O Fizzy*" / ==== LEAVE MY CO-OWNER ALONE, $0!!! ====;/mode $C +o Fizzy /comment /on mode "* * *-O RontuWolf*" / ==== NEVER DEOP MY MASTER, $0!!! ====;/mode $C +o BalooBear /comment /on mode "* * *-O Dankari*" /mode $C +o Dankari /comment /on mode "* * *-O Zorg*" / ==== HEY!! LEAVE ZORG ALONE!! *reops Zorg* ====;/mode $C +o Zorg /comment /on mode "* * *-O Christina*" / ==== LEAVE HER ALONE!!! *reops Christina* ====;/mode $C +o Christina /comment /on mode "* * *-O kodiak*" / ==== LEAVE MY BEAR BUDDY ALONE!!! ====;/mode $C +o kodiak /comment /on mode "* * *-O DreadLord*" / ==== DON'T MESS WITH DREADLORD!! *reops him* ====;/mode $C +o DreadLord /comment /on mode "* * *-O ce_nedra*" / ==== HEY!! LEAVE CE_NEDRA ALONE!! *reops* ====;/mode $C +o ce_nedra /comment /on mode "* * *-O snick*" / ==== HEY!! LEAVE SNICK ALONE!! *reops* ====;/mode $C +o snick /comment /on mode "* * *-O rags*" / ==== LEAVE RAGS ALONE!!! *reops him* ====;/mode $C +o rags /comment /on mode "* * *-O stale*" / ==== LEAVE STALE ALONE!! *reops* ====;/mode $C +o Stale /comment /on mode "* * *-O HotTubSrv*" / ==== LEAVE HOTTUBSRV ALONE!! ====;/mode $C +o HotTubSrv /comment /on mode "* * *-O Nap*" / ==== LEAVE NAP ALONE!! ====;/mode $C +o Nap /comment ******** COMMANDS FOR BALOOBEAR / FIZZY ***************** /on msg "BalooBear op*" /mode $C +o $2 /on msg "BalooBear deop*" /mode $C -o $2 /on msg "BalooBear boot*" /kick $C $2 /on msg "BalooBear later" /say ==== BYE ALL!!! ====;/exit LATER_ALL! /on msg "BalooBear serv*" /serv $2 /on msg "BalooBear join*" /join $2 /on msg "BalooBear leave*" /leave $2 /on msg "BalooBear nick*" /nick $2 /on msg "BalooBear ban*" /kick $C $2;/mode $C +b $2!*@* /on msg "Fizzy op*" /mode $C +o $2 /on msg "Fizzy deop*" /mode $C -o $2 /on msg "Fizzy boot*" /kick $C $2 /on msg "Fizzy later" /say ==== BYE ALL!!! ====;/exit LATER_ALL! /on msg "Fizzy serv*" /serv $2 /on msg "Fizzy join*" /join $2 /on msg "Fizzy leave*" /leave $2 /on msg "Fizzy nick*" /nick $2 /on msg "Fizzy ban*" /kick $C $2;/mode $C +b $2!*@* /comment ********************** THE END ************************ /comment ****** BalooBot V3.7, a BalooBear production :) ******* '''---```---^^^^^^-----#-----~~~~~----'''------~~~~-----````~~~---------=\ /= .sig (n): a piece of mail with a fool at one : Ravi Narayan, CS, WPI (0) end and flames at the other. (C). : DoD #540 - SuzukiGS500E H o _ _ _ _ : _ _ H _/\_> =| |========| |=========| |=========| |=========| |=========| |======= 0,> /0,=|w|,,=====,|,|.,===,,==| |,,===.,==|.|..======w| |..,,.====| |====,,=