Sha256: 160bdb84e1a73b3ddb735691572253b9f5208beb6f57a668683531be01e1267e

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

class Dashboard
  def initialize(channel, bot)
    @channel_id = channel["id"]
    @endpoints = channel["endpoints"]
    @bot = bot
    @messages = {}
  end

  def update
    @endpoints.each do |endpoint|
      qstat_request = QstatRequest.new(endpoint)

      if qstat_request.is_empty?
        if @messages[endpoint]
          @messages[endpoint].delete
          @messages.delete(endpoint)
        end

        next
      end

      embed = qstat_request.to_full_embed

      @messages[endpoint] = if @messages[endpoint]
                              @messages[endpoint].edit(nil, embed)
                            else
                              channel.send_embed(nil, embed)
                            end
    end
  end

  private

  def channel
    @channel ||= begin
                   data = Discordrb::API::Channel.resolve(
                     "Bot #{QwtfDiscordBot.config.token}",
                     @channel_id
                   )

                   Discordrb::Channel.new(JSON.parse(data), @bot)
                 end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
qwtf_discord_bot-5.5.5 lib/dashboard.rb
qwtf_discord_bot-5.5.4 lib/dashboard.rb
qwtf_discord_bot-5.5.3 lib/dashboard.rb