Class: Discorb::GuildTemplate
- Inherits:
-
DiscordModel
- Object
- DiscordModel
- Discorb::GuildTemplate
- Defined in:
- lib/discorb/guild_template.rb
Overview
Represents a guild template.
Defined Under Namespace
Classes: TemplateGuild
Instance Attribute Summary collapse
-
#code -> String
readonly
The code of the template.
-
#created_at -> Time
readonly
The time this template was created.
-
#creator -> Discorb::User
readonly
The user who created this template.
-
#description -> String
readonly
The description of the template.
-
#is_dirty -> Boolean
(also: #dirty?)
readonly
Whether this template is dirty.
-
#name -> String
readonly
The name of the template.
-
#serialized_source_guild -> Discorb::GuildTemplate::TemplateGuild
(also: #content)
readonly
The guild where the template was created.
- #source_guild -> nil, Discorb::Guild readonly
-
#source_guild_id -> Discorb::Guild
readonly
The guild where the template was created.
-
#updated_at -> Time
readonly
The time this template was last updated.
-
#usage_count -> Integer
readonly
The number of times this template has been used.
Instance Method Summary collapse
-
#delete! -> Object
(also: #destroy!)
Delete the template.
-
#edit(name = nil, description = :unset) -> Object
(also: #modify)
Edit the template.
-
#update -> Object
Update the template.
Methods inherited from DiscordModel
Instance Attribute Details
#code -> String (readonly)
Returns 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.
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.
17 18 19 |
# File 'lib/discorb/guild_template.rb', line 17 def creator @creator end |
#description -> String (readonly)
Returns 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.
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.
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.
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)
This method returns an object from client cache. it will return nil
if the object is not in cache.
|
# File 'lib/discorb/guild_template.rb', line 31
|
#source_guild_id -> Discorb::Guild (readonly)
Returns The guild where the template was created.
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.
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.
15 16 17 |
# File 'lib/discorb/guild_template.rb', line 15 def usage_count @usage_count end |
Instance Method Details
#delete! -> Object Also known as: destroy!
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Delete the template.
83 84 85 86 87 |
# File 'lib/discorb/guild_template.rb', line 83 def delete! Async do @client.internet.delete("/guilds/#{@source_guild_id}/templates/#{@code}").wait end end |
#edit(name = nil, description = :unset) -> Object Also known as: modify
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
The arguments of this method are defaultly set to :unset
. Specify value to set the value, if not don't specify or specify :unset
.
Edit the template.
55 56 57 58 59 60 61 62 |
# File 'lib/discorb/guild_template.rb', line 55 def edit(name = nil, description = :unset) Async do payload = {} payload[:name] = name if name payload[:description] = description if description != :unset @client.internet.patch("/guilds/#{@source_guild_id}/templates/#{@code}", payload).wait end end |
#update -> Object
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
Update the template.
71 72 73 74 75 76 |
# File 'lib/discorb/guild_template.rb', line 71 def update Async do _resp, data = @client.internet.put("/guilds/#{@source_guild_id}/templates/#{@code}").wait _set_data(data) end end |