README changes, create thread on join, update package-lock #21
@ -36,7 +36,10 @@ mix deps.compile
|
|||||||
# Install frontend stuff
|
# Install frontend stuff
|
||||||
cd front
|
cd front
|
||||||
npm install
|
npm install
|
||||||
npm start
|
|
||||||
|
# Generate SSH keys
|
||||||
|
cd ../priv
|
||||||
|
./make_keys.sh
|
||||||
|
|
||||||
# Run the frontend and server concurrently!
|
# Run the frontend and server concurrently!
|
||||||
cd ..
|
cd ..
|
||||||
|
@ -26,6 +26,7 @@ config :chessh, Web,
|
|||||||
config :chessh, DiscordNotifications,
|
config :chessh, DiscordNotifications,
|
||||||
game_move_notif_delay_ms: 0,
|
game_move_notif_delay_ms: 0,
|
||||||
game_created_notif_delay_ms: 15_000,
|
game_created_notif_delay_ms: 15_000,
|
||||||
|
game_player_joined_notif_delay_ms: 0,
|
||||||
reschedule_delay: 3 * 1000
|
reschedule_delay: 3 * 1000
|
||||||
|
|
||||||
config :joken, default_signer: "secret"
|
config :joken, default_signer: "secret"
|
||||||
|
8
front/package-lock.json
generated
8
front/package-lock.json
generated
@ -11,6 +11,7 @@
|
|||||||
"@testing-library/jest-dom": "^5.16.5",
|
"@testing-library/jest-dom": "^5.16.5",
|
||||||
"@testing-library/react": "^13.4.0",
|
"@testing-library/react": "^13.4.0",
|
||||||
"@testing-library/user-event": "^13.5.0",
|
"@testing-library/user-event": "^13.5.0",
|
||||||
|
"asciinema-player": "^3.0.1",
|
||||||
"http-proxy-middleware": "^2.0.6",
|
"http-proxy-middleware": "^2.0.6",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-code-blocks": "^0.0.9-0",
|
"react-code-blocks": "^0.0.9-0",
|
||||||
@ -19,9 +20,6 @@
|
|||||||
"react-router-dom": "^6.6.2",
|
"react-router-dom": "^6.6.2",
|
||||||
"react-scripts": "5.0.1",
|
"react-scripts": "5.0.1",
|
||||||
"web-vitals": "^2.1.4"
|
"web-vitals": "^2.1.4"
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"asciinema-player": "^3.0.1"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@adobe/css-tools": {
|
"node_modules/@adobe/css-tools": {
|
||||||
@ -4747,7 +4745,6 @@
|
|||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/asciinema-player/-/asciinema-player-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/asciinema-player/-/asciinema-player-3.0.1.tgz",
|
||||||
"integrity": "sha512-plm/C/MhOtZWysrfcT/rzxOuu8vxvvDSvF50pqZS6KpJUDmATedAhO54zktbE/g7RiaaYfzgX8xjRhlQdgISwA==",
|
"integrity": "sha512-plm/C/MhOtZWysrfcT/rzxOuu8vxvvDSvF50pqZS6KpJUDmATedAhO54zktbE/g7RiaaYfzgX8xjRhlQdgISwA==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.15.4",
|
"@babel/runtime": "^7.15.4",
|
||||||
"solid-js": "^1.3.0"
|
"solid-js": "^1.3.0"
|
||||||
@ -15017,7 +15014,6 @@
|
|||||||
"version": "1.6.9",
|
"version": "1.6.9",
|
||||||
"resolved": "https://registry.npmjs.org/solid-js/-/solid-js-1.6.9.tgz",
|
"resolved": "https://registry.npmjs.org/solid-js/-/solid-js-1.6.9.tgz",
|
||||||
"integrity": "sha512-kV3fMmm+1C2J95c8eDOPKGfZHnuAkHUBLG4hX1Xu08bXeAIPqmxuz/QdH3B8SIdTp3EatBVIyA6RCes3hrGzpg==",
|
"integrity": "sha512-kV3fMmm+1C2J95c8eDOPKGfZHnuAkHUBLG4hX1Xu08bXeAIPqmxuz/QdH3B8SIdTp3EatBVIyA6RCes3hrGzpg==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"csstype": "^3.1.0"
|
"csstype": "^3.1.0"
|
||||||
}
|
}
|
||||||
@ -20496,7 +20492,6 @@
|
|||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/asciinema-player/-/asciinema-player-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/asciinema-player/-/asciinema-player-3.0.1.tgz",
|
||||||
"integrity": "sha512-plm/C/MhOtZWysrfcT/rzxOuu8vxvvDSvF50pqZS6KpJUDmATedAhO54zktbE/g7RiaaYfzgX8xjRhlQdgISwA==",
|
"integrity": "sha512-plm/C/MhOtZWysrfcT/rzxOuu8vxvvDSvF50pqZS6KpJUDmATedAhO54zktbE/g7RiaaYfzgX8xjRhlQdgISwA==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"@babel/runtime": "^7.15.4",
|
"@babel/runtime": "^7.15.4",
|
||||||
"solid-js": "^1.3.0"
|
"solid-js": "^1.3.0"
|
||||||
@ -27928,7 +27923,6 @@
|
|||||||
"version": "1.6.9",
|
"version": "1.6.9",
|
||||||
"resolved": "https://registry.npmjs.org/solid-js/-/solid-js-1.6.9.tgz",
|
"resolved": "https://registry.npmjs.org/solid-js/-/solid-js-1.6.9.tgz",
|
||||||
"integrity": "sha512-kV3fMmm+1C2J95c8eDOPKGfZHnuAkHUBLG4hX1Xu08bXeAIPqmxuz/QdH3B8SIdTp3EatBVIyA6RCes3hrGzpg==",
|
"integrity": "sha512-kV3fMmm+1C2J95c8eDOPKGfZHnuAkHUBLG4hX1Xu08bXeAIPqmxuz/QdH3B8SIdTp3EatBVIyA6RCes3hrGzpg==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"csstype": "^3.1.0"
|
"csstype": "^3.1.0"
|
||||||
}
|
}
|
||||||
|
@ -54,11 +54,30 @@ defmodule Chessh.DiscordNotifier do
|
|||||||
{:noreply, state}
|
{:noreply, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp send_notification({:player_joined, game_id}) do
|
||||||
|
case Repo.get(Game, game_id) |> Repo.preload([:dark_player, :light_player]) do
|
||||||
|
%Game{
|
||||||
|
status: :continue,
|
||||||
|
dark_player: %Player{discord_id: dark_player_discord_id},
|
||||||
|
light_player: %Player{discord_id: light_player_discord_id}
|
||||||
|
} = game ->
|
||||||
|
game = maybe_put_new_thread_on_game(game)
|
||||||
|
|
||||||
|
post_discord(
|
||||||
|
game.discord_thread_id,
|
||||||
|
%{
|
||||||
|
content:
|
||||||
|
"Everyone (<@#{dark_player_discord_id}> as the dark pieces, <@#{light_player_discord_id}> as light) has joined! Play chess!"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp send_notification({:move_reminder, game_id}) do
|
defp send_notification({:move_reminder, game_id}) do
|
||||||
[min_delta_t, remind_move_channel_id] =
|
min_delta_t = Application.get_env(:chessh, DiscordNotifications)[:game_move_notif_delay_ms]
|
||||||
Application.get_env(:chessh, DiscordNotifications)
|
|
||||||
|> Keyword.take([:game_move_notif_delay_ms, :remind_move_channel_id])
|
|
||||||
|> Keyword.values()
|
|
||||||
|
|
||||||
case Repo.get(Game, game_id) |> Repo.preload([:dark_player, :light_player]) do
|
case Repo.get(Game, game_id) |> Repo.preload([:dark_player, :light_player]) do
|
||||||
%Game{
|
%Game{
|
||||||
@ -68,23 +87,10 @@ defmodule Chessh.DiscordNotifier do
|
|||||||
last_move: last_move,
|
last_move: last_move,
|
||||||
updated_at: last_updated,
|
updated_at: last_updated,
|
||||||
moves: move_count,
|
moves: move_count,
|
||||||
status: :continue,
|
status: :continue
|
||||||
discord_thread_id: discord_thread_id
|
|
||||||
} = game ->
|
} = game ->
|
||||||
delta_t = NaiveDateTime.diff(NaiveDateTime.utc_now(), last_updated, :millisecond)
|
delta_t = NaiveDateTime.diff(NaiveDateTime.utc_now(), last_updated, :millisecond)
|
||||||
|
game = maybe_put_new_thread_on_game(game)
|
||||||
game =
|
|
||||||
if is_nil(discord_thread_id) do
|
|
||||||
{:ok, game} =
|
|
||||||
Game.changeset(game, %{
|
|
||||||
discord_thread_id: make_private_discord_thread_id(remind_move_channel_id, game)
|
|
||||||
})
|
|
||||||
|> Repo.update()
|
|
||||||
|
|
||||||
game
|
|
||||||
else
|
|
||||||
game
|
|
||||||
end
|
|
||||||
|
|
||||||
if delta_t >= min_delta_t do
|
if delta_t >= min_delta_t do
|
||||||
post_discord(
|
post_discord(
|
||||||
@ -233,4 +239,21 @@ defmodule Chessh.DiscordNotifier do
|
|||||||
bot_token = Application.get_env(:chessh, DiscordNotifications)[:discord_bot_token]
|
bot_token = Application.get_env(:chessh, DiscordNotifications)[:discord_bot_token]
|
||||||
{'Authorization', 'Bot #{bot_token}'}
|
{'Authorization', 'Bot #{bot_token}'}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp maybe_put_new_thread_on_game(%Game{discord_thread_id: discord_thread_id} = game) do
|
||||||
|
remind_move_channel_id =
|
||||||
|
Application.get_env(:chessh, DiscordNotifications)[:remind_move_channel_id]
|
||||||
|
|
||||||
|
if is_nil(discord_thread_id) do
|
||||||
|
{:ok, game} =
|
||||||
|
Game.changeset(game, %{
|
||||||
|
discord_thread_id: make_private_discord_thread_id(remind_move_channel_id, game)
|
||||||
|
})
|
||||||
|
|> Repo.update()
|
||||||
|
|
||||||
|
game
|
||||||
|
else
|
||||||
|
game
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -32,7 +32,10 @@ defmodule Chessh.SSH.Client.Game do
|
|||||||
def init([
|
def init([
|
||||||
%State{
|
%State{
|
||||||
color: color,
|
color: color,
|
||||||
game: %Game{dark_player_id: dark_player_id, light_player_id: light_player_id},
|
game: %Game{
|
||||||
|
dark_player_id: dark_player_id,
|
||||||
|
light_player_id: light_player_id
|
||||||
|
},
|
||||||
player_session: %{player_id: player_id}
|
player_session: %{player_id: player_id}
|
||||||
} = state
|
} = state
|
||||||
| tail
|
| tail
|
||||||
@ -47,7 +50,6 @@ defmodule Chessh.SSH.Client.Game do
|
|||||||
else
|
else
|
||||||
case {is_nil(dark_player_id), is_nil(light_player_id)} do
|
case {is_nil(dark_player_id), is_nil(light_player_id)} do
|
||||||
{true, false} -> %State{state | color: :dark}
|
{true, false} -> %State{state | color: :dark}
|
||||||
{false, true} -> %State{state | color: :light}
|
|
||||||
{_, _} -> %State{state | color: :light}
|
{_, _} -> %State{state | color: :light}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -210,6 +212,12 @@ defmodule Chessh.SSH.Client.Game do
|
|||||||
:player_joined,
|
:player_joined,
|
||||||
%State{client_pid: client_pid, game: %Game{id: game_id}} = state
|
%State{client_pid: client_pid, game: %Game{id: game_id}} = state
|
||||||
) do
|
) do
|
||||||
|
GenServer.cast(
|
||||||
|
:discord_notifier,
|
||||||
|
{:schedule_notification, {:player_joined, game_id},
|
||||||
|
Application.get_env(:chessh, DiscordNotifications)[:game_player_joined_notif_delay_ms]}
|
||||||
|
)
|
||||||
|
|
||||||
game = Repo.get(Game, game_id) |> Repo.preload([:light_player, :dark_player])
|
game = Repo.get(Game, game_id) |> Repo.preload([:light_player, :dark_player])
|
||||||
new_state = %State{state | game: game}
|
new_state = %State{state | game: game}
|
||||||
send(client_pid, {:send_to_ssh, Renderer.render_board_state(new_state)})
|
send(client_pid, {:send_to_ssh, Renderer.render_board_state(new_state)})
|
||||||
|
Loading…
Reference in New Issue
Block a user