From 78b760f4099e230202b54c5ccbcf65cad1ed2b6d Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 15 Feb 2025 23:47:40 +0100 Subject: Send tournament ended notification. --- server.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'server.js') diff --git a/server.js b/server.js index 3faa6b0..1f3a745 100644 --- a/server.js +++ b/server.js @@ -2604,6 +2604,10 @@ function message_link(msg_id) { return SITE_URL + "/message/read/" + msg_id } +function tour_pool_link(pool_id) { + return SITE_URL + "/tm/pool/" + pool_id +} + function send_notification(user, link, message) { if (WEBHOOKS) { let webhook = SQL_SELECT_WEBHOOK_SEND.get(user.user_id) @@ -2638,6 +2642,10 @@ function send_play_notification(user, game_id, message) { send_notification(user, game_play_link(game_id, title_id, user), `${title_name} #${game_id} (${user.role}) - ${message}`) } +function send_tour_notification(user, pool_name, message) { + send_notification(user, tour_pool_link(pool_name), `${pool_name} - ${message}`) +} + function send_chat_activity_notification(game_id, p) { send_play_notification(p, game_id, "Chat activity") } @@ -3020,6 +3028,16 @@ const TM_SELECT_GAMES = SQL(` `) const TM_SELECT_WINNERS = SQL("select user_id from tm_winners where pool_id = ?").pluck() +const TM_SELECT_PLAYERS_IN_POOL = SQL(` + select + user_view.* + from + tm_rounds + join players using(game_id) + join user_view using(user_id) + group by + user_id +`) const TM_SELECT_PLAYERS_2P = SQL(` with @@ -3534,9 +3552,11 @@ function start_tournament_seed(seed_id, level) { function tm_reap_pools() { // reap pools that are finished (and promote winners) + // reap pools that are finished (and notify players) let ended = TM_SELECT_ENDED_POOLS.all() for (let item of ended) { console.log("TM POOL - END", item.pool_name) + SQL_BEGIN.run() try { TM_UPDATE_POOL_FINISHED.run(item.pool_id) @@ -3550,6 +3570,10 @@ function tm_reap_pools() { if (db.inTransaction) SQL_ROLLBACK.run() } + + let players = TM_SELECT_PLAYERS_IN_POOL.all(item.pool_id) + for (let user of players) + send_tour_notification(user, item.pool_name, "Finished") } } -- cgit v1.2.3