Sha256: d0a52355de050936ce12be7c3ee004fb48a87671959101734a43223a7d236621

Contents?: true

Size: 987 Bytes

Versions: 1

Compression:

Stored size: 987 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) && sleep(5)

    @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

1 entries across 1 versions & 1 rubygems

Version Path
qwtf_discord_bot-5.5.7 lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb