Module: ESM::Command::Server::Gamble::V1
- Defined in:
- lib/esm/command/server/gamble.rb
Instance Method Summary collapse
Instance Method Details
#on_execute ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/esm/command/server/gamble.rb', line 44 def on_execute return reply(send_stats) if arguments.amount.blank? || arguments.amount == "stats" check_for_connected_server! check_for_bad_amount! deliver!( function_name: "gamble", uid: current_user.steam_uid, amount: arguments.amount, id: current_user.discord_id, name: current_user.username ) end |
#on_response ⇒ Object
59 60 61 62 |
# File 'lib/esm/command/server/gamble.rb', line 59 def on_response update_stats send_results end |
#send_results ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/esm/command/server/gamble.rb', line 111 def send_results = ESM::Notification.build_random( community_id: target_community.id, type: @response.type, category: "gambling", serverid: target_server.server_id, servername: target_server.server_name, communityid: target_community.community_id, username: current_user.username, usertag: current_user.mention, amountchanged: @response.amount, amountgambled: arguments.amount, lockerbefore: @response.locker_before, lockerafter: @response.locker_after ) . = "Current Streak: #{gamble_stat.current_streak}" reply() end |
#update_stats ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/esm/command/server/gamble.rb', line 64 def update_stats # Ensure the streak is reset when switching between won/lost current_streak = if gamble_stat.last_action == @response.type gamble_stat.current_streak + 1 else 1 end case @response.type when "won" # Determine if we've broken our previous streak longest_win_streak = if current_streak > gamble_stat.longest_win_streak current_streak else gamble_stat.longest_win_streak end # Update the stats gamble_stat.update( total_wins: gamble_stat.total_wins + 1, total_poptabs_won: gamble_stat.total_poptabs_won + @response.amount.to_i, current_streak: current_streak, longest_win_streak: longest_win_streak, last_action: @response.type ) when "loss" # Determine if we've broken our previous streak longest_loss_streak = if current_streak > gamble_stat.longest_loss_streak current_streak else gamble_stat.longest_loss_streak end # Update the stats gamble_stat.update( total_losses: gamble_stat.total_losses + 1, total_poptabs_loss: gamble_stat.total_poptabs_loss + @response.amount.to_i, current_streak: current_streak, longest_loss_streak: longest_loss_streak, last_action: @response.type ) end end |