Class: Discorb::Guild::Widget

Inherits:
DiscordModel show all
Defined in:
lib/discorb/guild.rb

Overview

Represents a guild widget.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DiscordModel

#==, #eql?, #inspect

Instance Attribute Details

#channel -> nil, Discorb::Channel (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:



# File 'lib/discorb/guild.rb', line 1687

#channel_id -> Discorb::Snowflake (readonly)

Returns The channel ID.

Returns:



1681
1682
1683
# File 'lib/discorb/guild.rb', line 1681

def channel_id
  @channel_id
end

#enabled -> Boolean (readonly) Also known as: enabled?, enable?

Returns Whether the widget is enabled.

Returns:

  • (Boolean)

    Whether the widget is enabled.



1683
1684
1685
# File 'lib/discorb/guild.rb', line 1683

def enabled
  @enabled
end

#guild -> nil, Discorb::Guild (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:



# File 'lib/discorb/guild.rb', line 1687

#guild_id -> Discorb::Snowflake (readonly)

Returns The guild ID.

Returns:



1679
1680
1681
# File 'lib/discorb/guild.rb', line 1679

def guild_id
  @guild_id
end

#json_url -> String (readonly)

Returns The JSON URL.

Returns:

  • (String)

    The JSON URL.



# File 'lib/discorb/guild.rb', line 1687

Instance Method Details

#edit(enabled: nil, channel: nil, reason: nil) -> Async::Task<void> Also known as: modify

Note:

The arguments of this method are defaultly set to Discorb::Unset. Specify value to set the value, if not don't specify or specify Discorb::Unset.

Edit the widget.

Parameters:

  • enabled (Boolean) (defaults to: nil)

    Whether the widget is enabled.

  • channel (Discorb::GuildChannel) (defaults to: nil)

    The channel.

  • reason (String) (defaults to: nil)

    The reason for editing the widget.

Returns:

  • (Async::Task<void>)

    The task.



1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
# File 'lib/discorb/guild.rb', line 1726

def edit(enabled: nil, channel: nil, reason: nil)
  Async do
    payload = {}
    payload[:enabled] = enabled unless enabled.nil?
    payload[:channel_id] = channel.id if channel_id
    @client
      .http
      .request(
        Route.new(
          "/guilds/#{@guild_id}/widget",
          "//guilds/:guild_id/widget",
          :patch
        ),
        payload,
        audit_log_reason: reason
      )
      .wait
  end
end

#iframe(theme: "dark", width: 350, height: 500) -> String

Return iframe HTML of the widget.

Parameters:

  • theme ("dark", "light") (defaults to: "dark")

    The theme of the widget.

  • width (Integer) (defaults to: 350)

    The width of the widget.

  • height (Integer) (defaults to: 500)

    The height of the widget.

Returns:

  • (String)

    The iframe HTML.



1761
1762
1763
1764
1765
1766
1767
1768
# File 'lib/discorb/guild.rb', line 1761

def iframe(theme: "dark", width: 350, height: 500)
  # rubocop:disable Layout/LineLength
  [
    %(<iframe src="https://canary.discord.com/widget?id=#{@guild_id}&theme=#{theme}" width="#{width}" height="#{height}"),
    %(allowtransparency="true" frameborder="0" sandbox="allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"></iframe>)
  ].join
  # rubocop:enable Layout/LineLength
end