Sha256: 0808d8929db1dc95401fdeb4537b5ce38dd9f72f8089052801992487332241e6

Contents?: true

Size: 1.21 KB

Versions: 15

Compression:

Stored size: 1.21 KB

Contents

require "discorb"

class MessageExpander
  include Discorb::Extension

  @@message_regex = Regexp.new(
    '(?!<)https://(?:ptb\.|canary\.)?discord(?:app)?\.com/channels/' \
    "(?<guild>[0-9]{18})/(?<channel>[0-9]{18})/(?<message>[0-9]{18})(?!>)"
  )

  event :message do |message|
    next if message.author.bot?

    message.content.to_enum(:scan, @@message_regex).map { Regexp.last_match }.each do |match|
      ch = @client.channels[match[:channel]]
      next if ch.nil?

      begin
        url_message = ch.fetch_message(match[:message]).wait
      rescue Discorb::NotFoundError
        url_message.add_reaction(Discorb::UnicodeEmoji["x"])
      else
        embed = Discorb::Embed.new(
          nil, url_message.content,
          color: Discorb::Color[:blurple],
          timestamp: url_message.created_at,
          author: Discorb::Embed::Author.new(
            url_message.author.name,
            url: url_message.jump_url,
            icon: url_message.author.avatar.url,
          ),
          footer: Discorb::Embed::Footer.new(
            "#{url_message.guild.name} / #{ch.name}",
            icon: url_message.guild.icon&.url,
          ),
        )
        message.reply embed: embed
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
discorb-0.13.4 examples/extension/message_expander.rb
discorb-0.13.3 examples/extension/message_expander.rb
discorb-0.13.2 examples/extension/message_expander.rb
discorb-0.13.1 examples/extension/message_expander.rb
discorb-0.13.0 examples/extension/message_expander.rb
discorb-0.12.4 examples/extension/message_expander.rb
discorb-0.12.3 examples/extension/message_expander.rb
discorb-0.12.2 examples/extension/message_expander.rb
discorb-0.12.1 examples/extension/message_expander.rb
discorb-0.12.0 examples/extension/message_expander.rb
discorb-0.11.4 examples/extension/message_expander.rb
discorb-0.11.3 examples/extension/message_expander.rb
discorb-0.11.2 examples/extension/message_expander.rb
discorb-0.11.1 examples/extension/message_expander.rb
discorb-0.11.0 examples/extension/message_expander.rb