Sha256: ae39cd9157eaeb895a07fa41e2e7cb2738b37d72028246fd4af9473c3950a506

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

class QwtfDiscordBotServer < QwtfDiscordBot # :nodoc:
  def run
    bot = Discordrb::Commands::CommandBot.new(
      token: @token,
      client_id: @client_id,
      prefix: '!'
    )

    bot.command :server do |event, *args|
      if args.empty?
        event.channel.send_message(
          'Provide a server address e.g. `!server sydney.fortressone.org` ' \
          'or use `!active` or `!all`'
        )
      else
        endpoint = args.first
        qstat_response = QstatRequest.new(endpoint)
        message = qstat_response.server_summary
        embed = qstat_response.to_embed

        if embed
          event.channel.send_embed(message, embed)
        else
          event.channel.send_message(message)
        end
      end
    end

    bot.command :all do |event|
      @endpoints.each do |endpoint|
        endpoint.channel_ids.each do |channel_id|
          next unless event.channel.id == channel_id

          qstat_request = QstatRequest.new(endpoint.address)
          message = qstat_request.server_summary
          embed = qstat_request.to_embed


          if embed
            event.channel.send_embed(message, embed)
          else
            event.channel.send_message(message)
          end
        end
      end

      return nil
    end

    bot.command :active do |event|
      @endpoints.each do |endpoint|
        endpoint.channel_ids.each do |channel_id|
          next unless event.channel.id == channel_id

          qstat_request = QstatRequest.new(endpoint.address)
          next if qstat_request.is_empty?

          message = qstat_request.server_summary
          embed = qstat_request.to_embed


          if embed
            event.channel.send_embed(message, embed)
          else
            event.channel.send_message(message)
          end
        end
      end

      return nil
    end

    bot.run
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qwtf_discord_bot-4.0.0 lib/qwtf_discord_bot/qwtf_discord_bot_server.rb