Skip to content

Commit

Permalink
Use next player name in Discord notifications (#850)
Browse files Browse the repository at this point in the history
Fixes #739
  • Loading branch information
Thrillberg authored Mar 9, 2024
1 parent 7b93997 commit e55aa3f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions app/channels/game_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,20 @@ def receive(data)
.perform_later(next_player.id, game.id)
end
# Send Discord notification
current_player_identifier = next_player_name
current_player_discord_id = next_player&.discord_id
if current_player_discord_id.present? && ENV["RAILS_ENV"] == "production"
if current_player_discord_id
current_player_identifier = "<@#{current_player_discord_id}>"
end
if ENV["RAILS_ENV"] == "production"
puts "Preparing to send notifyNextPlayer Discord notification"
DiscordTurnNotificationJob.set(wait: 5.minutes)
.perform_later(current_player_discord_id, next_player.id, game.id, game.name)
.perform_later(
current_player_identifier,
next_player.id,
game.id,
game.name
)
end

game.last_move.update(player_notified_at: Time.now)
Expand Down
6 changes: 3 additions & 3 deletions app/jobs/discord_turn_notification_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class DiscordTurnNotificationJob < ApplicationJob
queue_as :default

def perform(player_discord_id, player_id, game_id, game_name)
def perform(player_identifier, player_id, game_id, game_name)
player = User.find(player_id)
game = Game.find(game_id)
if game.current_player == player
Expand All @@ -10,7 +10,7 @@ def perform(player_discord_id, player_id, game_id, game_name)
Net::HTTP.post(
uri,
{
content: "<@#{player_discord_id}> it is your turn!",
content: "#{player_identifier} it is your turn!",
allowed_mentions: {parse: ["users"]},
embeds: [
title: game_name,
Expand All @@ -25,7 +25,7 @@ def perform(player_discord_id, player_id, game_id, game_name)
Net::HTTP.post(
uri,
{
content: "<@#{player_discord_id}> it is your turn!",
content: "#{player_identifier} it is your turn!",
allowed_mentions: {parse: ["users"]},
embeds: [
title: game_name,
Expand Down

0 comments on commit e55aa3f

Please sign in to comment.