-
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.
Merge pull request #273 from datafruits/daily-glorp-lottery
daily-glorp-lottery
- Loading branch information
Showing
4 changed files
with
48 additions
and
1 deletion.
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
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
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,36 @@ | ||
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}!" | ||
end | ||
|
||
if prize | ||
# pick random winner | ||
winner = current_chat_users.sample | ||
if winner | ||
puts "the winner is: #{winner.username}" | ||
ExperiencePointAward.create! award_type: prize, user: winner, amount: rand(5) | ||
end | ||
end | ||
|
||
def current_chat_users | ||
sockets = redis.smembers "datafruits:chat:sockets" | ||
usernames = sockets.map { |s| return s.split(":").last } | ||
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