Sha256: 73831e08277c066346c848eb9f47d3984a6a57a3a873056a5271b15167054143

Contents?: true

Size: 1.58 KB

Versions: 5

Compression:

Stored size: 1.58 KB

Contents

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

    channel_name = dashboard_config["name"]

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

    @channel = if old_dashboard_channel
                 old_messages = JSON.parse(
                   Discordrb::API::Channel.messages(
                     "Bot #{QwtfDiscordBot.config.token}",
                     old_dashboard_channel.id,
                     100
                   )
                 )

                 old_messages.each do |old_message|
                   sleep 2
                   old_dashboard_channel.message(old_message['id']).delete
                 end

                 old_dashboard_channel
               else
                 @server.create_channel(channel_name).tap do |channel|
                   channel.topic = "QWTF Bot Dashboard"
                 end
               end
  end

  def update
    messages = {}

    @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

5 entries across 5 versions & 1 rubygems

Version Path
qwtf_discord_bot-5.5.22 lib/dashboard.rb
qwtf_discord_bot-5.5.21 lib/dashboard.rb
qwtf_discord_bot-5.5.20 lib/dashboard.rb
qwtf_discord_bot-5.5.19 lib/dashboard.rb
qwtf_discord_bot-5.5.18 lib/dashboard.rb