-
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
0 parents
commit fbc2c6f
Showing
2 changed files
with
81 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,58 @@ | ||
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 top10WithUs = formattedData.filter( | ||
(row) => row.team === TEAM_NAME || row["#"] <= 10 | ||
); | ||
|
||
// メッセージ作成、自分のチームを強調 | ||
const message = top10WithUs | ||
.map((row) => { | ||
const rank = row["#"]; | ||
const team = row.team; | ||
const isUs = row.team === TEAM_NAME; | ||
return `${isUs ? "**" : ""}${rank}. ${team}${isUs ? "**" : ""}`; | ||
}) | ||
.join("\n"); | ||
|
||
const now = new Date().toLocaleString("ja-JP", { | ||
timeZone: "Asia/Tokyo", | ||
}); | ||
|
||
await fetch(DISCORD_WEBHOOK_URL, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
content: `**Scoreboard**\n\`\`\`${message}\`\`\`\nLast updated: ${now}`, | ||
}), | ||
}); | ||
|
||
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 }} |