Annict に記録したアニメの視聴記録(作品の視聴開始・終了のみ)を Discord の特定のチャンネルに転送します。
Discord bot の作成および投稿したいサーバーへの招待が必要です。
config
という名前のファイルに入っているダミーの文字列を置き換えて
- Annict のユーザー ID
- Annict のアクセストークン
- Discord bot のアクセストークン
- Discord チャンネルの ID
を設定します。
systemd timer を用いて定期的に実行します。
# /etc/systemd/system/annict-discord-bot.service
[Unit]
Description=forward activities recorded on Annict to Discord
[Service]
Type=simple
ExecStart=/path/to/annict-discord-bot/main.py
WorkingDirectory=/path/to/annict-discord-bot
[Install]
WantedBy=multi-user.target
# /etc/systemd/system/annict-discord-bot.timer
[Unit]
Description=run annict-discord-bot
[Timer]
OnCalendar=*-*-* *:00/20:00
Persistent=true
[Install]
WantedBy=timers.target
/path/to/annict-discord-bot
はリポジトリを clone したディレクトリに置き換えてください。
systemctl
コマンドで定期実行を有効化します。
# systemctl enable annict-discord-bot.service
# systemctl enable annict-discord-bot.timer
ログの確認は journalctl
コマンドで行います。
$ journalctl -xeu annict-discord-bot
一度投稿した内容は再投稿しないようになっています。そのため
$ ./main.py
$ ./main.py
とすると二度目の実行ではメッセージは投稿されません(実行すると実際に Discord チャンネルにメッセージが投稿される のでご注意ください)。
メッセージを投稿すること無く、現在までに Annict に記録してあるもののデータの取得を行って投稿済みの扱いにしたい
(今後新たに記録したもののみを Discord チャンネルに投稿したい)場合には dry
という引数をつけて実行します。
$ ./main.py dry