loot
This commit is contained in:
parent
0e380931b1
commit
97d5bd9ace
1
.gitignore
vendored
1
.gitignore
vendored
@ -36,3 +36,4 @@
|
|||||||
|
|
||||||
*.sqlite3*
|
*.sqlite3*
|
||||||
*DS_store*
|
*DS_store*
|
||||||
|
config/secrets.yml
|
90
.idea/gambosite.iml
generated
90
.idea/gambosite.iml
generated
@ -153,76 +153,78 @@
|
|||||||
<component name="RailsGeneratorsCache">
|
<component name="RailsGeneratorsCache">
|
||||||
<option name="generators">
|
<option name="generators">
|
||||||
<list>
|
<list>
|
||||||
<option value="active_record:migration" />
|
<option value="active_record:application_record" />
|
||||||
<option value="active_record:model" />
|
<option value="active_record:multi_db" />
|
||||||
<option value="active_record:observer" />
|
<option value="application_record" />
|
||||||
<option value="active_record:session_migration" />
|
<option value="authentication" />
|
||||||
|
<option value="benchmark" />
|
||||||
|
<option value="channel" />
|
||||||
<option value="controller" />
|
<option value="controller" />
|
||||||
<option value="erb:controller" />
|
<option value="erb:authentication" />
|
||||||
<option value="erb:mailer" />
|
|
||||||
<option value="erb:scaffold" />
|
|
||||||
<option value="generator" />
|
<option value="generator" />
|
||||||
<option value="helper" />
|
<option value="helper" />
|
||||||
<option value="integration_test" />
|
<option value="integration_test" />
|
||||||
|
<option value="jbuilder" />
|
||||||
|
<option value="job" />
|
||||||
|
<option value="mailbox" />
|
||||||
<option value="mailer" />
|
<option value="mailer" />
|
||||||
<option value="metal" />
|
|
||||||
<option value="migration" />
|
<option value="migration" />
|
||||||
<option value="model" />
|
<option value="model" />
|
||||||
<option value="model_subclass" />
|
|
||||||
<option value="observer" />
|
|
||||||
<option value="performance_test" />
|
|
||||||
<option value="plugin" />
|
|
||||||
<option value="resource" />
|
<option value="resource" />
|
||||||
<option value="scaffold" />
|
<option value="scaffold" />
|
||||||
<option value="scaffold_controller" />
|
<option value="scaffold_controller" />
|
||||||
<option value="session_migration" />
|
<option value="script" />
|
||||||
<option value="stylesheets" />
|
<option value="solid_cable:install" />
|
||||||
<option value="test_unit:controller" />
|
<option value="solid_cable:update" />
|
||||||
<option value="test_unit:helper" />
|
<option value="solid_cache:install" />
|
||||||
<option value="test_unit:integration" />
|
<option value="solid_queue:install" />
|
||||||
<option value="test_unit:mailer" />
|
<option value="stimulus" />
|
||||||
<option value="test_unit:model" />
|
<option value="system_test" />
|
||||||
<option value="test_unit:observer" />
|
<option value="task" />
|
||||||
<option value="test_unit:performance" />
|
<option value="test_unit:authentication" />
|
||||||
|
<option value="test_unit:channel" />
|
||||||
|
<option value="test_unit:generator" />
|
||||||
|
<option value="test_unit:install" />
|
||||||
|
<option value="test_unit:mailbox" />
|
||||||
<option value="test_unit:plugin" />
|
<option value="test_unit:plugin" />
|
||||||
<option value="test_unit:scaffold" />
|
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
<option name="myGenerators">
|
<option name="myGenerators">
|
||||||
<list>
|
<list>
|
||||||
<option value="active_record:migration" />
|
<option value="active_record:application_record" />
|
||||||
<option value="active_record:model" />
|
<option value="active_record:multi_db" />
|
||||||
<option value="active_record:observer" />
|
<option value="application_record" />
|
||||||
<option value="active_record:session_migration" />
|
<option value="authentication" />
|
||||||
|
<option value="benchmark" />
|
||||||
|
<option value="channel" />
|
||||||
<option value="controller" />
|
<option value="controller" />
|
||||||
<option value="erb:controller" />
|
<option value="erb:authentication" />
|
||||||
<option value="erb:mailer" />
|
|
||||||
<option value="erb:scaffold" />
|
|
||||||
<option value="generator" />
|
<option value="generator" />
|
||||||
<option value="helper" />
|
<option value="helper" />
|
||||||
<option value="integration_test" />
|
<option value="integration_test" />
|
||||||
|
<option value="jbuilder" />
|
||||||
|
<option value="job" />
|
||||||
|
<option value="mailbox" />
|
||||||
<option value="mailer" />
|
<option value="mailer" />
|
||||||
<option value="metal" />
|
|
||||||
<option value="migration" />
|
<option value="migration" />
|
||||||
<option value="model" />
|
<option value="model" />
|
||||||
<option value="model_subclass" />
|
|
||||||
<option value="observer" />
|
|
||||||
<option value="performance_test" />
|
|
||||||
<option value="plugin" />
|
|
||||||
<option value="resource" />
|
<option value="resource" />
|
||||||
<option value="scaffold" />
|
<option value="scaffold" />
|
||||||
<option value="scaffold_controller" />
|
<option value="scaffold_controller" />
|
||||||
<option value="session_migration" />
|
<option value="script" />
|
||||||
<option value="stylesheets" />
|
<option value="solid_cable:install" />
|
||||||
<option value="test_unit:controller" />
|
<option value="solid_cable:update" />
|
||||||
<option value="test_unit:helper" />
|
<option value="solid_cache:install" />
|
||||||
<option value="test_unit:integration" />
|
<option value="solid_queue:install" />
|
||||||
<option value="test_unit:mailer" />
|
<option value="stimulus" />
|
||||||
<option value="test_unit:model" />
|
<option value="system_test" />
|
||||||
<option value="test_unit:observer" />
|
<option value="task" />
|
||||||
<option value="test_unit:performance" />
|
<option value="test_unit:authentication" />
|
||||||
|
<option value="test_unit:channel" />
|
||||||
|
<option value="test_unit:generator" />
|
||||||
|
<option value="test_unit:install" />
|
||||||
|
<option value="test_unit:mailbox" />
|
||||||
<option value="test_unit:plugin" />
|
<option value="test_unit:plugin" />
|
||||||
<option value="test_unit:scaffold" />
|
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
class AdminController < ApplicationController
|
class AdminController < ApplicationController
|
||||||
# echo "ya got butts?" | sha256
|
|
||||||
PASSWORD = "50cf9308a2cd117a16f7c1f8eb2267fb87556066403b751f8fbf0af159bc9bac"
|
|
||||||
|
|
||||||
before_action :authenticate_admin, only: [:index, :set_alt, :clear_alt ]
|
before_action :authenticate_admin, only: [:index, :set_alt, :clear_alt ]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@ -42,7 +39,7 @@ class AdminController < ApplicationController
|
|||||||
|
|
||||||
def login_submit
|
def login_submit
|
||||||
pw = params[:password]
|
pw = params[:password]
|
||||||
if pw == PASSWORD
|
if pw == ENV["ADMINPW"]
|
||||||
session[:user_id] = 1
|
session[:user_id] = 1
|
||||||
redirect_to admin_path, notice: "Logged in!"
|
redirect_to admin_path, notice: "Logged in!"
|
||||||
else
|
else
|
||||||
|
@ -2,15 +2,16 @@ class BotController < ApplicationController
|
|||||||
skip_before_action :verify_authenticity_token
|
skip_before_action :verify_authenticity_token
|
||||||
before_action :authenticate
|
before_action :authenticate
|
||||||
|
|
||||||
def players
|
def leaderboard
|
||||||
|
players = Player.where(main_player_id: nil).order(purse: :desc)
|
||||||
|
render json: players
|
||||||
end
|
end
|
||||||
|
|
||||||
def summary
|
def lords
|
||||||
|
players = Player.where(main_player_id: nil).order(purse: :desc)
|
||||||
end
|
lords = []
|
||||||
|
lords << players.first
|
||||||
def player_name
|
lords << players.last
|
||||||
|
render json: lords
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
43
app/controllers/loot_controller.rb
Normal file
43
app/controllers/loot_controller.rb
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
class LootController < ApplicationController
|
||||||
|
skip_before_action :verify_authenticity_token, only: [ :create ]
|
||||||
|
before_action :authenticate, only: [ :create ]
|
||||||
|
|
||||||
|
respond_to? :json
|
||||||
|
|
||||||
|
def create
|
||||||
|
@loot = Loot.new(item_id: params[:item_id], item_name: params[:item_name], timestamp: params[:timestamp], roll_type: params[:roll_type])
|
||||||
|
|
||||||
|
player = Player.find_by(name: params[:player])
|
||||||
|
if player.nil?
|
||||||
|
player = Player.new(name: params[:player], wins: 0, losses: 0, purse: 0)
|
||||||
|
player.save
|
||||||
|
end
|
||||||
|
@loot.player = player
|
||||||
|
|
||||||
|
if @loot.save
|
||||||
|
render json: {}, status: :ok
|
||||||
|
else
|
||||||
|
render json: { error: "Unable to process input" }, status: :unprocessable_content
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def index
|
||||||
|
@players = Player.all.reject(&:alt?).map { |player| [
|
||||||
|
player.name,
|
||||||
|
player.get_loot_count_with_roll("mainspec"),
|
||||||
|
player.get_loot_count_with_roll("minor"),
|
||||||
|
player.get_loot_count_with_roll("offspec"),
|
||||||
|
player.get_loot_count_with_roll("transmog"),
|
||||||
|
]}.sort
|
||||||
|
end
|
||||||
|
|
||||||
|
def list
|
||||||
|
@loot = Loot.all.sort_by &:timestamp
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def already_reported_response
|
||||||
|
render json: { error: "Already reported this loot" }, status: :already_reported
|
||||||
|
end
|
||||||
|
end
|
2
app/helpers/loot_helper.rb
Normal file
2
app/helpers/loot_helper.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
module LootHelper
|
||||||
|
end
|
34
app/models/loot.rb
Normal file
34
app/models/loot.rb
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
class Loot < ApplicationRecord
|
||||||
|
belongs_to :player
|
||||||
|
|
||||||
|
def player_name_with_alt
|
||||||
|
if self.player.alt?
|
||||||
|
"#{self.player.name} (alt of #{self.player.main_player.name})"
|
||||||
|
else
|
||||||
|
self.player.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def wowhead
|
||||||
|
"https://wowhead.com/item=#{self.item_id}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def roll_type_pretty
|
||||||
|
case self.roll_type
|
||||||
|
when "mainspec"
|
||||||
|
"Main Spec"
|
||||||
|
when "offspec"
|
||||||
|
"Offspec"
|
||||||
|
when "minor"
|
||||||
|
"Minor Upgrade"
|
||||||
|
when "transmog"
|
||||||
|
"Transmog"
|
||||||
|
else
|
||||||
|
"Unknown"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def date
|
||||||
|
self.timestamp&.strftime("%m/%d/%Y")
|
||||||
|
end
|
||||||
|
end
|
@ -5,6 +5,9 @@ class Player < ApplicationRecord
|
|||||||
# A Player can have multiple alts
|
# A Player can have multiple alts
|
||||||
has_many :alternate_players, class_name: "Player", foreign_key: "main_player_id"
|
has_many :alternate_players, class_name: "Player", foreign_key: "main_player_id"
|
||||||
|
|
||||||
|
# A Player can have many loots
|
||||||
|
has_many :loots
|
||||||
|
|
||||||
validate :no_circular_references
|
validate :no_circular_references
|
||||||
|
|
||||||
def total_wins
|
def total_wins
|
||||||
@ -35,6 +38,10 @@ class Player < ApplicationRecord
|
|||||||
self.main_player
|
self.main_player
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_alts?
|
||||||
|
self.alternate_players.count > 0
|
||||||
|
end
|
||||||
|
|
||||||
def main_name
|
def main_name
|
||||||
if alt?
|
if alt?
|
||||||
self.main_player.name
|
self.main_player.name
|
||||||
@ -46,4 +53,25 @@ class Player < ApplicationRecord
|
|||||||
errors.add(:main_account, "circular reference")
|
errors.add(:main_account, "circular reference")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_loot
|
||||||
|
loot = Loot.where(player_id: self.id)
|
||||||
|
self.alternate_players.each do |alt|
|
||||||
|
loot << Loot.where(player_id: alt.id)
|
||||||
|
end
|
||||||
|
loot
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_loot_with_roll(roll)
|
||||||
|
ids = [self.id] + self.alternate_players.pluck(:id)
|
||||||
|
Loot.where(player_id: ids, roll_type: roll)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_loot_count
|
||||||
|
get_loot.size
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_loot_count_with_roll(roll)
|
||||||
|
get_loot_with_roll(roll).size
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -40,6 +40,18 @@
|
|||||||
|
|
||||||
<%= submit_tag "Set Alt", id: "set-alt-button" %>
|
<%= submit_tag "Set Alt", id: "set-alt-button" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% form_with(url: "/admin/set_lootban", method: :post, local: true) do %>
|
||||||
|
<h2>Set Lootban</h2>
|
||||||
|
<label for="lootban-input">Set Lootban: </label>
|
||||||
|
<input id="lootban-input" type="text">
|
||||||
|
<%= submit_tag "Set Lootban", id: "set-lootban-button" %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% form_with(url: "/admin/delete_lootban", method: :post, local: true) do %>
|
||||||
|
<%= submit_tag "Clear Lootban", id: "clear-lootban-button" %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<a href="/">Leaderboard</a>
|
<a href="/">Leaderboard</a>
|
||||||
<a href="/admin/destroy">Logout</a>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
27
app/views/loot/index.html.erb
Normal file
27
app/views/loot/index.html.erb
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<h1>Seasonal Loot Distribution</h1>
|
||||||
|
|
||||||
|
<% if @players.any? %>
|
||||||
|
<div class="wrapper">
|
||||||
|
<div class="table">
|
||||||
|
<div class="row header">
|
||||||
|
<div class="cell">Player</div>
|
||||||
|
<div class="cell">Main Spec</div>
|
||||||
|
<div class="cell">Minor Upgrade</div>
|
||||||
|
<div class="cell">Offspec</div>
|
||||||
|
<div class="cell">Transmog</div>
|
||||||
|
</div>
|
||||||
|
<% @players.each do |player| %>
|
||||||
|
<div class="row">
|
||||||
|
<div class="cell" data-title="Player"><%= player[0] %></div>
|
||||||
|
<div class="cell" data-title="Main Spec"><%= player[1]%></div>
|
||||||
|
<div class="cell" data-title="Minor Upgrade"><%= player[2]%></div>
|
||||||
|
<div class="cell" data-title="Offspec"><%= player[3] %></div>
|
||||||
|
<div class="cell" data-title="Transmog"><%= player[4] %></div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<a href="/loot/list">Loot List</a>
|
||||||
|
</div>
|
||||||
|
<% else %>
|
||||||
|
<h1>No loot records exist</h1>
|
||||||
|
<% end %>
|
25
app/views/loot/list.html.erb
Normal file
25
app/views/loot/list.html.erb
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<h1>Seasonal Loot List</h1>
|
||||||
|
|
||||||
|
<% if @loot.any? %>
|
||||||
|
<div class="wrapper">
|
||||||
|
<div class="table">
|
||||||
|
<div class="row header">
|
||||||
|
<div class="cell">Date</div>
|
||||||
|
<div class="cell">Player</div>
|
||||||
|
<div class="cell">Item</div>
|
||||||
|
<div class="cell">Roll Type</div>
|
||||||
|
</div>
|
||||||
|
<% @loot.each do |l| %>
|
||||||
|
<div class="row">
|
||||||
|
<div class="cell" data-title="Date"><%= l.date %></div>
|
||||||
|
<div class="cell" data-title="Player"><%= l.player_name_with_alt %></div>
|
||||||
|
<div class="cell" data-title="Item"><%= link_to l.item_name, l.wowhead, target: "_blank", rel: "nofollow" %></div>
|
||||||
|
<div class="cell" data-title="Roll Type"><%= l.roll_type_pretty %></div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<a href="/loot">Loot Distribution</a>
|
||||||
|
</div>
|
||||||
|
<% else %>
|
||||||
|
<h1>No loot records exist</h1>
|
||||||
|
<% end %>
|
@ -24,9 +24,9 @@ Rails.application.routes.draw do
|
|||||||
match "discord" => redirect("https://discord.gg/hQShdPMy7p"), via: [ :get ]
|
match "discord" => redirect("https://discord.gg/hQShdPMy7p"), via: [ :get ]
|
||||||
|
|
||||||
# Bot
|
# Bot
|
||||||
get "bot/players" => "bot#players"
|
get "bot/leaderboard" => "bot#leaderboard"
|
||||||
get "bot/player/:id" => "bot#player_name"
|
get "bot/lords" => "bot#lords"
|
||||||
get "bot/summary" => "bot#summary"
|
get "bot/weekly" => "bot#weekly"
|
||||||
|
|
||||||
# Admin
|
# Admin
|
||||||
get "admin", to: "admin#index"
|
get "admin", to: "admin#index"
|
||||||
@ -35,4 +35,11 @@ Rails.application.routes.draw do
|
|||||||
get "admin/login", to: "admin#login"
|
get "admin/login", to: "admin#login"
|
||||||
post "admin/login_submit", to: "admin#login_submit"
|
post "admin/login_submit", to: "admin#login_submit"
|
||||||
get "admin/destroy", to: "admin#destroy"
|
get "admin/destroy", to: "admin#destroy"
|
||||||
|
post "admin/set_lootban", to: "admin#set_lootban"
|
||||||
|
post "admin/delete_lootban", to: "admin#clear_lootban"
|
||||||
|
|
||||||
|
# Loot
|
||||||
|
resources :loot, only: [ :create ], defaults: { format: :json }
|
||||||
|
get "loot", to: "loot#index"
|
||||||
|
get "loot/list", to: "loot#list"
|
||||||
end
|
end
|
||||||
|
13
db/migrate/20250310212905_create_loots.rb
Normal file
13
db/migrate/20250310212905_create_loots.rb
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
class CreateLoots < ActiveRecord::Migration[8.0]
|
||||||
|
def change
|
||||||
|
create_table :loots do |t|
|
||||||
|
t.integer :item_id
|
||||||
|
t.datetime :timestamp
|
||||||
|
t.string :item_name
|
||||||
|
t.string :roll_type
|
||||||
|
t.references :player, null: false, foreign_key: true
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
15
db/schema.rb
generated
15
db/schema.rb
generated
@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[8.0].define(version: 2025_02_27_233421) do
|
ActiveRecord::Schema[8.0].define(version: 2025_03_10_212905) do
|
||||||
create_table "api_keys", force: :cascade do |t|
|
create_table "api_keys", force: :cascade do |t|
|
||||||
t.string "key"
|
t.string "key"
|
||||||
t.string "client"
|
t.string "client"
|
||||||
@ -38,6 +38,17 @@ ActiveRecord::Schema[8.0].define(version: 2025_02_27_233421) do
|
|||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "loots", force: :cascade do |t|
|
||||||
|
t.integer "item_id"
|
||||||
|
t.datetime "timestamp"
|
||||||
|
t.string "item_name"
|
||||||
|
t.string "roll_type"
|
||||||
|
t.integer "player_id", null: false
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["player_id"], name: "index_loots_on_player_id"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "players", force: :cascade do |t|
|
create_table "players", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.integer "wins"
|
t.integer "wins"
|
||||||
@ -48,4 +59,6 @@ ActiveRecord::Schema[8.0].define(version: 2025_02_27_233421) do
|
|||||||
t.integer "main_player_id"
|
t.integer "main_player_id"
|
||||||
t.index ["main_player_id"], name: "index_players_on_main_player_id"
|
t.index ["main_player_id"], name: "index_players_on_main_player_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_foreign_key "loots", "players"
|
||||||
end
|
end
|
||||||
|
1
db/seeds.rb
Normal file
1
db/seeds.rb
Normal file
@ -0,0 +1 @@
|
|||||||
|
ApiKey.create(client: "test", key: "12345")
|
7
test/controllers/loot_controller_test.rb
Normal file
7
test/controllers/loot_controller_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class LootControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
13
test/fixtures/loots.yml
vendored
Normal file
13
test/fixtures/loots.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
itemid: 1
|
||||||
|
timestamp: 2025-03-10 14:29:05
|
||||||
|
itemname: MyString
|
||||||
|
player: one
|
||||||
|
|
||||||
|
two:
|
||||||
|
itemid: 1
|
||||||
|
timestamp: 2025-03-10 14:29:05
|
||||||
|
itemname: MyString
|
||||||
|
player: two
|
7
test/models/loot_test.rb
Normal file
7
test/models/loot_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class LootTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user