mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-02-22 04:30:33 +09:00
66 lines
1.7 KiB
Ruby
Executable File
66 lines
1.7 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
require File.expand_path("../../config/environment", File.dirname(__FILE__))
|
|
require "optparse"
|
|
|
|
# Sample usage: script/flood-room --room 16384 --count 100
|
|
|
|
def parse_options!
|
|
options = {}
|
|
|
|
parser = OptionParser.new do |opts|
|
|
opts.banner = "Usage: ruby script/development/flood_topic.rb [options]"
|
|
|
|
opts.on "--room ROOM-ID", Integer, "Room ID to flood" do |room_id|
|
|
options[:room_id] = room_id
|
|
end
|
|
|
|
opts.on "--count COUNT", Integer, "Number of messages to send" do |count|
|
|
options[:count] = count
|
|
end
|
|
|
|
opts.on "--sleep SECONDS", Float, "How long to sleep between messages" do |sleep_interval|
|
|
options[:sleep] = sleep_interval
|
|
end
|
|
|
|
opts.on "-h", "--help", "Prints this help" do
|
|
puts opts
|
|
exit
|
|
end
|
|
end.tap(&:parse!)
|
|
|
|
if options[:room_id].blank?
|
|
warn(parser.help)
|
|
exit(1)
|
|
else
|
|
options
|
|
end
|
|
end
|
|
|
|
options = parse_options!
|
|
|
|
words = %w[
|
|
tacit watch store rinse bead rich idea raise draconian well-made interesting root
|
|
groan cows wine copper puffy tip fill spurious precede scorch lunch place
|
|
title mute wait relax gainful rabid preach freezing scandalous nebulous remain coast
|
|
]
|
|
|
|
room = Room.find options[:room_id]
|
|
users = room.users
|
|
|
|
count = options[:count] || 20
|
|
sleep_interval = options[:sleep] || 0
|
|
|
|
count.times do |n|
|
|
sentence = words.sample(rand(20) + 1).join(" ")
|
|
creator = users.sample
|
|
message_params = { room: room, client_message_id: Random.uuid, body: "%04d #{sentence}" % n, creator: creator }
|
|
|
|
message = Message.create! message_params
|
|
message.broadcast_append_to room, :messages, target: [ room, :messages ]
|
|
|
|
puts n if n > 0 && n % 10 == 0
|
|
sleep sleep_interval
|
|
end
|
|
|
|
puts "done"
|