Class: Discorb::ScheduledEvent
- Inherits:
-
DiscordModel
- Object
- DiscordModel
- Discorb::ScheduledEvent
- Defined in:
- lib/discorb/event.rb
Defined Under Namespace
Classes: Metadata
Class Attribute Summary collapse
-
.entity_type -> Object
readonly
Returns the value of attribute entity_type.
-
.privacy_level -> Object
readonly
Returns the value of attribute privacy_level.
-
.status -> Object
readonly
Returns the value of attribute status.
Instance Attribute Summary collapse
-
#channel -> Discorb::Channel?
readonly
The channel of the event.
-
#creator -> Discorb::User
readonly
The user who created the event.#.
-
#description -> String
readonly
The description of the event.
-
#entity_id -> Discorb::Snowflake
readonly
The ID of the entity the event is for.
-
#entity_type -> :stage_instance, ...
readonly
The type of the event.
- #guild -> Object readonly
-
#id -> Discorb::Snowflake
readonly
The ID of the event.
-
#metadata -> Discorb::ScheduledEvent::Metadata
readonly
The metadata of the event.
-
#name -> String
readonly
The name of the event.
-
#privacy_level -> :guild_only
readonly
The privacy level of the event.
-
#scheduled_end_time -> Time
(also: #end_time, #end_at)
readonly
The time the event ends.
-
#scheduled_start_time -> Time
(also: #start_time, #start_at)
readonly
The time the event starts.
-
#status -> :scheduled, ...
readonly
The status of the event.
-
#time -> Range<Time>
readonly
The time range of the event.
-
#user_count -> Integer
readonly
The user count of the event.
Instance Method Summary collapse
-
#cancel -> Object
Cancels the event.
-
#complete -> Object
(also: #finish)
Completes the event.
-
#delete! -> Object
(also: #destroy!)
Deletes the event.
-
#edit(type: Discorb::Unset, name: Discorb::Unset, description: Discorb::Unset, start_time: Discorb::Unset, end_time: Discorb::Unset, privacy_level: Discorb::Unset, location: Discorb::Unset, channel: Discorb::Unset, status: Discorb::Unset) -> Object
(also: #modify)
Create a scheduled event for the guild.
-
#fetch_users(limit = nil, before: nil, after: nil, with_member: true) -> Array<Discorb::Member>
(also: #fetch_members)
Fetches the event users.
-
#start -> Object
Starts the event.
Methods inherited from DiscordModel
Class Attribute Details
.entity_type -> Object (readonly)
Returns the value of attribute entity_type.
273 274 275 |
# File 'lib/discorb/event.rb', line 273 def entity_type @entity_type end |
.privacy_level -> Object (readonly)
Returns the value of attribute privacy_level.
273 274 275 |
# File 'lib/discorb/event.rb', line 273 def privacy_level @privacy_level end |
.status -> Object (readonly)
Returns the value of attribute status.
273 274 275 |
# File 'lib/discorb/event.rb', line 273 def status @status end |
Instance Attribute Details
#channel -> Discorb::Channel? (readonly)
Returns The channel of the event. Only present if the event will do in stage instance or voice channel.
75 76 77 |
# File 'lib/discorb/event.rb', line 75 def guild @client.guilds[@guild_id] end |
#creator -> Discorb::User (readonly)
Returns The user who created the event.#.
75 76 77 |
# File 'lib/discorb/event.rb', line 75 def guild @client.guilds[@guild_id] end |
#description -> String (readonly)
Returns The description of the event.
42 43 44 |
# File 'lib/discorb/event.rb', line 42 def description @description end |
#entity_id -> Discorb::Snowflake (readonly)
Returns The ID of the entity the event is for.
59 60 61 |
# File 'lib/discorb/event.rb', line 59 def entity_id @entity_id end |
#entity_type -> :stage_instance, ... (readonly)
Returns The type of the event.
57 58 59 |
# File 'lib/discorb/event.rb', line 57 def entity_type @entity_type end |
#guild -> Object (readonly)
75 76 77 |
# File 'lib/discorb/event.rb', line 75 def guild @client.guilds[@guild_id] end |
#id -> Discorb::Snowflake (readonly)
Returns The ID of the event.
38 39 40 |
# File 'lib/discorb/event.rb', line 38 def id @id end |
#metadata -> Discorb::ScheduledEvent::Metadata (readonly)
Returns The metadata of the event.
61 62 63 |
# File 'lib/discorb/event.rb', line 61 def @metadata end |
#name -> String (readonly)
Returns The name of the event.
40 41 42 |
# File 'lib/discorb/event.rb', line 40 def name @name end |
#privacy_level -> :guild_only (readonly)
Returns The privacy level of the event.
53 54 55 |
# File 'lib/discorb/event.rb', line 53 def privacy_level @privacy_level end |
#scheduled_end_time -> Time (readonly) Also known as: end_time, end_at
Returns The time the event ends.
49 50 51 |
# File 'lib/discorb/event.rb', line 49 def scheduled_end_time @scheduled_end_time end |
#scheduled_start_time -> Time (readonly) Also known as: start_time, start_at
Returns The time the event starts.
45 46 47 |
# File 'lib/discorb/event.rb', line 45 def scheduled_start_time @scheduled_start_time end |
#status -> :scheduled, ... (readonly)
Returns The status of the event.
55 56 57 |
# File 'lib/discorb/event.rb', line 55 def status @status end |
#time -> Range<Time> (readonly)
Returns The time range of the event.
75 76 77 |
# File 'lib/discorb/event.rb', line 75 def guild @client.guilds[@guild_id] end |
#user_count -> Integer (readonly)
Returns The user count of the event.
63 64 65 |
# File 'lib/discorb/event.rb', line 63 def user_count @user_count end |
Instance Method Details
#cancel -> Object
Cancels the event. Shortcut for edit(status: :canceled)
.
191 192 193 |
# File 'lib/discorb/event.rb', line 191 def cancel edit(status: :canceled) end |
#complete -> Object Also known as: finish
Completes the event. Shortcut for edit(status: :completed)
.
182 183 184 |
# File 'lib/discorb/event.rb', line 182 def complete edit(status: :completed) end |
#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.
Deletes the event.
200 201 202 203 204 |
# File 'lib/discorb/event.rb', line 200 def delete! Async do @client.http.delete("/guilds/#{@guild_id}/scheduled-events/#{@id}").wait end end |
#edit(type: Discorb::Unset, name: Discorb::Unset, description: Discorb::Unset, start_time: Discorb::Unset, end_time: Discorb::Unset, privacy_level: Discorb::Unset, location: Discorb::Unset, channel: Discorb::Unset, status: Discorb::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.
Create a scheduled event for the guild.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/discorb/event.rb', line 110 def edit( type: Discorb::Unset, name: Discorb::Unset, description: Discorb::Unset, start_time: Discorb::Unset, end_time: Discorb::Unset, privacy_level: Discorb::Unset, location: Discorb::Unset, channel: Discorb::Unset, status: Discorb::Unset ) Async do payload = case (type == Discorb::Unset) ? @entity_type : type when :stage_instance raise ArgumentError, "channel must be provided for stage_instance events" unless channel { name: name, description: description, scheduled_start_time: start_time.iso8601, scheduled_end_time: end_time&.iso8601, privacy_level: Discorb::ScheduledEvent.privacy_level.key(privacy_level) || Discorb::Unset, channel_id: channel&.id, entity_type: Discorb::ScheduledEvent.entity_type.key(:stage_instance), status: Discorb::ScheduledEvent.status.key(status) || Discorb::Unset, }.reject { |_, v| v == Discorb::Unset } when :voice raise ArgumentError, "channel must be provided for voice events" unless channel { name: name, description: description, scheduled_start_time: start_time.iso8601, scheduled_end_time: end_time&.iso8601, privacy_level: Discorb::ScheduledEvent.privacy_level.key(privacy_level) || Discorb::Unset, channel_id: channel&.id, entity_type: Discorb::ScheduledEvent.entity_type.key(:voice), status: Discorb::ScheduledEvent.status.key(status) || Discorb::Unset, }.reject { |_, v| v == Discorb::Unset } when :external raise ArgumentError, "location must be provided for external events" unless location raise ArgumentError, "end_time must be provided for external events" unless end_time { name: name, description: description, channel_id: nil, scheduled_start_time: start_time.iso8601, scheduled_end_time: end_time.iso8601, privacy_level: Discorb::ScheduledEvent.privacy_level.key(privacy_level) || Discorb::Unset, entity_type: Discorb::ScheduledEvent.entity_type.key(:external), entity_metadata: { location: location, }, status: Discorb::ScheduledEvent.status.key(status) || Discorb::Unset, }.reject { |_, v| v == Discorb::Unset } else raise ArgumentError, "Invalid scheduled event type: #{type}" end @client.http.patch("/guilds/#{@guild_id}/scheduled-events/#{@id}", payload).wait end end |
#fetch_users(limit = nil, before: nil, after: nil, with_member: true) -> Array<Discorb::Member> Also known as: fetch_members
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.
You can fetch all of members by not specifying a parameter.
Fetches the event users.
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/discorb/event.rb', line 223 def fetch_users(limit = nil, before: nil, after: nil, with_member: true) Async do if limit.nil? after = 0 res = [] while true _resp, users = @client.http.get("/guilds/#{@guild_id}/scheduled-events/#{@id}/users?limit=100&after=#{after}&with_member=true").wait if users.empty? break end res += users.map { |u| Member.new(@client, @guild_id, u[:user], u[:member]) } after = users.last[:user][:id] end res else params = { limit: limit, before: Discorb::Utils.try(after, :id), after: Discorb::Utils.try(around, :id), with_member: with_member, }.filter { |_k, v| !v.nil? }.to_h _resp, = @client.http.get("/channels/#{channel_id.wait}/messages?#{URI.encode_www_form(params)}").wait .map { |m| Message.new(@client, m.merge({ guild_id: @guild_id.to_s })) } end end end |
#start -> Object
Starts the event. Shortcut for edit(status: :active)
.
175 176 177 |
# File 'lib/discorb/event.rb', line 175 def start edit(status: :active) end |