Hello world

First open source release of Campfire 🎉
This commit is contained in:
Kevin McConnell
2025-08-15 11:02:42 +01:00
commit df76a227dc
664 changed files with 36235 additions and 0 deletions

65
script/dev/flood-room Executable file
View File

@@ -0,0 +1,65 @@
#!/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"

103
script/dev/populate Executable file
View File

@@ -0,0 +1,103 @@
#!/usr/bin/env ruby
require File.expand_path("../../config/environment", File.dirname(__FILE__))
require "optparse"
require "faker"
# Sample usage: script/populate --rooms 100 --users 100 --messages 100
PASSWORD_DIGEST = BCrypt::Password.create("secret123456", cost: BCrypt::Engine::MIN_COST)
def create_user
User.insert({ name: Faker::Name.name, email_address: Faker::Internet.email, password_digest: PASSWORD_DIGEST })
end
def create_room(room_id:, creator_id:)
Room.insert({
id: room_id, type: "Rooms::Open", creator_id: creator_id,
name: "#{Faker::Creature::Animal.name.capitalize} #{Faker::Game.title}"
})
end
def create_memberships(room_id:, user_ids:)
Membership.insert_all(user_ids.collect { |user_id| { user_id: user_id, room_id: room_id } })
end
def create_message(message_id:, room_id:, creator_id:)
Message.insert({ id: message_id, room_id: room_id, creator_id: creator_id, client_message_id: SecureRandom.alphanumeric(12) })
ActionText::RichText.insert({ name: "body", record_type: "Message", record_id: message_id, body: "<div>#{Faker::Lorem.words(number: 10).join(" ")}</div>" })
end
def parse_options!
options = {}
parser = OptionParser.new do |opts|
opts.banner = "Usage: ruby script/dev/populate.rb [options]"
opts.on("--users COUNT", Integer, "Number of users") { |c| options[:user_count] = c }
opts.on("--rooms COUNT", Integer, "Number of rooms (default: 100)") { |c| options[:room_count] = c }
opts.on("--messages COUNT", Integer, "Number of messages per room (default: 100)") { |c| options[:message_count] = c }
opts.on "-h", "--help", "Prints this help" do
puts opts
exit
end
end.tap(&:parse!)
if options[:user_count].blank?
warn(parser.help)
exit(1)
else
options
end
end
options = parse_options!
print "This will reset the database and repopulate it. Are you sure? [y/n] "
if gets.chomp == "y"
puts "Resetting development DB"
`RAILS_ENV=development ./bin/rails db:reset`
puts "\nCreating first run (so you can login as king@example.com/secret123456)"
FirstRun.create! name: "King of The Hill", email_address: "king@example.com", password: "secret123456"
user_count = options[:user_count]
room_count = options[:room_count] || 100
message_count = options[:message_count] || 100
puts "\nCreating #{user_count} users"
user_count.times do |n|
create_user
print "."
end
puts "\n\nCreating #{room_count} rooms with #{message_count} messages"
user_ids = User.pluck(:id)
room_counter = message_counter = 0
room_count.times do |n|
room_counter += 1
create_room(room_id: room_counter, creator_id: user_ids.sample)
create_memberships(room_id: room_counter, user_ids: user_ids)
print "."
message_count.times do |n|
message_counter += 1
create_message(message_id: message_counter, room_id: room_counter, creator_id: user_ids.sample)
print "."
end
end
puts "\n\nRestarting server"
`./bin/rails restart`
puts "Done!"
else
puts "Nevermind then!"
end