-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const SCOREBOARD_API = "https://boundvariable.space/scoreboard"; | ||
const DISCORD_WEBHOOK_URL = process.env.DISCORD_WEBHOOK_URL; | ||
const TEAM_NAME = "Maximum"; | ||
|
||
async function postToDiscord() { | ||
try { | ||
const response = await fetch(SCOREBOARD_API); | ||
const data = await response.json(); | ||
|
||
// dataを構造体に変換 | ||
const formattedData = data.rows.map((row) => { | ||
const columns = data.columns; | ||
const obj = {}; | ||
columns.forEach((column, index) => { | ||
obj[column] = row.values[index]; | ||
}); | ||
return obj; | ||
}); | ||
|
||
// dataを#順にソート | ||
formattedData.sort((a, b) => a["#"] - b["#"]); | ||
|
||
// 上位10チームのみ抽出 | ||
const top = formattedData.filter((row) => row["#"] <= 10).slice(0, 10); | ||
|
||
// top10に自チームが含まれているか確認 | ||
const isInTop10 = top.some((row) => row.team === TEAM_NAME); | ||
|
||
// メッセージ作成、自分のチームがあれば強調 | ||
let message = ` | ||
## Scoreboard | ||
time: ${new Date().toLocaleString("ja-JP", { timeZone: "Asia/Tokyo" })} | ||
=== Top 10 === | ||
`.trim(); | ||
message += "\n"; | ||
message += top | ||
.map((row) => { | ||
const rank = row["#"]; | ||
const team = row.team; | ||
const isUs = row.team === TEAM_NAME; | ||
return `${isUs ? "**" : ""}${rank}\\. ${team}${isUs ? "**" : ""}`; | ||
}) | ||
.join("\n"); | ||
|
||
// 自分のチームが上位10に含まれていない場合はメッセージに追加 | ||
if (!isInTop10) { | ||
const rank = formattedData.find((row) => row.team === TEAM_NAME)["#"]; | ||
message += `\n~ ~ ~ ~ ~ ~\n**${rank}\\. ${TEAM_NAME}**`; | ||
} | ||
|
||
console.log(message); | ||
|
||
const res = await fetch(DISCORD_WEBHOOK_URL, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ content: message }), | ||
}); | ||
|
||
if (!res.ok) { | ||
console.error(res); | ||
throw new Error(`Failed to post to Discord: ${res.statusText}`); | ||
} | ||
|
||
console.log("Posted to Discord successfully."); | ||
} catch (error) { | ||
console.error("Error posting to Discord:", error); | ||
} | ||
} | ||
|
||
postToDiscord(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: ICFPC2024 Leaderboard Reporter | ||
|
||
on: | ||
schedule: | ||
- cron: "0 * * * *" | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Bun | ||
uses: oven-sh/setup-bun@v1 | ||
|
||
- name: Run | ||
run: bun run .github/scripts/reporter.ts | ||
env: | ||
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} |