Skip to content

Instantly share code, notes, and snippets.

@sharl
Created September 2, 2019 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharl/872441fed0b8f010f06c4022d7a94965 to your computer and use it in GitHub Desktop.
Save sharl/872441fed0b8f010f06c4022d7a94965 to your computer and use it in GitHub Desktop.
DQ10の現在の職業とレベルをSlackのステータスに反映する
#!/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>:&nbsp;\(.*\)</dd>.*<dt>レベル</dt>.*<dd>:&nbsp;\([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