summaryrefslogtreecommitdiff
path: root/server.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2025-02-15 23:47:40 +0100
committerTor Andersson <tor@ccxvii.net>2025-02-23 12:56:08 +0100
commit78b760f4099e230202b54c5ccbcf65cad1ed2b6d (patch)
treeec5589411321bdce0bef96bc6fbe67ceddb3d09c /server.js
parent921947692a38d80e5cacaaca6b1ca01f920b28d5 (diff)
downloadserver-78b760f4099e230202b54c5ccbcf65cad1ed2b6d.tar.gz
Send tournament ended notification.
Diffstat (limited to 'server.js')
-rw-r--r--server.js24
1 files changed, 24 insertions, 0 deletions
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")
}
}