Created
February 18, 2015 16:21
-
-
Save muhh/ceea8459cae766e2cf2b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| # A simple status updater. Changes presence status on Sqwiggle and Slack. | |
| # Posts message to our Slack #company channel | |
| # | |
| # Author: Markus Heurung <markus@freistil.it> | |
| # | |
| # Copyright 2015 Markus Heurung | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| require 'optparse' | |
| require 'sqwiggle-ruby' | |
| require 'slack' | |
| options = {} | |
| option_parser = OptionParser.new do |opts| | |
| executable_name = File.split($0)[1] | |
| opts.banner = "Set your status on all our favorite conversation tools | |
| Usage: #{executable_name} -[a|b|o] [MESSAGE]" | |
| options[:new_status] = 'available' | |
| options[:new_status_message] = 'Available' | |
| opts.on('-b MESSAGE', '--busy MESSAGE', 'set user to busy with optional message') do |db_item| | |
| options[:new_status] = 'busy' | |
| options[:new_status_message] = db_item | |
| end | |
| opts.on('-a MESSAGE', '--available MESSAGE', 'set user to available with optional message') do |message| | |
| options[:new_status] = 'available' | |
| options[:new_status_message] = message | |
| end | |
| opts.on('-o', '--offline', 'set user to offline') do | |
| options[:new_status] = 'offline' | |
| end | |
| end | |
| option_parser.parse! | |
| SQWIGGLE_TOKEN = '' | |
| SQWIGGLE_ID = 7007 | |
| SLACK_TOKEN = '' | |
| SLACK_USERNAME = '' | |
| SLACK_CHANNEL = '#company' | |
| sqwiggle_client = Sqwiggle.client(SQWIGGLE_TOKEN) | |
| sqwiggle_user = sqwiggle_client.users.find SQWIGGLE_ID | |
| sqwiggle_user.status = options[:new_status] | |
| sqwiggle_user.message = options[:new_status_message] | |
| sqwiggle_user.save! | |
| Slack.configure do |config| | |
| config.token = SLACK_TOKEN | |
| end | |
| Slack.chat_postMessage(channel: SLACK_CHANNEL, | |
| username: SLACK_USERNAME, | |
| text: "I'm #{options[:new_status]} (#{options[:new_status_message]})" | |
| ) | |
| if(options[:new_status] == 'available') | |
| slack_status = 'auto' | |
| else | |
| slack_status = 'away' | |
| end | |
| Slack.users_setPresence(presence: slack_status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment