Build your own IRC bot in Java

Long long time ago. We are all used to chat via a protocol named Internet-Relay-Chat, short IRC (Wikipedia).

I was very into it, with Bouncern, Eggdrop bots, etc. Nevertheless, after a couple of years, modern chat systems like Skype, Jabber or big blue Facebook destroyed my demand to use IRC. As i switched from Linux to Mac OSX, I lost all my connection to this protocol. Till today. Thanks to Klaus. We’ll code our own, Java-based simple IRC bot.

That’s not only a simple bot, that’s also a simple task. With a bit Open-Source und Maven magic, we’ll have a starter bot in under 120 seconds. Thats my promise.

Four steps

All in all, we have to do four simple Steps.

  1. Create a new Maven project
  2. Add the following dependency
  3. Extend the PircBot
  4. Connect to a IRC server of your choice — Done.

In Detail

In this scenario, I’ll use the IntelliJ IDE Community Edition as my IDE of choice. Of course, you can use other editors as you like.

  1. Create a new Maven project – File -> New Project -> Choose Maven -> fill out form -> finish wizard.
  2. Open the pom.xml file and add the given dependency to it. Execute a mvm install to fetch the libraries. PircBot pom.xml
  3. Create a new class and extend the PircBot object. Create a starter class with a main-method and create a instance of your robot.
  4. Call the methods bot.setName(„MyName“), bot.connect(„irc.server.net“) and bot.joinChannel(„#myChannel“).

Isn’t it simple enough to be the foundation of an awesome weekend or holiday project. You can attach a REST-service or a website. Build your own Chat based on the old and stable IRC network. Endless possibilities dudes!

Video To be fair and give a proof that it takes just two minutes to build your own bot, I created a small, uncommented, video.

Further I added some further functionalities to my bot. My bot – it’s name is „Tobot“ is able to say the current time („!time„) and be a random item generator („!random item1 item2„). I pushed it to a Github repository.

You may share your bots. Leave a comment or fork me on github to stay in touch.

Have a nice christmas holiday.

  • Tobias

Schreibe einen Kommentar

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s