Skip to content

mikuta0407/kuchihira-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kuchihira-bot

ja: 「中村繪里子・吉田尚記の本格雑談くちをひらく」の更新通知を Twitter (@kuchihira_bot, 公黙認) と Bluesky (@kuchihira-bot.bsky.social, 非公式)に投稿するBotプログラム。このボットは RSS の更新内容を Twitter に投稿できます。基本的な RSS フィード形式であれば他のポッドキャストにも利用可能です。

en: A bot program that posts "中村繪里子・吉田尚記の本格雑談くちをひらく" update notifications to Twitter (@kuchihira_bot, semi-official) and Bluesky (@kuchihira-bot.bsky.social, unofficial) This bot can post RSS updates to Twitter. It works with standard RSS feeds and can be used for other podcasts as well.

setup

  1. git clone or go install

    git clone https://github.com/mikuta0407/kuchihira-bot.git
    cd kuchihira-bot
    make build

    or

    mkdir kuchihira-bot
    cd kuchihira-bot
    go install github.com/mikuta0407/kuchihira-bot@latest
  2. make config and data directory

    mkdir ./_config
    mkdir ./_data
  3. create _config/config-discord.json

    {
        "username":"くちをひらくBot",
        "avatar_url":"",
        "url":"https://discord.com/api/webhooks/..."
    }
  4. create _config/config-twtr.json

    {
        "apikey":"hogeApiKey",
        "apikeysec":"hogeApiKeySecret",
        "oauthtoken":"hogeOAuthToken",
        "oauthtokensec":"hogeOAuthTokenSecret"
    }
  5. create _config/config-kuchihira.json

    {
        "hashtag":"#くちをひらく",
        "rss":"https://www.omnycontent.com/d/playlist/67122501-9b17-4d77-84bd-a93d00dc791e/bf2b4e95-c669-4e1c-abcf-a98c00a5f513/b923e360-dc05-438d-be85-a98c00a5f517/podcast.rss",
        "omnyfm":"https://omny.fm/shows/kuchiwohiraku/",
        "voicy":"https://voicy.jp/channel/584",
        "mentions":[
            "@yoshidahisanori",
            "@eriko_co_log",
            "@kuchiwohiraku"
        ]
    }
  6. generate _config/config-bsky.json

    ./kuchihira-bot login -u handle.example.net -p yourpassword -s host(optional)

    config-bsky.json is generated in _config. Auth data is generated by first post in _config/<handle>.auth

usage

one-time exec

./kuchihira-bot post

daemon mode

./kuchihira-bot daemon

dryrun mode (no actual post. only stdout)

./kuchihira-bot post --debug
./kuchihira-bot daemon --debug

cron example (for one-time exec mode)

Episode updates are usually done between 17:00 (JST) and 17:02 (JST), so start fetching RSS updates every 20 seconds starting at 16:50 (JST).

50 16 * * * /path/to/kuchihira-bot/kuchihira-bot post

systemd service example (for daemon mode)

Please change binary path, user and group!

[Unit]
Description=Kuchiwohiraku Bot

[Service]
ExecStart=/path/to/kuchihira-bot/kuchihira-bot daemon
Restart=always
Type=simple
User=hogeuser
Group=hogeuser

[Install]
WantedBy=multi-user.target

For development

ja:

バイナリの位置に対する相対パスでコンフィグファイルやデータを見に行くため、go runで実行しないでください。/tmp以下の_configを読みに行こうとして動かなくなります。 動作テストを行う際は、 単発実行の場合は

make debug

デーモンモードの場合は

make daemondebug

を使用するなど、makeコマンドを使用してください。この2つのmakeコマンドは、カレントディレクトリにkuchihira-bot_debugとしてバイナリファイルを出力し、--debugオプションを付加させた状態で起動します。 (internal/config/config.go内のGetConfigDir()でコメントアウトを入れ替えれば、シェルのカレントディレクトリを見に行くようにはなりますが、おすすめはしません。)

en:

Do not run with go run as it retrieves configuration files and data relative to the binary location. If you start it with go run, it will try to read _config under /tmp and will not work. Please use the following make command when testing the operation. For one-shot execution

make debug

In daemon mode

make daemondebug

These two make commands output a binary file as kuchihira-bot_debug in the current directory and start with the --debug option added. (If you replace the comment out with GetConfigDir() in internal/config/config.go, you will be able to see the current directory of the shell, but I do not recommend it.)

License

MIT

Note

Digression(余談)

  • 元々、 https://gist.github.com/mikuta0407/955808cff9eb725a313a17286c43b558 でも公開しているPHP製プログラムとして2023年5月から稼働させていました。Bluesky投稿を勝手に実装してみるにあたり、PHPでBlueskyのリンク付き投稿の実装がかなり辛かったため、既にmattn氏によって作られていたリンク付き投稿のコードを利用するために、Goを用いて最初から作り直してみました。

    正直なところ、行数は増え、cobraによるCLIコマンドを(blueskyログインのためだけに)足したため、プログラムの規模に対して内容が過剰になってしまいました。

    書き直したメリットとしては、

    • Goによってシングルバイナリになったこと
    • すべての変数を外に出したこと(PHPで作ったときは(面倒くさくて)ハードコーディングしていた部分を外に出しながら作った)
      • 逆に配置時面倒くさくなったとも言える
    • templatesを使ってパワーな文字列結合をしなくなったこと

    くらいでしょうか。

    このプログラムは利用者が作者自身しかいない気がしますが、一応制作物としてここに置いておきます。くちをひらかーの皆様、もしツッコミどころや鉞組があればお待ちしています。

About

くちをひらくBot (For Twitter + Bluesky)

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors