Hacker News new | comments | show | ask | jobs | submit login
How to write an IRC bot (sircmpwn.github.io)
215 points by janvdberg 4 months ago | hide | past | web | favorite | 96 comments



In summary to write an IRC bot, open a TCP socket to an IRC server in whatever language you want and start doing stuff. To write a slack bot, go jump through their hoops and proprietary tech, and maybe they'll let you do stuff.

Thank goodness the web and email are open protocols, let's hope in 10 years time we have added a standard chat protocol to that list, and no one is wasting time on proprietary chat platforms.


> let's hope in 10 years time we have added a standard chat protocol to that list

Well we do have one now: XMPP. I was pleasantly surprised at the current state of it, when I revisited it last year.

That being said, it's still not in a "just-works" state, and while I might enjoy fidgeting around with it to get things like push messaging to work, I can see why many people don't want to do that.


> That being said, it's still not in a "just-works" state, and while I might enjoy fidgeting around with it to get things like push messaging to work, I can see why many people don't want to do that.

At least you're fidgeting around with an open protocol and not something that's proprietary and won't work in a few months.


XMPP?


My mum knows what a website is, and she knows what an email address is.

She doesn't know what XMPP is.

When she knows what XMPP is (or a competing federated protocol), chat is solved.


Given that you're describing your Mum in the same fashion we typically all do (And to avoid the "Yes, she's actually very technical" bait-n-switch), we'll assume no.

You're mixing the ubiquity and common parlance/popularity to suit your situation, but it doesn't work that way. FTP, IRC, HTTP, and SMTP are all ubiquitious, but not necessarily the most popular method for describing things, keeping in mind that we haven't fully shut the book on the internet == www.

XMPP is the protocol that you're talking about here but you shifted gears midway through to say that she should know what instant messaging is. (which again, I'm gunna guess she does).

Similarly, Email fetching itself has gone through one major protocol shift under her nose without changing the very nature of it, so to make claims that in the particular instance of messaging she should know the protocol is arbitrarily moving the rule-bar.

(Bet you still have to try and explain the difference between http and https to her too, and that always ends with *sigh... just look for the little green lock. :P)


> Similarly, Email fetching itself has gone through one major protocol shift under her nose without changing the very nature of it, so to make claims that in the particular instance of messaging she should know the protocol is arbitrarily moving the rule-bar.

Probably your mom does use neither POP3 mir IMAP, but either a Webmailer or Google's proprietary HTTP-based Gmail protocol used by the Gmail app (or Yahoo mail or ...)

And whatever is being used: Users don't know what HTTP is or how it works, they have some understanding of entering addresses and clicking on links.

(For German speakers I suggest this video from children TV program "Die Sendung mit der Maus" from ca. 1996 which goes quite in depth https://youtu.be/8PNRrOGJqUI )


Does she know what HTTP or IMAP are?


Does she know what instant messaging is? What you listed are not the protocols themselves. The trick is just to make XMPP the standard way to do IM.


The argument always boils down to "non-technical" people only know how to use a web browser and they can only only use things available within the browser. They seemingly have absolutely no knowledge of any other type of application (like a word processor, chat client, email client, etc).

This argument directly contradicts my first hand experience communicating with people online. They were perfectly capable of using those various applications to communicate with others.


i bet your mom knows what a chat is and not what imap and smtp are.


Does your mum use Mac or Windows?? That could be part of the problem.


Sircmpwn is a user on this site. There are so many times I've opened a link to a piece of software, an article, or a tutorial and thought "Wow, this is cool" or "Hey, this is fun to read." And Sircmpwn has repeatedly been an author I've seen that sort of content from and felt like I got something nice out of it every time.

Sircompwn, if you're reading this, thanks for the neat content. I don't mind stumbling upon them during my lunch breaks :)


Yeah, a bit like ludde in the old days. I've used or enjoyed scumm VM, openttd and utorrent a lot.

I also remembered truecraft right now when I saw this post and went to check on it. The git repo is now archived and read only, but didn't find a mention anywhere if/why development was given up.


TrueCraft needs a lot of work that I don't have time for right now, it gets in the way of my other FOSS work. I'll work on it more if I make enough recurring donation revenue to work on FOSS full time.

Progress: https://drewdevault.com/donate


That makes sense, thanks for the clarification. That archived message on github just felt like it's a permanent decision. And since I started using sway recently I'm pretty OK with your priorities. ;)


Thanks :)



I'm always very impressed by people who can write awesome things in bash.


As much as I like IRC, I don't get why the author hates slack so much. I dislike slack (probably because of the culture in Slack groups) but I do think that having a mobile app & ease of use is why Slack is okay. Not having to deal with different servers & terminology that look scary also helps (a lot) for most people using Slack.

Most people who use Slack haven't ever used IRC professionally (or at all) - I've shown IRC to people who love Slack and I usually get "Ugh, it looks so old fashioned and difficult to use" as a reaction. Looks matters a lot if you want people to use it - most IRC clients are old or have designs based on old clients.

Plenty of Slack clones out there that look decent that have similar business models. What would be awesome if there's an IRC server that looked and acted like Slack; nice features like:

- a website to log into like Slack (with benefits like modern web design and Github, Twitter, Facebook login). - an irc client that looks decent on website, desktop and phone clients (and doesn't run on electron). - having multiple channels for one company like Slack channels in a group. IRC currently requires you to register several channels (which is annoying).

------------

As for the difficulty in writing bots for Slack vs IRC, sure it's easier to write stuff for Slack because:

- most Slack bots/services are written by companies who want their third party services to be easily integrated into whatever team communication their client use.

- most custom bots are variation of some bots that someone else has written (anecdotal evidence but pretty sure it's true). I'm pretty sure it's not that different for irc.

- most people don't bother writing bots unless they're willing to play around with bots; difficulty isn't an issue when it comes to writing one and I haven't seen bot development treated as an actual task (it's more of a hack that works and isn't really touched again.)

------------

Honestly, this seems to be a case where the author neglects how real-life people work in favor of code "niceness" (for lack of a better term). There's a reason why most people use Microsoft products (and it isn't because they make great software.)


> I don't get why the author hates slack so much.

He gives a nice reasoning in the last paragraph:

Slack is a walled garden. Their proprietary API is defined by them and only implemented by them. They can and will shut off parts you depend on (like the IRC+XMPP gateways that were just shut down).


> Their proprietary API is defined by them and only implemented by them.

Is this really true though? Doesn't Mattermost have a slack-ish-compatible interface?


Well, others can try to implement parts of it but it is a cat and mouse game of wasting human resources. Mattermost managed to get some compatibility https://docs.mattermost.com/developer/webhooks-incoming.html...


> I've shown IRC to people who love Slack and I usually get "Ugh, it looks so old fashioned and difficult to use" as a reaction.

This is the exact reason why I don't like Slack - It takes up WAY too much screen estate. At least with IRC I can format it in a way that I prefer, AND be able to use the rest of my screen for other tasks.


Slack and Discord (which seem to be the "hype" chats these days) are pigs both in terms of real estate and resource usage. I can easily see a backlog of nearly a hundred messages in a single terminal IRC frame but I'm lucky if I can see 10 messages in Slack or Discord. So much scrolling to catch up with chat history, not to mention how laggy it feels if you don't have a high end PC. I can't easily script the client, I can't easily self-host and script the server and I'm stuck with a proprietary architecture at the whims of the devs. Amazing. You'll have to pry irssi out of my cold dead hands.


Most people who use Slack haven't ever used IRC professionally (or at all) - I've shown IRC to people who love Slack and I usually get "Ugh, it looks so old fashioned and difficult to use" as a reaction. Probably the same people that never used a terminal and have the same reaction at first. And then you teach them a thing or two, let them evolve and weeks later when you less expect it, that same person is thriving on the terminal he hated initially. I have seen this happen a couple times... windows people saying linux is awkward. or even that i3-wm is awkward, until they get to learn it and they completely change their mind.

Slack has its merits, but plain IRC also works fine.

The same people that prefer slack because they never really tried IRC, might say they prefer slack because it allows them to write BOTs.

BOTs in irc is easy, there are 3 kind of bots:

- bots that interact: User types something in a channel or via private message. The bot will receive that message and the user that typed it. then it will parse the message and take an action. Examples of interaction messages:

-- msg to bot: google this: "time now ?" (then the bot connects to google and makes a query and replies to this message): UTC 10h20 -- msg to bot: reboot

- bots that say stuff: You are on a chatroom and then all of a sudden a bot joins and says something ie. "Your new website has been updated". OR, "Someone made a pullrequest on github, please somebody go there and accept it"

- a mix of those 2: the bot will say stuff and also accept/interact commands

IRC is really simple. The bot simply reads text and takes action. Or, just take action and talk on the channel. Its completely diffrent from slack bots because it is simpler it will not need the programmer to set up a WEB SERVER in order to receive messages from slack. Seriously.. the bot should connect there just like the user does and read messages, parse and take action.

Long live IRC =)

BOTs that say stuff works this way: You are on a channel and then all of a sudden a BOT joins and says: "The new release of your website has been successfully updated"


> And then you teach them a thing or two, let them evolve and weeks later when you less expect it, that same person is thriving on the terminal he hated initially. I have seen this happen a couple times... windows people saying linux is awkward. or even that i3-wm is awkward, until they get to learn it and they completely change their mind.

Usually I have met two kinds of people. Those who do not need any motivation to learn new things about computers. And those who will just flat out refuse to learn anything that remotely does not look like what they are already accustomed to.


> The same people that prefer slack because they never really tried IRC, might say they prefer slack because it allows them to write BOTs.

The biggest "win" for Slack where I worked was getting the non-engineers on it (product, UX, etc), and I doubt they prefer Slack because of the bot writing :)


Well, you can set up a web server using netcat too. Just recently there was an article on HN doing basically that.

However Slack does require HTTPS which complicates things, but is also quite a must in current day and age.


What’s the nicest looking IRC client these days?

I lately only ever use any chat client sporadically so I’m out of touch, but may be needing a platform soon.

Interesting note: I worked at AOL when AIM was introduced and was one of the first users :-P When I moved to tech support of a local cable internet company that was our official work chat :-)


As someone who's been on irc since the mid 90s and have had and still do have a couple of Irssis running in screens for 10+ years, I have to say that irccloud is pretty great for ease of use. There was an open source clone called ircanywhere, but it seems abandoned.

I have no idea what the future holds, and I always welcome new tools and disruptions, and I'm using slack, discord, messenger etc for various communities. What keeps me from leaving irc is:

* friction in moving all users that have been using an IRC channel for 20 years

* stupid stuff in slack and messenger like lock in and slow search. I really like grep:ing logs for links and discussions and then reading the context up and down, which I have found difficult in web services.


If you're looking for an open source alternative to IRCCloud, then The Lounge[1] pretty much fills that niche.

[1] https://github.com/thelounge/thelounge


Disclaimer: I personally do not need emoji's.

Does TheLounge let users upload custom emoji? I ask, because my coworkers say, "You can take Slack from my cold dead hands". There was even a great emoji war.

I would like to stand up a web interface to IRC and let folks play around on it. I tried Convos, but it didn't seem to fit that piece of the puzzle.

For the backend, I have always used UnrealIRCD + Anope services. It has always been rock solid and scales beyond any need I could imagine. It would be great if there were a modern web interface I could put in front of it that people would want to use.


No, it does not support that. Just uses unicode emojis and lets the OS/browser handle the rendering


Thanks. I totally understand and agree. The problem I am faced with is that Slack (a former gaming company) has gotten people hooked / trained / conditioned on the custom emoji.


No, it doesn't support custom emojis. Even if it did, only this particular client would display them and not any other IRC client.


Thankyou. That would probably be ok, since Slack using the IRC gateway had the same effect.


+1 to The Lounge. It's how I was able to get a few friends & coworkers to start using IRC.


Are you using The Lounge for work? Would you mind sharing which company? It would help me find out if/what companies are (disclaimer: I'm one of the dev). Thanks!


haha this client name reminds me of the old mIRC Channel List days!


Yeah, irssi is running perfectly fine for last 20 years, icq, msn, Skype, discord, everything comes and goes, longins/password got forgotten and lost.

But there is always that irc channel easily to get into and will be there in 20 years.

I know that I can extend my irssi client with plugins needed to preserve history, flag stuff, save in database by triggers, then export that in whatever way I want and serve to the users.


I just wish irssi supported other scripting languages. I don't particularly dislike Perl and it's not like it needs to do very complex stuff, but it'd be fun to tinker with it with my language of choice.


Use the irssi proxy and connect any scripting language or bot framework you like (that supports IRC of course)

I used to do this anyway so that I could reload the bot without reconnect spam


I hate grepping my IRC logs. I wish ZNC had a plug-in that allowed searching logs.


ZNC has the shell plugin, which I use for grepping logs. It's still grepping logs but I can do it from my IRC client.


That’s literally the first actual use of the shell functionality that makes sense!


Here are a couple I just found. I've not tried either but hope to later today.

1) https://github.com/pR0Ps/znc-logsearch

2) https://github.com/robinsmidsrod/znc-log-viewer/blob/master/...


I'm using Louge [0] It's a web application with nodejs stuff.

[0] https://github.com/thelounge/thelounge


You might want to take a look at https://www.irccloud.com.

The best apps tend to be platform dependent. I know many who like http://colloquy.info for mac, for example.


I'm fairly impressed with Quassel:

https://quassel-irc.org/


Especially when used in the core/client split version, which allows you to use the webclient https://github.com/magne4000/quassel-webserver/, the irssi-client https://github.com/phhusson/quassel-irssi, the iOS client https://woboq.com/iquassel.html, the Android client https://play.google.com/store/apps/details?id=com.iskrembile... or https://f-droid.org/packages/com.iskrembilen.quasseldroid/, the new alpha of the new android client https://quasseldroid.info/, and the fulltext search https://github.com/justjanne/quassel-rest-search (with demo here: http://s3.kuschku.de/public/quassel-rest-search.mp4 )

Quassel alone is a kinda nice client, with the entire ecosystem around it, it becomes amazingly powerful.

And the beauty of the Qt client is that, being Qt, you can fully style it with css - e.g. https://bugs.quassel-irc.org/projects/quassel-irc/wiki/Style...

Disclaimer: I contribute to some of the above mentioned projects)


That is so incredible! I've never split it up, I just use the "all-in-one" package usually. Might take the time to deploy the detached server on DO sometime.


For me: WeeChat (running in a screen/tmux) + Glowing Bear (webinterface WeeChat frontend).


WeeChat + screen is awesome. I was using it for Slack. It handled their strange use of +v/-v for user is away at least, better than Epic

I've never tried Glowing Bear. Maybe that would be a nice way for friends to get comfortable with IRC?


You still can, with Wee- Slack (https://github.com/wee-slack/wee-slack) that's what I use now.


Oh sorry, I just meant a way to get friends comfortable with IRC by having a simple doc that says how to use Glowing Bear in front of a simple weechat config so that they could easily move to IRC vs. slack. i.e. even using freenode with a modern web interface. I've seen the wee-chat-slack plugin, but it feels wrong using a normal IRC client to a heavy web stack.


If you have a Mac, Textual is a great IRC client although their upgrade policy is a bit frustrating, in that upgrades don't seem to be free for life, only discounted.


'Great' is relative. Textual (and Colloquy) are tolerable at best.


For Mac, Colloquy is quite good: http://colloquy.info

Works well, and is a native app that fits well into the general ecosystem.


I think Textual looks cleaner and is more functional than Textual - probably because the Textual team picks and chooses what Mac app design cues to use.


Was the second instance of "textual" (out of the 3) meant to say something else?


Ha - good catch. Colloquy not Textual. I was on the John.


IRCCloud and their night theme + their Android + iOS app.


I prefer Limechat for macOS. It’s plain and simple but not terminal based or archaic looking. At least to me anyway. And it has themes.


When I was a wild-haired youth, mIRC was my client of choice, but these days I much prefer KVIrc.


I use Limechat on OSX and Hexchat on Windows and am mildly dissatisfied with both.


I already commented on this, but have you tried Colloquy for Mac?

http://colloquy.info


bitchx


irssi, it really enhances the experience when you can brag about your e-peen


Slack is literally worse than XMPP or IRC at most things. The only improvement that Slack has is newer UI and you can bill someone to manage it on your company's behalf instead of paying someone in house.


When I learn a new language, the first things I do is I write an IRC bot. Such a fun task.

Right now my plan is to convert my good old (but still in heavy use, with MegaHAL!) bot [0] to Haskell, while reading the book and learning the language. The current bot was my last ever Ruby project and while I take using a new language as a challenge, the Cinch [1] framework is definitely worth a try if you want to create a bot quickly.

[0] https://github.com/pimeys/diskotappi [1] https://github.com/cinchrb/cinch


For those wondering, RFC's can be installed to /usr/share/doc/rfc/txt/ with the rfc package[0] on Arch Linux. Ubuntu has the doc-rfc package[1] with installs to /usr/share/doc/RFC.

[0]: https://www.archlinux.org/packages/community/any/rfc/

[1]: https://packages.ubuntu.com/xenial/doc-rfc


I tried the commands given (plus a few more I just guessed) and they all worked. What an enlightening demonstration of IRC's simplicity! This comes at a good time because I've been having issues with eggdrop, maybe now I'll just write something tiny to replace the bits of functionality I want.


The problem with eggdrop is that it does TOO much things.

* Keeping an internal ban list? Check.

* Removing stale bans from the channel? Check.

* Keep the bot opped? Check.

* Has built-in user management? Check.

* Uses telnet or DCC to manage the bot? Check.

All that features have it's use, but most of the time they are not needed. Instead people new to eggdrop have to "fight" with that features.

* User keeps getting banned when he enters the channel, even after an op removed the ban. Channel op has to learn about the internal ban list.

* Eggdrop removes all bans after 180 minutes (default).

Eggdrop admin has to disable that feature or add the user to the internal ban list.

* For non-channel admin bots, the bot does not need to be op.

Eggdrop will complain about it.

* Built-in user management uses part of the hostmask.

You got a new ISP, good luck restoring your access to the bot.

And it doesn't play nice with the accounts from IRC services.

* DCC doesn't work behind if you are behind NAT. And using telnet means using a different program.

In the past, I tried to solve several of that problems with Tcl scripts, with variable success.

* Allow the bot to be managed through commands in IRC.

* Bind to raw events, hide them (return 1) from eggdrop and send a replacement command through an internal API.

I had to use that to make eggdrop aware of the popular +qa modes (channel owner and channel admin)

Or replace the user host so eggdrop sees a fake host with the account name in it. Solves the problem with the user management through hostmasks.

In the end, I gave up. I wrote an IRC Bot in Tcl and re-implemented the Tcl API, so I could use the old eggdrop scripts.


TIL that eggdrop is still being developed / maintained.. I had a few bots running around EFNet and Undernet in ~96. Hadn't heard this reference in years.

http://www.eggheads.org/


Op me cause I'm lame.


FWIW, you can still use your favorite IRC client (e.g. WeeChat + Glowing Bear) with Slack by using wee-slack (https://github.com/wee-slack/wee-slack)


I've been using wee-slack for months, but I always assumed it was using the IRC bridge under the hood - judging by the fact that it's still working right now, I guess that's not the case :)


I think they'll shut down all remaining IRC and XMPP gateways by May 15. So we still have a little over 2 months from now.


It uses the WebSocket API.


Are there any good books/comprehensive resources for a beginner wanting to experiment with the irc protocol? I tried setting up my own irc server on an aws instance once. Opening the firewalls, connecting it to other clouds and to the clients was hard [for me]. Would love a step by step guide, that gives quick win and further confidence to get started.

This was my original inspiration: https://aaronparecki.com/2015/08/29/8/why-i-live-in-irc


so cool read IRC Bot in HN front page. I remember when I started to program, hacking irc scripts for fun, thanks for the post, remembers me good times. (RIP t7ds)


mIRC scripts is what you meant, right? That's basically how I started in programming.

One of the things that certainly contributed for keeping my interest in programming was the quick feedback. No need for confusing setups, just open the editor and start doing something. I know a lot of people that started this way and are good programmers nowadays.


Can't speak for OP, but my progression went like this starting in 1995:

- Start wasting lots of time in MSN chatrooms

- Parents cancel MSN and switch to local ISP. Mourn loss of chatrooms.

- Discover IRC using the mIRC client

- Start playing around with mIRC scripting

- Get into Linux because that's what the crowd I hung out with on IRC was using

- Switch to epic and BitchX and start scripting on this clients

- Get into eggdrops and start scripting those and then start looking through the actual source code and making changes

- Start writing my own bots

Amazing how much my current career as a software dev is owed to things I learned because I liked "wasting" time chatting online.


Nostalgic read! Same here, '96. Then getting into irc wars, net splits and nickname collisions, taking over channels. Finding bugs in eggdrop 1.1.5 to gain op on channels. Never did work with TCL again though.


Same, I wrote a bunch of mIRC scripts then my dad kept switching the family PC off and they weren't useful anymore. So i learned to make IRC bots in PHP. what a time.


Shameless plug for our NodeJS IRC Bot Framework Tennu: https://github.com/Tennu/tennu

Connect in one line of code:

`require('tennu').Client('../config/myNetwork.json').connect();`


> IRC is over 20 years old

IRC is turning 30 this year, actually.

Yeah


Not directly related, but I found an irc bot this guy wrote. IN BRAINFUCK.

https://github.com/SirCmpwn/bf-irc-bot


RIP Eggdrops


Nuts. We were writing IRC bots in the 1990s when eggdrop bot was around.


anyone remember VladBot?


I wish someone would pick up megahal and bring it up to date.


- 80% of the article: complaining about Slack

- 20% of the article: pretending to write a bot (and never actually writing a bot) that does about 1% of what a bot on Slack can do

Article title: "How to write an IRC bot"

I've personally written a (admittedly crappy) four-way integration between Slack, IRC, XMPP, and Telegram [1]. IRC and XMPP are consistently the worst protocols to write for if you want anything but plain text. And believe you me, people do want something besides plain text.

And don't get me started on clients for those :)

Funnily enough, irccloud is basically trying to do what Slack is doing, only with IRC: a web-based interface, with private channels, embedded media, etc. The only way to ,enjoy all that is to use the web-based clients, etc.

[1] https://github.com/dmitriid/tetrad


Seriously?

What did you expect? The secret sauce is on the client.

For example, user pastes in plain text, a youtube url:

userXXX: http://youtube.com/cool-video

Then lets say user2 client reads that message, then it will parse it and check if youtube.com has a plugin enabled. If it does, it will get the thumnail and title and display it in a nicer way than just the URL. But it was initially just a url.

I think you want a HTML chat with javascript. Try making that... and discover that it is not secure to accept and run javascript from unkown users.

So plain text means securer! -- without code that might be evalled.


I see you've never used Slack before.

Slack doesn't run a "youtube plugin javascript". It does link unfurling [1]. Precisely for this reason: "it is not secure to accept and run javascript from unkown users.". And, of course, it supports unfurling for a lot of things out of the box: links, images, youtube and vimeo videos, spotify playlists etc.

That is there in the protocol/API. Your client may then chose to display those unfurled links however it wants. Slack's client presents them more or less exactly the way users may want, consistently across multiple platforms.

Neither IRC no XMPP have that. That's why you mistakenly think that the only recourse is to "accept and run javascript from unkown users on the client".

And yes. Most users do want a chat with formatting, unfurled links, inline messages, inline video, emoji reactions, multifunctional bots etc. That's why they flock to Slack, not to IRC/XMPP.

---

[1] https://api.slack.com/docs/message-link-unfurling#slack_app_...




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: