From a15cbeb3073db3a28573a2f19bf147b35b2b97d2 Mon Sep 17 00:00:00 2001 From: Matchu Date: Wed, 2 Aug 2023 14:58:16 -0700 Subject: [PATCH] Remove pet state labeling & Neopets gem This labeling technique hasn't worked in a long time bc it requires being logged in. These days we just manually label them with the 2020 support tools I think! Clearing out the Neopets gem should help us manage some gem dep conflicts in the 4.2 upgrade too (I think the nokogiri one gets tricky?) --- Gemfile | 1 - Gemfile.lock | 8 ------- app/models/pet.rb | 1 - app/models/pet_state.rb | 50 ++++++++++++++++++++++------------------- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/Gemfile b/Gemfile index efafc12d..2dfa6bac 100644 --- a/Gemfile +++ b/Gemfile @@ -39,7 +39,6 @@ gem 'sanitize', '~> 2.0.3' # For working with Neopets APIs. # unstable version of RocketAMF interprets info registry as a hash instead of an array gem 'RocketAMF', :git => 'https://github.com/rubyamf/rocketamf.git' -gem 'neopets', '~> 0.2.0', :git => 'https://github.com/matchu/neopets.git' # For working with the OpenNeo ID service. gem 'msgpack', '~> 0.5.3' diff --git a/Gemfile.lock b/Gemfile.lock index 8af4ad77..98619c40 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,10 +1,3 @@ -GIT - remote: https://github.com/matchu/neopets.git - revision: 5d13a720b616ba57fbbd54541f3e5daf02b3fedc - specs: - neopets (0.2.0) - nokogiri (~> 1.5.2) - GIT remote: https://github.com/rubyamf/rocketamf.git revision: 796f591d002b5cf47df436dbcbd6f2ab00e869ed @@ -228,7 +221,6 @@ DEPENDENCIES memcache-client (~> 1.8.5) msgpack (~> 0.5.3) mysql2 (>= 0.3.11) - neopets (~> 0.2.0)! nokogiri (~> 1.5.2) openneo-auth-signatory (~> 0.1.0) parallel (~> 1.13.0) diff --git a/app/models/pet.rb b/app/models/pet.rb index 509c44a2..dc39352b 100644 --- a/app/models/pet.rb +++ b/app/models/pet.rb @@ -40,7 +40,6 @@ class Pet < ActiveRecord::Base biology = pet_data[:biology_by_zone] biology[0] = nil # remove effects if present @pet_state = self.pet_type.add_pet_state_from_biology! biology - @pet_state.label_by_pet(self, pet_data[:owner]) @items = Item.collection_from_pet_type_and_registries(self.pet_type, viewer_data[:object_info_registry], viewer_data[:object_asset_registry], options[:item_scope]) diff --git a/app/models/pet_state.rb b/app/models/pet_state.rb index f7d41fc4..04bd037b 100644 --- a/app/models/pet_state.rb +++ b/app/models/pet_state.rb @@ -98,30 +98,8 @@ class PetState < ActiveRecord::Base end end - def label_by_pet(pet, username) - # If this pet is already labeled with a gender/mood, or it's unconverted - # and therefore has none, skip. - return false if self.labeled? || self.unconverted? - - # Find this pet on the owner's userlookup, where we can get both its gender - # and its mood. - begin - user_pet = Neopets::User.new(username).pets. - find { |user_pet| user_pet.name.downcase == pet.name.strip.downcase } - self.female = user_pet.female? - self.mood_id = user_pet.mood.id - self.labeled = true - rescue - # If there's an error loading the userlookup data (e.g. account is - # frozen), no big deal; we just won't label the pet right now. Proceed - # as usual. - end - - true - end - def mood - Neopets::Pet::Mood.find(self.mood_id) + Mood.find(self.mood_id) end def gender_name @@ -246,5 +224,31 @@ class PetState < ActiveRecord::Base end end end + + # Copied from https://github.com/matchu/neopets/blob/5d13a720b616ba57fbbd54541f3e5daf02b3fedc/lib/neopets/pet/mood.rb + class Mood + attr_reader :id, :name + + def initialize(options) + @id = options[:id] + @name = options[:name] + end + + def self.find(id) + self.all_by_id[id.to_i] + end + + def self.all + @all ||= [ + Mood.new(:id => 1, :name => :happy), + Mood.new(:id => 2, :name => :sad), + Mood.new(:id => 4, :name => :sick) + ] + end + + def self.all_by_id + @all_by_id ||= self.all.inject({}) { |h, m| h[m.id] = m; h } + end + end end