feat: add ffxiv-eureka.com import function

This commit is contained in:
insects 2025-03-12 12:31:03 +01:00
parent a28484d0e0
commit e2c99cbc6a
9 changed files with 131 additions and 1 deletions

View file

@ -12,6 +12,52 @@ class InstanceController < ApplicationController
end
end
def create_from_fe
info = create_from_fe_params
# Make sure we have the correct string
if info.start_with?("NMs on cooldown:")
str = info.sub("NMs on cooldown:", "").strip
split = str.split("")
ts = Time.now.utc
zone = nil
results = split.map do |s|
# Grab the name and time until it can be repopped
name, time = s.split("(")
name = name.strip
time = time.gsub(/\D/, "") # remove anything but digits
# Try and guess the zone based on names
if zone.nil?
if APP_DATA[:anemos][:nms].any? { |nm| nm[:nick] == name }
zone = "anemos"
elsif APP_DATA[:pagos][:nms].any? { |nm| nm[:nick] == name }
zone = "pagos"
elsif APP_DATA[:pyros][:nms].any? { |nm| nm[:nick] == name }
zone = "pyros"
elsif APP_DATA[:hydatos][:nms].any? { |nm| nm[:nick] == name }
zone = "hydatos"
end
end
{
name: APP_DATA[zone.to_sym][:nms].find { |nm| nm[:nick] == name }[:name].parameterize,
created_at: ts - (120.minutes - time.to_i.minutes)
}
end
public_id = Nanoid.generate(size: 6)
name = Spicy::Proton.pair(" ")
password = Nanoid.generate(size: 4, alphabet: "0123456789")
instance = Instance.new(zone: zone, public_id: public_id, name: name, password: password)
if instance.save
Pop.insert_all(results.map { |r| { instance_id: instance.id, **r } })
@id = instance.public_id
@password = instance.password
render "set_password"
end
end
end
def show
@instance = Instance.includes(:pops, :fairies).find_by(public_id: show_instance_params)
if @instance
@ -61,6 +107,10 @@ class InstanceController < ApplicationController
params.expect(:zone)
end
def create_from_fe_params
params.expect(:info)
end
def show_instance_params
params.expect(:public_id)
end