module Discorb::View::Base::Prepend
Modules for the prepend.
Attributes
interaction[W]
@return [Discorb::MessageComponentInteraction] The interaction.
Public Class Methods
new(client, channel, ...)
click to toggle source
@private
Calls superclass method
# File lib/discorb/view/view.rb, line 124 def initialize(client, channel, ...) @client = channel.instance_variable_get(:@client) @channel = channel @message_id = nil @stopped = false @components = self.class.components.dup.map { |id, component| [id, ComponentHandler.new(component.object.dup, component.block)] }.to_h @result = Result.new(nil, [], []) super(...) end
Public Instance Methods
actual_view()
click to toggle source
@private
# File lib/discorb/view/view.rb, line 184 def actual_view view = self.class.views.filter { |v| v.check }.find { |v| instance_exec(@interaction, &v.check) } if view.nil? view = self.class.views.find { |v| v.check.nil? } end view end
render()
click to toggle source
Renders the view.
# File lib/discorb/view/view.rb, line 158 def render instance_exec(@result, &actual_view.block) components = @result.components.map do |c| case c when Symbol @components[c]&.object or raise ArgumentError "Unknown component ID #{c}" when Button c else raise ArgumentError "Component must be a Symbol or a Button" end end if @stopped components.each do |component| component.disabled = true end end if @interaction @interaction.edit(@result.content, embeds: @result.embeds, components: components).wait else msg = @channel.post(@result.content, embeds: @result.embeds, components: components).wait @message_id = msg.id end end
start()
click to toggle source
@private
# File lib/discorb/view/view.rb, line 135 def start render @client.views[@message_id.to_s] = self end
stop!(disable: true, delete: false)
click to toggle source
Stops the view.
@param [Boolean] disable Whether to disable the components. @param [Boolean] delete Whether to delete the message.
# File lib/discorb/view/view.rb, line 146 def stop!(disable: true, delete: false) @client.views.delete(@message_id.to_s) if disable @stopped = true render end @channel.delete_message!(@message_id) if delete end