Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/bots/asakatsu-bot/ @nakaterm
/bots/auto-moderator/ @chelproc @aster-void
/bots/gsc-report/ @na-trium-144
/bots/joji-bot/ @tknkaa
2 changes: 2 additions & 0 deletions bots/joji-bot/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WEBHOOK_URL=https://discord.com/api/webhooks/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
LAST_ID_FILE=~/run/last_video_id.txt
36 changes: 36 additions & 0 deletions bots/joji-bot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# dependencies (bun install)
node_modules

# output
out
dist
*.tgz

# code coverage
coverage
*.lcov

# logs
logs
_.log
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# caches
.eslintcache
.cache
*.tsbuildinfo

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store

last_video_id.txt
15 changes: 15 additions & 0 deletions bots/joji-bot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# joji-bot

To install dependencies:

```bash
bun install
```

To run:

```bash
bun run index.ts
```

This project was created using `bun init` in bun v1.3.5. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
39 changes: 39 additions & 0 deletions bots/joji-bot/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions bots/joji-bot/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Parser from 'rss-parser';

const WEBHOOK_URL = process.env.WEBHOOK_URL;
const CHANNEL_ID = 'UCGxzWLH1_1ABKKfSiy2WIAw';
const RSS_URL = `https://www.youtube.com/feeds/videos.xml?channel_id=${CHANNEL_ID}`;
const LAST_ID_FILE = process.env.LAST_ID_FILE || 'last_video_id.txt';

async function main() {
const parser = new Parser();
const response = await fetch(RSS_URL);
const feedText = await response.text();
const feed = await parser.parseString(feedText);
if (!feed.items || feed.items.length === 0) {
console.log('No entries found in RSS feed');
return;
}

const latestVideo = feed.items[0];
const latestId = latestVideo.id?.split(':').pop();
const videoUrl = latestVideo.link;
const videoTitle = latestVideo.title;
console.log(`Latest video: ${videoTitle} (ID: ${latestId})`);

let lastId = '';
try {
lastId = await Bun.file(LAST_ID_FILE).text();
} catch {}
if (lastId === latestId) {
console.log(`No new video (last ID: ${lastId})`);
return;
}

const message = {
content: `**${videoTitle}**\nNew video uploaded!\n${videoUrl}`
};
const res = await fetch(WEBHOOK_URL!, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(message)
});
console.log(`Discord response: ${res.status}`);

if (res.status === 204) {
await Bun.write(LAST_ID_FILE, latestId!);
console.log('Notification sent successfully!');
} else {
const errorText = await res.text();
console.log(`Failed to send notification: ${errorText}`);
}
}

main()

15 changes: 15 additions & 0 deletions bots/joji-bot/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "joji-bot",
"module": "index.ts",
"type": "module",
"private": true,
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5"
},
"dependencies": {
"rss-parser": "^3.13.0"
}
}
5 changes: 5 additions & 0 deletions bots/joji-bot/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail

bun install --frozen-lockfile
bun --env-file=.env run index.ts
29 changes: 29 additions & 0 deletions bots/joji-bot/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
// Environment setup & latest features
"lib": ["ESNext"],
"target": "ESNext",
"module": "Preserve",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
7 changes: 7 additions & 0 deletions rollcron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ jobs:
env_file: ~/run/discord-bots/asakatsu-bot/env
log: ~/run/discord-bots/asakatsu-bot/log

joji-bot:
schedule: "7pm"
working_dir: bots/joji-bot
run: ./run.sh
env_file: ~/run/discord-bots/joji-bot/env
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここでLAST_ID_FILE を ~/run 以下に指定すると良さそう (env.LAST_ID_FILE で)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.env にこんな感じで書くってこと?

LAST_ID_FILE=~/run/last_video_id.txt

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

それでもいいし、 YAML の env フィールドでも指定できる

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど、で merge していいの?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge してから、env に書き込むって感じかな?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

後、 gitignore に追加するだけだと既存のは消えないのでそれも消してね

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そうしたので、よさそうだったら merge してね

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

消えてなさそう

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

普通に。既存のものを消すのを忘れていた

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

よさそう

log: ~/run/discord-bots/joji-bot/log