Sha256: 46a9b56d584303af4eecb8bda1870db6cc64f57638dbb8487857c002dcceea9b

Contents?: true

Size: 975 Bytes

Versions: 35

Compression:

Stored size: 975 Bytes

Contents

class QwtfDiscordBotDashboard
  THIRTY_SECONDS = 30

  def run
    bot = Discordrb::Commands::CommandBot.new(
      token: QwtfDiscordBot.config.token,
      client_id: QwtfDiscordBot.config.client_id,
      help_command: false,
      prefix: proc do |message|
        match = /^\!(\w+)(.*)/.match(message.content)
        if match
          first = match[1]
          rest = match[2]
          # Return the modified string with the first word lowercase:
          "#{first.downcase}#{rest}"
        end
      end
    )

    bot.run(true)

    @dashboards ||= QwtfDiscordBot.config.dashboards.map do |dashboard_config|
      Dashboard.new(dashboard_config, bot)
    end

    every(THIRTY_SECONDS) do
      @dashboards.each do |dashboard|
        dashboard.update
      end
    end
  end

  private

  def every(n_seconds)
    loop do
      before = Time.now
      yield
      interval = n_seconds - (Time.now - before)
      sleep(interval) if interval > 0
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
qwtf_discord_bot-6.3.1 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-6.3.0 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-6.2.2 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-6.2.1 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-6.2.0 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-6.1.5 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-6.1.4 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-6.1.3 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-6.1.2 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-6.1.1 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-6.1.0 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-6.0.4 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-6.0.3 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-6.0.2 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-6.0.1 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-5.5.26 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-5.5.25 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-5.5.24 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-5.5.23 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
qwtf_discord_bot-5.5.22 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb