Class: Discorb::GuildTemplate

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

Overview

Represents a guild template.

Defined Under Namespace

Classes: TemplateGuild

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DiscordModel

#==, #eql?, #inspect

Instance Attribute Details

#code -> String (readonly)

Returns The code of the template.

Returns:

  • (String)

    The code of the template.



9
10
11
# File 'lib/discorb/guild_template.rb', line 9

def code
  @code
end

#created_at -> Time (readonly)

Returns The time this template was created.

Returns:

  • (Time)

    The time this template was created.



19
20
21
# File 'lib/discorb/guild_template.rb', line 19

def created_at
  @created_at
end

#creator -> Discorb::User (readonly)

Returns The user who created this template.

Returns:



17
18
19
# File 'lib/discorb/guild_template.rb', line 17

def creator
  @creator
end

#description -> String (readonly)

Returns The description of the template.

Returns:

  • (String)

    The description of the template.



13
14
15
# File 'lib/discorb/guild_template.rb', line 13

def description
  @description
end

#is_dirty -> Boolean (readonly) Also known as: dirty?

Returns Whether this template is dirty.

Returns:

  • (Boolean)

    Whether this template is dirty.



28
29
30
# File 'lib/discorb/guild_template.rb', line 28

def is_dirty
  @is_dirty
end

#name -> String (readonly)

Returns The name of the template.

Returns:

  • (String)

    The name of the template.



11
12
13
# File 'lib/discorb/guild_template.rb', line 11

def name
  @name
end

#serialized_source_guild -> Discorb::GuildTemplate::TemplateGuild (readonly) Also known as: content

Returns The guild where the template was created.

Returns:



25
26
27
# File 'lib/discorb/guild_template.rb', line 25

def serialized_source_guild
  @serialized_source_guild
end

#source_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:

  • (nil)

    The object wasn't cached.

  • (Discorb::Guild)

    The guild this template is based on.

  • (nil)

    Client wasn't able to find the guild this template is based on.



# File 'lib/discorb/guild_template.rb', line 31

#source_guild_id -> Discorb::Snowflake (readonly)

Returns The ID of guild where the template was created.

Returns:



23
24
25
# File 'lib/discorb/guild_template.rb', line 23

def source_guild_id
  @source_guild_id
end

#updated_at -> Time (readonly)

Returns The time this template was last updated.

Returns:

  • (Time)

    The time this template was last updated.



21
22
23
# File 'lib/discorb/guild_template.rb', line 21

def updated_at
  @updated_at
end

#usage_count -> Integer (readonly)

Returns The number of times this template has been used.

Returns:

  • (Integer)

    The number of times this template has been used.



15
16
17
# File 'lib/discorb/guild_template.rb', line 15

def usage_count
  @usage_count
end

Instance Method Details

#delete! -> Async::Task<void> Also known as: destroy!

Delete the template.

Returns:

  • (Async::Task<void>)

    The task.



96
97
98
99
100
101
# File 'lib/discorb/guild_template.rb', line 96

def delete!
  Async do
    @client.http.request(Route.new("/guilds/#{@source_guild_id}/templates/#{@code}",
                                   "//guilds/:guild_id/templates/:code", :delete)).wait
  end
end

#edit(name = nil, description = Discorb::Unset) -> 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 template.

Parameters:

  • name (String) (defaults to: nil)

    The new name of the template.

  • description (String) (defaults to: Discorb::Unset)

    The new description of the template.

Returns:

  • (Async::Task<void>)

    The task.



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/discorb/guild_template.rb', line 62

def edit(name = nil, description = Discorb::Unset)
  Async do
    payload = {}
    payload[:name] = name if name
    payload[:description] = description if description != Discorb::Unset
    @client.http.request(
      Route.new("/guilds/#{@source_guild_id}/templates/#{@code}", "//guilds/:guild_id/templates/:code",
                :patch), payload
    ).wait
  end
end

#update -> Async::Task<void>

Update the template.

Returns:

  • (Async::Task<void>)

    The task.



82
83
84
85
86
87
88
# File 'lib/discorb/guild_template.rb', line 82

def update
  Async do
    _resp, data = @client.http.request(Route.new("/guilds/#{@source_guild_id}/templates/#{@code}",
                                                 "//guilds/:guild_id/templates/:code", :put)).wait
    _set_data(data)
  end
end