From e2c99cbc6a1bb964d56bf6696895598ad1556cdc Mon Sep 17 00:00:00 2001 From: insects Date: Wed, 12 Mar 2025 12:31:03 +0100 Subject: [PATCH] feat: add ffxiv-eureka.com import function --- app/controllers/instance_controller.rb | 50 +++++++++++++++++++++++++ app/views/instance/_list.html.erb | 2 +- app/views/page/index.html.erb | 14 +++++++ config/routes.rb | 1 + data/anemos.toml | 20 ++++++++++ data/hydatos.toml | 11 ++++++ data/pagos.toml | 17 +++++++++ data/pyros.toml | 17 +++++++++ public/the_button.png | Bin 0 -> 628 bytes 9 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 public/the_button.png diff --git a/app/controllers/instance_controller.rb b/app/controllers/instance_controller.rb index 46c5f7b..abc1d21 100644 --- a/app/controllers/instance_controller.rb +++ b/app/controllers/instance_controller.rb @@ -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 diff --git a/app/views/instance/_list.html.erb b/app/views/instance/_list.html.erb index 6d8af11..03e2db9 100644 --- a/app/views/instance/_list.html.erb +++ b/app/views/instance/_list.html.erb @@ -1,6 +1,6 @@
<% 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 } %>
" alt="<%= nm[:element] %>" width="30" /> diff --git a/app/views/page/index.html.erb b/app/views/page/index.html.erb index f556a2c..64031cb 100644 --- a/app/views/page/index.html.erb +++ b/app/views/page/index.html.erb @@ -40,3 +40,17 @@ <% end %>
+ +

Import from ffxiv-eureka.com

+ +

+ Paste the text from the "killed NMs" button + the button + in here, and we'll create an identical tracker for you. +

