Created
September 2, 2019 07:13
-
-
Save sharl/872441fed0b8f010f06c4022d7a94965 to your computer and use it in GitHub Desktop.
DQ10の現在の職業とレベルをSlackのステータスに反映する
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
#!/bin/bash | |
# -*- coding: utf-8 -*- | |
# $HOME/.dqxpresence format | |
# { | |
# "slack_token": "xoxp-xxxx", | |
# "id": 667538238772, | |
# "icon_emoji": ":dot_slime:" | |
# } | |
# id は https://hiroba.dqx.jp/sc/character/${user_id} です。マイページ全体の公開設定が『制限なしで公開』になっている必要があります。 | |
slack_token=$(cat $HOME/.dqxpresence | jq -r .slack_token) | |
user_id=$(cat $HOME/.dqxpresence | jq -r .id) | |
icon_emoji=$(cat $HOME/.dqxpresence | jq -r .icon_emoji) | |
status=$(curl -s https://hiroba.dqx.jp/sc/character/${user_id} | tr -d "\r\n" | sed -e 's,.*<dt>職 業</dt>.*<dd>: \(.*\)</dd>.*<dt>レベル</dt>.*<dd>: \([0-9]*\)</dd>.*,\1\2\n,p;d') | |
json="$(jo profile=$(jo status_text="${status}" status_emoji=${icon_emoji} status_expiration=$(date +%s --date="1 hour")))" | |
curl -s -X POST -H 'Content-type: application/json; charset=utf-8' -H "Authorization: Bearer ${slack_token}" -d "${json}" https://slack.com/api/users.profile.set > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment