iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
💩

I Built an Overwhelmingly Smelly Discord Bot: Featuring Qusine

に公開

This article is part of Day 9 of the Shitty App Advent Calendar (Series 3).

I've created a Discord Bot that gives off an overwhelming stench!!!!!!!!!

Repository: sevenc-nanashi/pooper

https://github.com/sevenc-nanashi/pooper/blob/main/formatted.rb

What is Qusine?

Qusine refers to a Quine that is particularly malodorous.
Source: None

How it works

Libraries

This time, I used my own Discord API wrapper, discorb.
For the database, I used sqlite, and for operations, I used sequel.

Replacement Section

client.on :message do |message|
  next if message.author.bot?
  next unless channels.include?(message.channel.id.to_s)
  next unless message.channel.is_a?(Discorb::TextChannel)
  channel = message.channel
  (
    channel.fetch_webhooks.wait.find { |w| w.name == "Pooper" } ||
      channel.create_webhook("Pooper").wait
  ).post(
    message.content.gsub(
      /[\p{Emoji}\p{Emoji_Component}&&[:^ascii:]]|<a?:[a-z0-9_]+:[0-9]+>/i,
      "💩"
    ),
    username: message.author.name,
    avatar_url: message.author.avatar.url,
    allowed_mentions:
      Discorb::AllowedMentions.new(
        everyone: false,
        roles: false,
        users: false
      )
  )
  message.delete
end
  1. Get a Webhook named Pooper (create one if it doesn't exist),
  2. Replace with /[\p{Emoji}\p{Emoji_Component}&&[:^ascii:]]|<a?:[a-z0-9_]+:[0-9]+>/i (Reference: How to determine if a string contains emojis in Ruby (Summary of Q&A on ruby-jp slack on 2021/11/08)),
  3. Post the replaced content using the same name and icon as the author,
  4. Delete the original message.

It works something like that.

The Qusine Part

client.slash(
  "qusine",
  "このBotのソースコードを表示します。"
) do |interaction|
  interaction.post(
    attachment:
      Discorb::Attachment.from_string(
        " " * 51 + "eval(\n" + " " * 49 + "(s='" + s +
          "').gsub(/\\s/,''))",
        "pooper.rb"
      )
  )
end

Other than the initial eval( and (s=', and the final ').gsub(/\s/,'')), it's just writing out s. Simple.

So, is this actually practical?

None. (Definitively)

But it's okay because I found a bug in the Webhook class while making this.

Afterword

An overwhelming stench. This is my second Quine, and I think I've created a pretty good piece. (First work: Bad Quine!)
Thank you for reading to the end.

Promotion

I'm creating a Ruby Discord API wrapper called discorb. I'd be happy if you could report bugs or send PRs.

Discussion