+ +<%= form_with url: new_from_fe_path do |f| %> + <%= f.text_field :info, placeholder: "Paste here!" %> + <%= f.submit "Create" %> +<% end %> + diff --git a/config/routes.rb b/config/routes.rb index e37e4ce..ec9c047 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,7 @@ Rails.application.routes.draw do get "/up" => "rails/health#show", as: :rails_health_check post "/new", to: "instance#create", as: :new_instance + post "/new_from_fe", to: "instance#create_from_fe", as: :new_from_fe post "/pop", to: "instance#pop", as: :pop_in_instance post "/reset", to: "instance#reset", as: :reset_in_instance post "/auth", to: "instance#authenticate", as: :authenticate_to_instance diff --git a/data/anemos.toml b/data/anemos.toml index 815e29d..4aefc21 100644 --- a/data/anemos.toml +++ b/data/anemos.toml @@ -42,6 +42,7 @@ fairies = [ [[nms]] name = "Sabotender Corrido" +nick = "Sabo" level = 1 element = "wind" x = 14 @@ -53,6 +54,7 @@ level = 6 [[nms]] name = "The Lord of Anemos" +nick = "Lord" level = 2 element = "water" x = 30 @@ -65,6 +67,7 @@ level = 7 [[nms]] name = "Teles" +nick = "Teles" level = 3 element = "wind" x = 26 @@ -76,6 +79,7 @@ level = 8 [[nms]] name = "The Emperor of Anemos" +nick = "Emperor" level = 4 element = "wind" x = 17 @@ -88,6 +92,7 @@ level = 9 [[nms]] name = "Callisto" +nick = "Callisto" level = 5 element = "earth" x = 26 @@ -99,6 +104,7 @@ level = 10 [[nms]] name = "Number" +nick = "Number" level = 6 element = "lightning" x = 24 @@ -110,6 +116,7 @@ level = 11 [[nms]] name = "Jahannam" +nick = "Jaha" level = 7 element = "wind" x = 18 @@ -122,6 +129,7 @@ weather = "gales" [[nms]] name = "Amemet" +nick = "Amemet" level = 8 element = "fire" x = 15 @@ -133,6 +141,7 @@ level = 13 [[nms]] name = "Caym" +nick = "Caym" level = 9 element = "ice" x = 14 @@ -144,6 +153,7 @@ level = 14 [[nms]] name = "Bombadeel" +nick = "Bomba" level = 10 element = "earth" x = 28 @@ -156,6 +166,7 @@ night_only = true [[nms]] name = "Serket" +nick = "Serket" level = 11 element = "earth" x = 25 @@ -168,6 +179,7 @@ level = 16 [[nms]] name = "Judgmental Julika" +nick = "Julika" level = 12 element = "ice" x = 22 @@ -179,6 +191,7 @@ level = 17 [[nms]] name = "The White Rider" +nick = "Rider" level = 13 element = "lightning" x = 20 @@ -191,6 +204,7 @@ night_only = true [[nms]] name = "Polyphemus" +nick = "Poly" level = 14 element = "ice" x = 26 @@ -202,6 +216,7 @@ level = 19 [[nms]] name = "Simurgh's Strider" +nick = "Strider" level = 15 element = "wind" x = 29 @@ -214,6 +229,7 @@ level = 20 [[nms]] name = "King Hazmat" +nick = "Hazmat" level = 16 element = "fire" x = 35 @@ -225,6 +241,7 @@ level = 21 [[nms]] name = "Fafnir" +nick = "Fafnir" level = 17 element = "fire" x = 36 @@ -238,6 +255,7 @@ night_only = true [[nms]] name = "Amarok" +nick = "Amarok" level = 18 element = "ice" x = 8 @@ -249,6 +267,7 @@ level = 23 [[nms]] name = "Lamashtu" +nick = "Lamashtu" level = 19 element = "wind" x = 8 @@ -261,6 +280,7 @@ night_only = true [[nms]] name = "Pazuzu" +nick = "Paz" level = 20 element = "wind" x = 7 diff --git a/data/hydatos.toml b/data/hydatos.toml index 5bac111..f652d13 100644 --- a/data/hydatos.toml +++ b/data/hydatos.toml @@ -36,6 +36,7 @@ fairies = [ [[nms]] name = "Khalamari" +nick = "Khalamari" level = 50 element = "water" x = 11 @@ -47,6 +48,7 @@ level = 55 [[nms]] name = "Stegodon" +nick = "Stegodon" level = 51 element = "earth" x = 9 @@ -58,6 +60,7 @@ level = 56 [[nms]] name = "Molech" +nick = "Molech" level = 52 element = "ice" x = 7 @@ -70,6 +73,7 @@ level = 57 [[nms]] name = "Piasa" +nick = "Piasa" level = 53 element = "wind" x = 7 @@ -81,6 +85,7 @@ level = 58 [[nms]] name = "Frostmane" +nick = "Frostmane" level = 54 element = "fire" x = 8 @@ -92,6 +97,7 @@ level = 59 [[nms]] name = "Daphne" +nick = "Daphne" level = 55 element = "water" x = 25 @@ -103,6 +109,7 @@ level = 60 [[nms]] name = "King Goldemar" +nick = "Golde" level = 56 element = "lightning" x = 28 @@ -116,6 +123,7 @@ night_only = true [[nms]] name = "Leuke" +nick = "Leuke" level = 57 element = "earth" x = 37 @@ -127,6 +135,7 @@ level = 62 [[nms]] name = "Barong" +nick = "Barong" level = 58 element = "fire" x = 32 @@ -138,6 +147,7 @@ level = 63 [[nms]] name = "Ceto" +nick = "Ceto" level = 59 element = "water" x = 36 @@ -150,6 +160,7 @@ level = 64 [[nms]] name = "Provenance Watcher" +nick = "PW" level = 60 element = "fire" x = 32 diff --git a/data/pagos.toml b/data/pagos.toml index 515dc0d..5ffbc76 100644 --- a/data/pagos.toml +++ b/data/pagos.toml @@ -48,6 +48,7 @@ fairies = [ [[nms]] name = "The Snow Queen" +nick = "Queen" level = 20 element = "ice" x = 21 @@ -60,6 +61,7 @@ level = 25 [[nms]] name = "Taxim" +nick = "Taxim" level = 21 element = "earth" x = 25 @@ -72,6 +74,7 @@ night_only = true [[nms]] name = "Ash Dragon" +nick = "Dragon" level = 22 element = "fire" x = 29 @@ -83,6 +86,7 @@ level = 27 [[nms]] name = "Glavoid" +nick = "Glavoid" level = 23 element = "earth" x = 32 @@ -94,6 +98,7 @@ level = 28 [[nms]] name = "Anapos" +nick = "Anapos" level = 24 element = "water" x = 34 @@ -106,6 +111,7 @@ weather = "fog" [[nms]] name = "Hakutaku" +nick = "Haku" level = 25 element = "fire" x = 29 @@ -118,6 +124,7 @@ level = 30 [[nms]] name = "King Igloo" +nick = "Igloo" level = 26 element = "ice" x = 17 @@ -129,6 +136,7 @@ level = 31 [[nms]] name = "Asag" +nick = "Asag" level = 27 element = "lightning" x = 10 @@ -140,6 +148,7 @@ level = 32 [[nms]] name = "Surabhi" +nick = "Surabhi" level = 28 element = "earth" x = 10 @@ -151,6 +160,7 @@ level = 33 [[nms]] name = "King Arthro" +nick = "Arthro" level = 29 element = "water" x = 8 @@ -164,6 +174,7 @@ level = 34 [[nms]] name = "Mindertaur/Eldertaur" +nick = "Brothers" level = 30 element = "earth" x = 13 @@ -175,6 +186,7 @@ level = 35 [[nms]] name = "Holy Cow" +nick = "Holy Cow" level = 31 element = "water" x = 26 @@ -186,6 +198,7 @@ level = 36 [[nms]] name = "Hadhayosh" +nick = "Behe" level = 32 element = "lightning" x = 30 @@ -199,6 +212,7 @@ level = 37 [[nms]] name = "Horus" +nick = "Horus" level = 33 element = "fire" x = 25 @@ -211,6 +225,7 @@ level = 38 [[nms]] name = "Arch Angra Mainyu" +nick = "Mainyu" level = 34 element = "wind" x = 24 @@ -222,6 +237,7 @@ level = 39 [[nms]] name = "Copycat Cassie" +nick = "Cassie" level = 35 element = "ice" x = 22 @@ -235,6 +251,7 @@ level = 40 [[nms]] name = "Louhi" +nick = "Louhi" level = 35 element = "ice" x = 36 diff --git a/data/pyros.toml b/data/pyros.toml index 3360bdc..6228d23 100644 --- a/data/pyros.toml +++ b/data/pyros.toml @@ -26,6 +26,7 @@ fairies = [ [[nms]] name = "Leucosia" +nick = "Leucosia" level = 35 element = "water" x = 27 @@ -38,6 +39,7 @@ night_only = true [[nms]] name = "Flauros" +nick = "Flauros" level = 36 element = "lightning" x = 29 @@ -50,6 +52,7 @@ weather = "thunder" [[nms]] name = "The Sophist" +nick = "Sophist" level = 37 element = "wind" x = 31 @@ -61,6 +64,7 @@ level = 42 [[nms]] name = "Graffiacane" +nick = "Doll" level = 38 element = "ice" x = 23 @@ -73,6 +77,7 @@ level = 43 [[nms]] name = "Askalaphos" +nick = "Owl" level = 39 element = "wind" x = 19 @@ -85,6 +90,7 @@ level = 44 [[nms]] name = "Grand Duke Batym" +nick = "Batym" level = 40 element = "earth" x = 18 @@ -97,6 +103,7 @@ night_only = true [[nms]] name = "Aetolus" +nick = "Aetolus" level = 41 element = "lightning" x = 10 @@ -108,6 +115,7 @@ level = 46 [[nms]] name = "Lesath" +nick = "Lesath" level = 42 element = "fire" x = 13 @@ -119,6 +127,7 @@ level = 47 [[nms]] name = "Eldthurs" +nick = "Eldthurs" level = 43 element = "fire" x = 13 @@ -130,6 +139,7 @@ level = 48 [[nms]] name = "Iris" +nick = "Iris" level = 44 element = "water" x = 21 @@ -141,6 +151,7 @@ level = 49 [[nms]] name = "Lamebrix Strikebocks" +nick = "Lamebrix" level = 45 element = "earth" x = 21 @@ -153,6 +164,7 @@ level = 50 [[nms]] name = "Dux" +nick = "Dux" level = 46 element = "lightning" x = 27 @@ -165,6 +177,7 @@ level = 51 [[nms]] name = "Lumber Jack" +nick = "Jack" level = 47 element = "earth" x = 29 @@ -177,6 +190,7 @@ level = 52 [[nms]] name = "Glaukopis" +nick = "Glaukopis" level = 48 element = "fire" x = 31 @@ -188,6 +202,7 @@ level = 53 [[nms]] name = "Ying-Yang" +nick = "YY" level = 49 element = "water" x = 11 @@ -200,6 +215,7 @@ level = 54 [[nms]] name = "Skoll" +nick = "Skoll" level = 50 element = "ice" x = 23 @@ -213,6 +229,7 @@ level = 55 [[nms]] name = "Penthesilea" +nick = "Penny" level = 50 element = "fire" x = 35 diff --git a/public/the_button.png b/public/the_button.png new file mode 100644 index 0000000000000000000000000000000000000000..261d8c73a50acfe5255442509c2b538cf015e091 GIT binary patch literal 628 zcmeAS@N?(olHy`uVBq!ia0vp^l0YoY!3HEd6;(2T6lZ})WHAE+-w_aIoT|+y4HV=p zag8X+$xqKrPRxm5Fg7-{h}|n`2bADJl89t5G&MMSQB4adu8|oMQBqu*62Mp0u&AnanrS6Ko`Gr>?P1Cj0Zhk978<3*G}8$$K)u`_Wz-uu(p&n_Xp7x8YY(_ zF3wKK=eUuPzr0f_IoYvkZl``?4FhjR(>|7@p0yWcB)QA-)4!LoKH2xAXt(k1-|x@7 z)d>*MH)Q#`H~C5#-;zwN@7vRN?6xdilM=PA<4DnlSF?9+*!|AvSg^pgl@qG|wAgOE zn;MbGlyIK!@M+&Pp9}f3#5$!kN@q+xD0+RzN28=Pwu!H=2nurWOiTO8wpuf*VGB1` z!>u{3a|M_J^w&Qw+}_yk#(aC}q(UP#?v!f=GfFBiC)}F8RrgDKeuZ3b!M>e}$1)CS zy=+fsI1=D!(6=g7CQR#AZlIpn$DQ~6evAKApYyGXgELUE%UDh+;YLo9WmnAf>FZSv zMt#3!y8MV1+vyWL-U(YTpL}Debf|hYD?>!*T(5#3w^#qjn0@6ByXvCFh2LlMFOm=! z-XNU!cxA=*q;z!?@1@#L=Jf~YC24Nx2=QPLSe`A|s1r2lh~PQbqvHJ5rH`bI#W(Ss zS$FyJQvIO6e|nC;T##9#-uWWcfBAC`{}=oA>{_M}-rSh&wUpyS{DeverQ&{=9naPrOeApYnw7mA?6B(f$h4s$2W^e(DCsG=rzBpUXO@geCwE7X*?3 literal 0 HcmV?d00001