Sha256: a8e1658f0156ad96f098420053c7050213dc62cb8f0d7f5a76a8bae5a704d321

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

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

    old_dashboard_channel = @server.channels.find do |chan|
      chan.name == "dashboard" && chan.topic = "QWTF Bot Dashboard"
    end

    old_dashboard_channel && old_dashboard_channel.delete

    @channel = @server.create_channel("dashboard")
    @channel.topic = "QWTF Bot Dashboard"
    @channel.position = dashboard_config["position"]
  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

2 entries across 2 versions & 1 rubygems

Version Path
qwtf_discord_bot-5.5.7 lib/dashboard.rb
qwtf_discord_bot-5.5.6 lib/dashboard.rb