class Ruboty::Reinvite::Actions::Reinvite

Public Instance Methods

call() click to toggle source
# File lib/ruboty/reinvite/actions/reinvite.rb, line 6
def call
  message.reply(reinvite)
rescue => e
  message.reply("Error #{e.message}")
end

Private Instance Methods

channel_id(channel) click to toggle source
# File lib/ruboty/reinvite/actions/reinvite.rb, line 28
def channel_id(channel)
  response = ::Slack.channels_list
  validate_response(response)
  response["channels"].find{ |e|e["name"] == channel }["id"]
end
invite(option) click to toggle source
# File lib/ruboty/reinvite/actions/reinvite.rb, line 39
def invite(option)
  response = ::Slack.channels_invite(option)
  validate_response(response)
end
kick(option) click to toggle source
# File lib/ruboty/reinvite/actions/reinvite.rb, line 34
def kick(option)
  response = ::Slack.channels_kick(option)
  validate_response(response)
end
reinvite() click to toggle source
# File lib/ruboty/reinvite/actions/reinvite.rb, line 13
def reinvite
  ::Slack.configure { |config|config.token = ENV["SLACK_API_TOKEN"] }
  channel = message[:channel]
  option = { user: user_id, channel: channel_id(channel) }
  kick(option)
  invite(option)
  ":robot_face: success reinvite to #{channel}"
end
user_id() click to toggle source
# File lib/ruboty/reinvite/actions/reinvite.rb, line 22
def user_id
  response = ::Slack.users_list
  validate_response(response)
  response["members"].find{ |e|e["name"] == ENV["SLACK_USERNAME"] }["id"]
end
validate_response(response) click to toggle source
# File lib/ruboty/reinvite/actions/reinvite.rb, line 44
def validate_response(response)
  return if response["ok"]
  fail response["error"]
end