From fe5f5b77fcc3ef24516866561f9b54ac07663ad6 Mon Sep 17 00:00:00 2001 From: Simponic Date: Wed, 1 Feb 2023 14:57:14 -0700 Subject: Discord notifs (#14) * Add role id to config * Add discord notifications for games * Fix discord discriminant tests --- lib/chessh/ssh/client/game/game.ex | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'lib/chessh/ssh/client') diff --git a/lib/chessh/ssh/client/game/game.ex b/lib/chessh/ssh/client/game/game.ex index 4a79d05..fc48d6f 100644 --- a/lib/chessh/ssh/client/game/game.ex +++ b/lib/chessh/ssh/client/game/game.ex @@ -77,7 +77,7 @@ defmodule Chessh.SSH.Client.Game do ) do {:allow, _count} -> # Starting a new game - {:ok, %Game{} = game} = + {:ok, %Game{id: game_id} = game} = Game.changeset( %Game{}, Map.merge( @@ -92,6 +92,12 @@ defmodule Chessh.SSH.Client.Game do ) |> Repo.insert() + GenServer.cast( + :discord_notifier, + {:schedule_notification, {:game_created, game_id}, + Application.get_env(:chessh, DiscordNotifications)[:game_created_notif_delay_ms]} + ) + init([ %State{ state @@ -403,6 +409,12 @@ defmodule Chessh.SSH.Client.Game do :syn.publish(:games, {:game, game_id}, {:new_move, attempted_move}) + GenServer.cast( + :discord_notifier, + {:schedule_notification, {:move_reminder, game_id}, + Application.get_env(:chessh, DiscordNotifications)[:game_move_notif_delay_ms]} + ) + _ -> nil end -- cgit v1.2.3-70-g09d2