Skip to content

Instantly share code, notes, and snippets.

@kkosuge
Created July 24, 2017 03:19
Show Gist options
  • Save kkosuge/af5894ced5cc1ac38bfd2687cad7c780 to your computer and use it in GitHub Desktop.
Save kkosuge/af5894ced5cc1ac38bfd2687cad7c780 to your computer and use it in GitHub Desktop.
Slack のステータス変更スクリプト
SLACK_TOKEN=lgsolashdgoalisdhgaldgahksdg
require 'json'
Bundler.require
Dotenv.load
emoji = ARGV[0]
text = ARGV[1]
def notify(title, message)
`osascript -e 'display notification "#{message}" with title "#{title}"'`
end
def set_status(status_emoji, status_text)
params = {
token: ENV['SLACK_TOKEN'],
profile: {
status_emoji: status_emoji,
status_text: status_text
}.to_json
}
res = Faraday.post('https://slack.com/api/users.profile.set', params)
res.success? && JSON.parse(res.body)['ok']
rescue => e
false
end
if set_status(emoji, text)
notify("#{emoji} #{text}", 'Slack の絵文字ステータスを更新しました')
else
notify('Failed to update emoji status', '')
end
source 'https://rubygems.org'
gem 'dotenv'
gem 'faraday'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment