logo

drewdevault.com

[mirror] blog and personal website of Drew DeVault git clone https://hacktivis.me/git/mirror/drewdevault.com.git

The-worlds-dumbest-IRC-bot.gmi (5798B)


  1. I’m an IRC power user, having been hanging out in 200+ channels on 10+ networks 24/7 for the past 10 years or so. Because IRC is standardized and simple, a common pastime for IRC enthusiasts is the creation of bots. In one of the social channels I hang out in, we’ve spent the past 6 years gradually building the world’s stupidest IRC bot: wormy.
  2. For a start, wormy is highly schizophrenic. Though it presents itself as a single bot, it is in fact a bouncer which combines the connections of 7 independent bots. At one point, this number was higher — as many as 11 — but some bots were consolidated.
  3. ```
  4. <@sircmpwn> .bots
  5. <wormy> Serving text/html since 2017, yours truly ["ps"] For a list of commands, try `.help`
  6. <wormy> minus' parcel tracking bot r10.b563abc (built on 2020-06-06T12:02:13Z, https://git.sr.ht/~minus/parcel-tracking-bot)
  7. <wormy> minus' dice bot r16.498a0b8 (built on 2020-02-04T20:16:14Z, https://git.sr.ht/~minus/dice-irc-bot)
  8. <wormy> Featuring arbitrary code execution by design and buffer overflows by mistake, jsbot checking in
  9. <wormy> Radiobot coming to you live from The Internet, taking listener requests at 1-800-GUD-SONGS
  10. <wormy> urlbot: live streaming moe directly to your eyeballs
  11. <wormy> o/ SirCmpwn made me so he wouldn't forget shit so much
  12. ```
  13. These bots provide a variety of features for channel members, such as checking tracking numbers for parcels out for delivery, requesting songs for our private internet radio, reading out the mimetypes and titles of URLs mentioned in the channel, or feeding queries into Wolfram Alpha.
  14. ```
  15. <wormy> Now playing: 8369492 小さき者への贖罪の為のソナタ by ALI PROJECT from 禁書 (4m42s FLAC)
  16. <wormy> Now playing: 1045361 アキノサクラ by Wakana from magic moment (5m0s FLAC) #live ♥ minus
  17. <wormy> Now playing: d0b1cb3 Forevermore by F from Cafe de Touhou 3 (4m9s FLAC) ♥ hummer12007
  18. <wormy> Now playing: 0911e90 Moeru San Shimai by Iwasaki Taku from Tengen Toppa Gurren Lagann Original Soundtrack - CD01 (3m3s FLAC)
  19. <wormy> Now playing: ac1a17e rebellion anthem by Yousei teikoku from rebellion anthem (5m15s MP3) ♥ minus
  20. <wormy> Now playing: a5ab39a Desirable Dream by GET IN THE RING from Aki-秋- (4m38s FLAC) ♥ minus
  21. ```
  22. Things really took off with the introduction of a truly stupid bot last year: jsbot. This bot adds a .js command which executes arbitrary JavaScript (using Fabrice Bellard’s quickjs) expressions, and sending their stringified result to the channel.
  23. ```
  24. <@sircmpwn> .js Array(16).join("wat" - 1) + " Batman!"
  25. <wormy> => NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN Batman!
  26. ```
  27. We soon realized, however, that what we had effectively created was a persistent JavaScript environment which was connected to IRC. This has made it possible to write even more IRC bots in the least practical manner imaginable: by writing JavaScript statements, one line at a time, into IRC messages, and hoping it works.
  28. This has not been an entirely smart move.
  29. One “feature”, inspired by Bryan Cantrill, records every time the word “fuck” is used in the channel. Then, whenever anyone says “wtf”, the bot helpfully offers up an example of the usage of the word “fuck” by printing one of the recorded messages. Here’s how it was made:
  30. ```
  31. <sircmpwn> .js let wtf = [];
  32. <wormy> => undefined
  33. <sircmpwn> .js on(/fuck/, msg => wtf.push(msg.text))
  34. <wormy> => 25
  35. <sircmpwn> .js on(/^what the fuck$/, msg => msg.reply(wtf[Math.floor(Math.random() * wtf.length)]))
  36. <wormy> => 26
  37. ```
  38. Here’s one which records whenever someone says “foo++” or “foo--” and keeps track of scores:
  39. ```
  40. .js on(/^([a-zA-Z0-9_]+)(\+\+|--)$/, (msg, thing, op) => { if (typeof scores[thing] === "undefined") scores[thing] = 0; scores[thing] += op === "++" ? 1 : -1; msg.reply(`${thing}: ${scores[thing]}`) });
  41. .js on(/\.score (.*)/, (msg, item) => msg.reply(scores[item]));
  42. .js let worst = () => Object.entries(scores).sort((a, b) => a[1] - b[1]).slice(0, 5).map(s => `${s[0]}: ${s[1]}`).join(", ");
  43. .js let best = () => Object.entries(scores).sort((a, b) => b[1] - a[1]).slice(0, 5).map(s => `${s[0]}: ${s[1]}`).join(", ");
  44. .js on(/^.worst$/, msg => msg.reply(worst()));
  45. .js on(/^.best$/, msg => msg.reply(best()));
  46. ```
  47. Other “features” written in horrible one-liners include SI unit conversions, rewriting undesirable URLs (e.g. m.wikipedia.org => en.wikipedia.org), answering “wormy you piece of shit” with “¯\_(ツ)_/¯”, and giving the obvious response to “make me a sandwich”.
  48. Eventually it occurred to us that we had two dozen stupid IRC bots storing not only their state, but their code, in a single long-lived process on some server. For a while, the answer to this was adding “don’t reboot this server kthx” to the MotD, but eventually we did some magic nonsense to make certain variables persistent:
  49. ```
  50. let persistent = {};
  51. function writePersistent() {
  52. let fd = std.open("persist.json", "w");
  53. fd.puts(JSON.stringify(persistent));
  54. fd.close();
  55. }
  56. let persist_handler = {
  57. set: (obj, prop, val) => {
  58. obj[prop] = val;
  59. writePersistent();
  60. },
  61. };
  62. let p = std.loadFile("persist.json");
  63. if (p !== null) {
  64. persistent = JSON.parse(p);
  65. Object.keys(persistent).map(key => {
  66. let proxy = new Proxy(persistent[key], persist_handler);
  67. persistent[key] = proxy;
  68. exports[key] = proxy;
  69. });
  70. }
  71. exports.persist = (name, obj) => {
  72. let proxy = new Proxy(obj, persist_handler);
  73. persistent[name] = proxy;
  74. writePersistent();
  75. return proxy;
  76. };
  77. ```
  78. Anyway, there’s no moral to this story. We just have a silly IRC bot and I thought I’d share that with you. If you want a stupid IRC bot for your own channel, jsbot is available on sourcehut. I highly disrecommend it and disavow any responsibility for the consequences.