An IRC bot project

This IRC bot project was initiated in early 2007 just because I felt like writing an IRC bot. It turned out to be an interesting excercise in object oriented design and programming so I decided to use it in my teaching as an example, and as a programming excercise for my students. This bot is implemented in Java. Currently it mostly speaks Swedish, but English translation is in the making and a lot of the functions supports both languages.

The code is extremely modular in its design and almost all of the bot's functionallity has been broken out of the main machinery into separate modules. It is easy to add new modules and anyone can create an own module with little effort. Modules can be dynamically added or removed on-line.

Index:

Documentation - Command line options

Command line options available when starting the bot.

OptionDescription
debug Turns on debug features. The most obvious one is that the bot connects to the console (stdin and stdout) instead of the real IRC network. Messages typed at the command line will be sent to the bot as IRC messages.
log Enables logging. All traffic in the channel(s) will be piped to stdout.
color Print log messages in color. Uses standard ANSI terminal codes to change color.
help Display this help message and exit.

Documentation - modules

Depending on what modules the bot operator has chosen to load, some or all of the modules below are available to users on the IRC network. Use the command !modules to see what modules are loaded in the particular bot you are talking to. The best way to get the latest version of this documentation is to talk to the bot online and issue the !help command with the desired module or command name as topic. Note that the descriptions below are generated from the source code. If some descriptions appear in Swedish it is because that particular module is not yet translated into English.

To invoke a command just type it as written below in the channel or in a private message to the bot. Arguments within [ ] are optional, arguments within < > are required. If unique, the beginning of a command is enough. For instance, there is only one command starting with !j (!join). Therefor it is enough to type !j to invoke the command !join. However, there are several commands starting with !s, so to invoke !seen the three first letters (!see) are required to find a unique beginning. If there is more than one command with a particular name, the module name can be added in front of the command name: !People.seen Please note that the command prefix (!) is placed in front of the module name.

AI
Author: Jesper Wilhelmsson

The AI module controls how the bot should react on text sent to the channel.

  • !good [remove] [word] --- (PUBLIC) Show words that are better than others. If a word is given, it will be added to the list of good words. If the parameter 'remove' is given in front of the word, it is removed.
  • !bad [remove] [word] --- (PUBLIC) Show words that are considered bad. If a word is given it will be added to the list of bad words. If the parameter 'remove' is given in front of the word, it is removed.

Calculator
Author: Jesper Wilhelmsson

Evaluates mathematical expressions. Answers can be stored for later use in variables or can be accessed through $0, $1, $2, and so on. The following symbols and built in functions are supported: + - / * ^ % ( ) = ~ & | < > && || << >> PI E sin cos tan asin acos atan sinh cosh tanh log ln lg abs rnd sqrt cbrt

  • !calc <expression> --- (PUBLIC) Evaluates mathematical expressions.

Channels
Author: Jesper Wilhelmsson

This module handles anything related to the channels used by this bot.

  • !verbose [channel] [on | off] --- (PUBLIC) Allows the bot to interfear with the discussion in the channel. Only the channelin which the command is entered is affected.
  • !settings [channel] --- (PUBLIC) Show channel-specific settings.
  • !msgstat [n] --- (PUBLIC) Display how many messages has been sent during the last 'n' days.
  • !topics [n] --- (PUBLIC) Displays the 'n' last topics for the channel, or all if no 'n' is given.
  • !greetings [channel] [on | off] --- (CHOP) Determines if the bot should greet people who join the channel.
  • !randomthought [channel] [on | off] --- (CHOP) Determines if the bot should send messages to the channel if it has been silent for too long.
  • !op [remove] [nick1 [nick2 [...]]] --- (CHOP) Grant op privileges to 'nick'. Several nicks can be specified. Specify 'remove' to remove privileges.
  • !halfop [remove] [nick1 [nick2 [...]]] --- (CHOP) Grant halfop privileges to 'nick'. Several nicks can be specified. Specify 'remove' to remove privileges.
  • !voice [remove] [nick1 [nick2 [...]]] --- (CHOP) Grant voice privileges to 'nick'. Several nicks can be specified. Specify 'remove' to remove privileges.
  • !channels --- (BOTOP) List all channels known to this bot.
  • !chremove <channel> --- (BOTOP) Remove the specified channel from this bot's list of channels.
  • !join <channel> [password] --- (BOTOP) Let the bot enter the given channel.
  • !leave <channel> --- (BOTOP) Ask the bot to leave the given channel.
  • !quit --- (BOTOP) Kill this bot.

Echo
Author: Jesper Wilhelmsson

Echoes messages

  • !echo --- (PUBLIC) Given a message, the same message is echoed.

Events
Author: Jesper Wilhelmsson

Denna modul tillhandahåller ett gränssnitt för att administrera händelser som schemaläggs i boten. Alla moduler kan själva lägga till och ta bort händelser så allt är egentligen helt automatiskt. Detta gränssnitt ger dock en möjlighet att övervaka händelser och ta bort dem om någon modul löper amok.

  • !events --- (BOTOP) Ger en lista över alla schemalagda händelser.

