Class: RubyCord::Guild::Widget

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DiscordModel

#==, #eql?, #inspect

Instance Attribute Details

#channelnil, RubyCord::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/rubycord/guild/widget.rb', line 18


#channel_idRubyCord::Snowflake (readonly)

Returns The channel ID.

Returns:



12
13
14
# File 'lib/rubycord/guild/widget.rb', line 12

def channel_id
  @channel_id
end

#enabledBoolean (readonly) Also known as: enabled?, enable?

Returns Whether the widget is enabled.

Returns:

  • (Boolean)

    Whether the widget is enabled.



14
15
16
# File 'lib/rubycord/guild/widget.rb', line 14

def enabled
  @enabled
end

#guildnil, RubyCord::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/rubycord/guild/widget.rb', line 18


#guild_idRubyCord::Snowflake (readonly)

Returns The guild ID.

Returns:



10
11
12
# File 'lib/rubycord/guild/widget.rb', line 10

def guild_id
  @guild_id
end

#json_urlString (readonly)

Returns The JSON URL.

Returns:

  • (String)

    The JSON URL.



# File 'lib/rubycord/guild/widget.rb', line 18


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 RubyCord::Unset. Specify value to set the value, if not don't specify or specify RubyCord::Unset.

Edit the widget.

Parameters:

  • enabled (Boolean) (defaults to: nil)

    Whether the widget is enabled.

  • channel (RubyCord::Guild::Channel) (defaults to: nil)

    The channel.

  • reason (String) (defaults to: nil)

    The reason for editing the widget.

Returns:

  • (Async::Task<void>)

    The task.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rubycord/guild/widget.rb', line 57

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(
        RubyCord::Internal::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.



92
93
94
95
96
97
98
99
# File 'lib/rubycord/guild/widget.rb', line 92

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