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

View file

@ -1,6 +1,6 @@
<div id="nm-list">
<% APP_DATA[instance.zone.to_sym][:nms].each do |nm| %>
<% is_popped = instance.pops.filter { |pop| (Time.current - 120.minutes) <= pop.created_at }.any? { |pop| pop.name == nm[:name].parameterize } %>
<% is_popped = instance.pops.filter { |pop| (Time.now.utc - 120.minutes) <= pop.created_at }.any? { |pop| pop.name == nm[:name].parameterize } %>
<section class="<%= class_names(popped: is_popped, missing_reqs: has_missing_reqs?(nm, forecast)) %>">
<div>
<img src="<%= "/#{nm[:element]}.png" %>" alt="<%= nm[:element] %>" width="30" />

View file

@ -40,3 +40,17 @@
</button>
<% end %>
</div>
<h3>Import from ffxiv-eureka.com</h3>
<p>
Paste the text from the "killed NMs" button
<img src="/the_button.png" title="this one" alt="the button" />
in here, and we'll create an identical tracker for you.
</p>
<%= form_with url: new_from_fe_path do |f| %>
<%= f.text_field :info, placeholder: "Paste here!" %>
<%= f.submit "Create" %>
<% end %>