Help
Author: Jesper Wilhelmsson

This module handles a dictionary.

  • !help [add | remove] [word [= description]] --- (PUBLIC) Provides help about the given topic. To add a new topic use the equal sign '=' between topic and description. Topics may contain spaces. To remove a topic type 'remove' in front of it.

Lang
Author: Jesper Wilhelmsson

This module handles the bot's language settings. The settings are personal. The language on a reply from the bot depends on the setting for the person who writes something.

  • !lang [sv | en | ro] --- (PUBLIC) Choose language. Only the given abrevations are valid. If no language is provided the current setting is displayed.
  • !lang [sv | en | ro] --- (PUBLIC) Choose language. Only the given abrevations are valid. If no language is provided the current setting is displayed.

MasterMind
Author: Jesper Wilhelmsson

Spelet går ut på att lista ut den rätta nyckeln. Detta gör man genom att prova olika nycklar och kombinera ihop svaren man får. Nyckeln består av ett antal siffror (0 - 9). För varje siffra i din nyckel får du tillbaka ett svar; '-' betyder att siffran inte finns med i den rätta nyckeln, '+' betyder att siffran finns med men ska vara på en annan position, '*' betyder att siffran är rätt. Notera att under vissa förutsättningar kan man få svaret '-' även för siffror som finns med i nyckeln. Detta sker då man har fler av samma siffra i sin nyckel och det finns färre i den rätta nyckeln. Exempel: Lösning [4711] - Prova nyckel [1118] - Svar [+-*-].

  • !mm [level | key] --- (PUBLIC) Om spelet är aktivt provar man nycklar genom att ange dem på kommandoraden, ex: '!mm 1234'. Om spelet inte är aktivt startar man det med '!mm'. Man kan även ange en svårighetsgrad mellan 1 och 10. Svårighetsgraden avgör längden på nyckeln.

Modules
Author: Jesper Wilhelmsson

Modulhanterare. Denna modul ansvarar för all kommunikation mellan IRC-motorn och modulerna. Den distribuerar kommandon, IRC-meddelanden och händelser i kanalen till samtliga moduler (inklusive sig själv). Den är också ansvarig för dynamisk laddning och borttagning av moduler. Moduler laddade just nu: [Modules]

  • !modules --- (PUBLIC) Visa en lista över alla laddade moduler.
  • !commands --- (PUBLIC) Visa en lista över alla tillgängliga kommandon.
  • !more --- (PUBLIC) Om ett kommando resulterar i ett svar som överstiger 900 tecken kommer det att klippas av. !more används då för att visa nästa del av svaret.
  • !load [module] --- (BOTOP) Ladda in en ny modul. Om ingen modul anges listas samtliga tillgängliga moduler.
  • !unload [module] --- (BOTOP) Ta bort angiven modul. Om ingen modul anges listas alla laddade moduler.
  • !reload [module] --- (BOTOP) Ladda om angiven modul. Om ingen modul anges listas alla laddade moduler. Tänk på att en en modul inte nödvändigtvis har samma namn som dess klassfil. Om dessa inte är identiska kan !reload inte användas. Använd då !unload/!load.
  • !save [module] --- (BOTOP) Spara inställningar och data för angiven modul. Om ingen modul anges sparas alla moduler.

Numbers
Author: Jesper Wilhelmsson

Guess the number. I'm thinking of a number between zero and an upper limit. Your task is to guess what number I'm thinking of. Everyone in the channel are welcome to guess and there are points to gain for the one who finds the answer first.

  • !gissa [gräns | gissning] --- (PUBLIC) Om spelet är aktivt gissar man genom att skriva '!gissa <gissning>', om spelet inte är aktivt skriver man '!gissa [övre gräns]' för att starta.
  • !numbers [limit | guess] --- (PUBLIC) If the game is active you guess by typing '!guess <your guess>', otherwise you start a new game by typing '!numbers [upper limit]'.

Pending
Author: Jesper Wilhelmsson

A way to send messages to people not active in the channel right now.

  • !mess [nick message] --- (PUBLIC) Send a message to 'nick'. If no argument is given, your pending messages will be displayed.
  • !opmess [nick message] --- (CHOP) Send a message to 'nick' using the bot as sender.
  • !pending [clear] [nick] --- (BOTOP) Display pending messages. If 'nick' is provided, only messages to 'nick' are displayed. The keyword 'clear' is used to remove all pending messages (or all messages addressed to the given 'nick').

People
Author: Jesper Wilhelmsson

Denna modul håller ordning på vilka som är aktiva i kanalen.

  • !seen [channel] [nick [nick...]] --- (PUBLIC) Visar när användaren 'nick' senast var aktiv i kanalen. Om inget nick anges visas alla personer som varit aktiva i kanalen.
  • !info [nick] --- (PUBLIC) Visa information om 'nick', eller om dig själv om inget 'nick' anges.
  • !score --- (PUBLIC) Visar din poäng.
  • !highscore --- (PUBLIC) Visar vilka i kanalen som har flest poäng. Poäng kan erhållas genom att prata om rätt saker i kanalen (och undvika fel saker), genom att vinna tävlingar eller på annat sätt visa att man är en bättre människa än genomsnittet.
  • !rename <new nick> --- (PUBLIC) Ändrar ditt nick i databasen.
  • !description <text> --- (PUBLIC) Ange en personlig beskrivning av dig själv.
  • !greeting <text> --- (PUBLIC) Ange en personlig hälsningsfras som kommer att användas när du går in i kanalen.
  • !alias [nick] [alias] --- (PUBLIC) Om ett 'nick' och ett 'alias' anges kommer dessa namn att betraktas som samma person i fortsättningen. Om endast ett 'nick' anges listas eventuella alias för detta. Om ingen parameter anges listas eventuella alias för den som anropar.
  • !reward <nick> [score] --- (TRUSTEE) Ge nick poäng. Om score anges ökas användarens poäng med så mycket, annars med ett slumpmässigt värde mellan 20 och 50.
  • !punish <nick> [score] --- (TRUSTEE) Bestraffa nick genom att ta poäng. Om score anges minskas användarens poäng med så mycket, annars med ett slumpmässigt värde mellan 20 och 50.
  • !botop [remove] [nick] --- (BOTOP) Ge 'nick' operatörsstatus för boten. Om inget nick anges listas alla operatörer.
  • !trustee [remove] [nick] --- (BOTOP) Ge 'nick' trustee-status för boten. Om inget nick anges listas alla trustees.
  • !ignore [remove <nick>] [nick1] [nick2...] --- (BOTOP) Låtsas som att 'nick' inte finns. Flera nick kan anges för att ignorera flera personer. Om 'remove' anges slutar boten att ignorera personen/personerna. Om inget 'nick' anges listas alla som ignoreras.
  • !remove <nick> --- (BOTOP) Plocka bort 'nick' ur databasen. Nytt nick för personen blir det första alias som finns sparat. Om inget alias finns för 'nick' raderas all sparad data om 'nick'.

Quote
Author: Jesper Wilhelmsson, Tim Eriksson

Gives a quote.

  • !quote [random | n] [index] --- (PUBLIC) If the parameter 'random' is provided a random quote from the database is selected, otherwise quotes are picked in order. A number (n) can be provided to show the quote with that index. If the parameter 'index' is provided the quote's index is displayed.

Sten-Sax-Påse
Author: Peter Jönsson

Spelet Sten-Sax-Påse

  • !sten --- (PUBLIC) Ett av alternativen i spelet Sten-Sax-Påse.
  • !sax --- (PUBLIC) Ett av alternativen i spelet Sten-Sax-Påse.
  • !påse --- (PUBLIC) Ett av alternativen i spelet Sten-Sax-Påse.

Time
Author: Jesper Wilhelmsson

Gives the time.

  • !time --- (PUBLIC) Gives the time.

Trivial Pursuit
Author: Adam Viklund, Jesper Wilhelmsson

!trivia [topic | answer] --- startar ett nytt spel och ger dig en fråga. Om 'topic' anges kommer endast frågor ur den kategorin. Tillgängliga kategorier är: [Lircbot.modules.Trivia$Topic;@2f754ad2 Du svarar på frågan genom att skriva !trivia <ditt svar>. Tänk på att försöka svara så kortfattat som möjligt och utan att lägga på några onödiga tecken. Den som svarar rätt på frågan får poäng.

  • !trivia [topic | answer] --- (PUBLIC) startar ett nytt spel och ger dig en fråga. Om 'topic' anges kommer endast frågor ur den kategorin. Tillgängliga kategorier är: [Lircbot.modules.Trivia$Topic;@3d833955 Du svarar på frågan genom att skriva !trivia <ditt svar>. Tänk på att försöka svara så kortfattat som möjligt och utan att lägga på några onödiga tecken. Den som svarar rätt på frågan får poäng.

Wikipedia
Author: Jesper Wilhelmsson

Denna modul slår upp sökord i Wikipedia.

  • !wiki <ord> --- (PUBLIC) Slår upp 'ord' i wikipedia och skriver ut en del av beskrivningen.

News
Author: Jesper Wilhelmsson

Denna modul lyssnar på AmigaRulez nyhets-RSS och ger dig de senaste rubrikerna.

  • !news --- (PUBLIC) Ger dig de senaste nyheterna från AmigaRulez.

Current ToDo list

  • More functionality...

Known bugs

  • 2. All modules need to be loaded using their own classLoaders for !reload to work. Reload needs to dump the classLoader (and gc*2?) for the old class to vanish before loading a new instance.
  • 4. !help !bad/!good should not mention [word] to nops.
  • 5. !wiki yadayada -> this page doesn't exist. this page doesn't exist. this page doesn't exist. -> There is some way in wikipedia to set the page size of the cellphone. For some reason the default is really small.
  • Let me know if you find any more...