Sha256: 424a83cfb0eb64e9edf041ebcd2fa5dc9f46a2dc37a20fd2343c160455052d02

Contents?: true

Size: 1.42 KB

Versions: 8

Compression:

Stored size: 1.42 KB

Contents

class Dashboard
  def initialize(dashboard_config, bot)
    @server = bot.server(dashboard_config["server_id"])
    @endpoints = dashboard_config["endpoints"]
    @messages = {}

    channel_name = dashboard_config["name"]

    old_dashboard_channel = @server.channels.find do |chan|
      chan.name == channel_name
    end

    @channel = if old_dashboard_channel
      position = old_dashboard_channel.position
      topic = old_dashboard_channel.topic
      category = old_dashboard_channel.category
      old_dashboard_channel.delete

      @server.create_channel(channel_name).tap do |channel|
        channel.position = position
        channel.topic = topic if topic
        channel.category = category if category
      end
    else
      @server.create_channel(channel_name).tap do |channel|
        channel.topic = "QWTF Bot Dashboard"
      end
    end
  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
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
qwtf_discord_bot-5.5.17 lib/dashboard.rb
qwtf_discord_bot-5.5.16 lib/dashboard.rb
qwtf_discord_bot-5.5.15 lib/dashboard.rb
qwtf_discord_bot-5.5.14 lib/dashboard.rb
qwtf_discord_bot-5.5.13 lib/dashboard.rb
qwtf_discord_bot-5.5.12 lib/dashboard.rb
qwtf_discord_bot-5.5.11 lib/dashboard.rb
qwtf_discord_bot-5.5.10 lib/dashboard.rb