Sha256: da45b6a29140afc8ca54ca9697d33586b350796fe354ab070fc1d47f15cf5337

Contents?: true

Size: 677 Bytes

Versions: 28

Compression:

Stored size: 677 Bytes

Contents

require "discorb"

client = Discorb::Client.new

client.once :standby 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

28 entries across 28 versions & 1 rubygems

Version Path
discorb-0.13.4 examples/simple/wait_for_message.rb
discorb-0.13.3 examples/simple/wait_for_message.rb
discorb-0.13.2 examples/simple/wait_for_message.rb
discorb-0.13.1 examples/simple/wait_for_message.rb
discorb-0.13.0 examples/simple/wait_for_message.rb
discorb-0.12.4 examples/simple/wait_for_message.rb
discorb-0.12.3 examples/simple/wait_for_message.rb
discorb-0.12.2 examples/simple/wait_for_message.rb
discorb-0.12.1 examples/simple/wait_for_message.rb
discorb-0.12.0 examples/simple/wait_for_message.rb
discorb-0.11.4 examples/simple/wait_for_message.rb
discorb-0.11.3 examples/simple/wait_for_message.rb
discorb-0.11.2 examples/simple/wait_for_message.rb
discorb-0.11.1 examples/simple/wait_for_message.rb
discorb-0.11.0 examples/simple/wait_for_message.rb
discorb-0.10.3 examples/simple/wait_for_message.rb
discorb-0.10.2 examples/simple/wait_for_message.rb
discorb-0.10.1 examples/simple/wait_for_message.rb
discorb-0.10.0 examples/simple/wait_for_message.rb
discorb-0.9.6 examples/simple/wait_for_message.rb