-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ad869e
commit 1bae54e
Showing
2 changed files
with
39 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
class DailyGlorpLottery | ||
include RedisConnection | ||
|
||
def draw! | ||
# 1 in 20 chance of getting a glop or glorp? | ||
chance = rand(100) | ||
prize = nil | ||
if chance <= 30 | ||
# congratulations, you've won :glorp: | ||
prize = :glorppy | ||
puts "today's prize is #{prize}!" | ||
elsif chance >= 80 | ||
# congratulations, you've won :glop: | ||
prize = :gloppy | ||
puts "today's prize is #{prize}!" | ||
else | ||
puts "no winner today!" | ||
end | ||
|
||
if prize | ||
# pick random winner | ||
winner_username = current_chat_users.sample | ||
winner = User.find_by(username: winner_username) | ||
if winner | ||
puts "the winner is: #{winner.username}" | ||
ExperiencePointAward.create! award_type: prize, user: winner, amount: rand(5) + 1 | ||
end | ||
end | ||
|
||
def current_chat_users | ||
sockets = redis.smembers "datafruits:chat:sockets" | ||
usernames = sockets.map { |s| s.split(":").last } | ||
return usernames.filter do |u| | ||
User.where(username: u).any? | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,7 @@ | ||
class DailyGlorpLotteryWorker < ActiveJob::Base | ||
include RedisConnection | ||
queue_as :default | ||
|
||
def perform | ||
# 1 in 20 chance of getting a glop or glorp? | ||
chance = rand(100) | ||
prize = nil | ||
if chance <= 30 | ||
# congratulations, you've won :glorp: | ||
prize = :glorppy | ||
puts "today's prize is #{prize}!" | ||
elsif chance >= 80 | ||
# congratulations, you've won :glop: | ||
prize = :gloppy | ||
puts "today's prize is #{prize}!" | ||
else | ||
puts "no winner today!" | ||
end | ||
|
||
if prize | ||
# pick random winner | ||
winner_username = current_chat_users.sample | ||
winner = User.find_by(username: winner_username) | ||
if winner | ||
puts "the winner is: #{winner.username}" | ||
ExperiencePointAward.create! award_type: prize, user: winner, amount: rand(5) + 1 | ||
end | ||
end | ||
|
||
def current_chat_users | ||
sockets = redis.smembers "datafruits:chat:sockets" | ||
usernames = sockets.map { |s| s.split(":").last } | ||
return usernames.filter do |u| | ||
User.where(username: u).any? | ||
end | ||
end | ||
DailyGlorpLottery.new.draw! | ||
end | ||
end |