-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaily_puzzle_job.rb
More file actions
56 lines (49 loc) · 1.22 KB
/
daily_puzzle_job.rb
File metadata and controls
56 lines (49 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class DailyPuzzleJob < ApplicationJob
queue_as :default
retry_on StandardError, attempts: 3
def perform
puzzle = Puzzle.approved.where(sent_at: nil).order("RANDOM()").first
return unless puzzle
Server.where(active: true).each do |server|
channel = server.channel
next unless channel
bot.send_message(
channel.channel_id,
"",
false,
puzzle_embed(puzzle),
nil,
nil,
nil,
puzzle_buttons(puzzle.id)
)
end
puzzle.update!(sent_at: Time.current, state: :archived)
end
private
def puzzle_embed(puzzle)
Discordrb::Webhooks::Embed.new(
title: "Puzzle Time! 🧩",
description: puzzle.question,
color: 0x3498db # Blue color
)
end
def puzzle_buttons(puzzle_id)
Discordrb::Webhooks::View.new do |view|
view.row do |row|
row.button(
style: :primary,
emoji: ENV["RUBY_EMOJI_ID"] || "🔴",
label: "Ruby",
custom_id: "ruby__#{puzzle_id}"
)
row.button(
style: :primary,
emoji: ENV["RAILS_EMOJI_ID"] || "🚂",
label: "Rails",
custom_id: "rails__#{puzzle_id}"
)
end
end
end
end