Sha256: 4004b265afbbe88565af17f78bc8d66712bd76fc5ca9c67a57c62881e1a5f039

Contents?: true

Size: 675 Bytes

Versions: 26

Compression:

Stored size: 675 Bytes

Contents

require "discorb"

client = Discorb::Client.new

client.once :ready do
  puts "Logged in as #{client.user}"
end

client.on :message do |message|
  next if message.author.bot?
  next unless message.content == "!quiz"

  operator = [:+, :-, :*].sample
  num1 = rand(1..10)
  num2 = rand(1..10)

  val = num1.send(operator, num2)
  message.channel.post("Quiz: `#{num1} #{operator} #{num2}`")
  begin
    msg = client.event_lock(:message, 30) { |m|
      m.content == val.to_s && m.channel == message.channel
    }.wait
  rescue Discorb::TimeoutError
    message.channel.post("No one answered...")
  else
    msg.reply("Correct!")
  end
end

client.run(ENV["DISCORD_BOT_TOKEN"])

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
discorb-0.7.6 examples/simple/wait_for_message.rb
discorb-0.7.3 examples/simple/wait_for_message.rb
discorb-0.7.2 examples/simple/wait_for_message.rb
discorb-0.7.1 examples/simple/wait_for_message.rb
discorb-0.7.0 examples/simple/wait_for_message.rb
discorb-0.6.1 examples/simple/wait_for_message.rb
discorb-0.6.0 examples/simple/wait_for_message.rb
discorb-0.5.6 examples/simple/wait_for_message.rb
discorb-0.5.5 examples/simple/wait_for_message.rb
discorb-0.5.4 examples/simple/wait_for_message.rb
discorb-0.5.3 examples/simple/wait_for_message.rb
discorb-0.5.2 examples/simple/wait_for_message.rb
discorb-0.5.1 examples/simple/wait_for_message.rb
discorb-0.5.0 examples/simple/wait_for_message.rb
discorb-0.4.2 examples/simple/wait_for_message.rb
discorb-0.4.1 examples/simple/wait_for_message.rb
discorb-0.4.0 examples/simple/wait_for_message.rb
discorb-0.3.1 examples/simple/wait_for_message.rb
discorb-0.3.0 examples/simple/wait_for_message.rb
discorb-0.2.5 examples/simple/wait_for_message.rb