Skip to content

Commit

Permalink
Migrate app to granular scopes and events API.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Nov 22, 2020
1 parent 7d2517d commit 2a19607
Show file tree
Hide file tree
Showing 91 changed files with 391 additions and 1,120 deletions.
49 changes: 19 additions & 30 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,71 +1,60 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-11-15 22:07:57 UTC using RuboCop version 1.3.0.
# on 2020-11-22 17:19:23 UTC using RuboCop version 1.3.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
Bundler/OrderedGems:
Exclude:
- 'Gemfile'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: AllowAliasSyntax, AllowedMethods.
# AllowedMethods: alias_method, public, protected, private
Layout/EmptyLinesAroundAttributeAccessor:
# Offense count: 1
Lint/MissingSuper:
Exclude:
- 'slack-shellbot/models/current_directory_entry.rb'
- 'slack-shellbot/models/parent_directory_entry.rb'
- 'lib/commands/base.rb'

# Offense count: 8
Lint/MixedRegexpCaptureTypes:
Exclude:
- 'slack-shellbot/commands/cat.rb'
- 'slack-shellbot/commands/cd.rb'
- 'slack-shellbot/commands/echo.rb'
- 'slack-shellbot/commands/mkdir.rb'
- 'slack-shellbot/commands/rm.rb'
- 'slack-shellbot/commands/rmdir.rb'
- 'slack-shellbot/commands/touch.rb'
- 'slack-shellbot/commands/vi.rb'
- 'lib/commands/cat.rb'
- 'lib/commands/cd.rb'
- 'lib/commands/echo.rb'
- 'lib/commands/mkdir.rb'
- 'lib/commands/rm.rb'
- 'lib/commands/rmdir.rb'
- 'lib/commands/touch.rb'
- 'lib/commands/vi.rb'

# Offense count: 2
# Cop supports --auto-correct.
Lint/NonDeterministicRequireOrder:
Exclude:
- 'slack-shellbot.rb'
- 'app.rb'
- 'spec/spec_helper.rb'

# Offense count: 1
# Configuration parameters: AllowComments.
Lint/SuppressedException:
Exclude:
- 'slack-shellbot/models/vi_program.rb'

# Offense count: 1
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Naming/FileName:
Exclude:
- 'slack-shellbot.rb'
- 'lib/models/vi_program.rb'

# Offense count: 2
# Configuration parameters: ForbiddenDelimiters.
# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
Naming/HeredocDelimiterNaming:
Exclude:
- 'slack-shellbot/commands/help.rb'
- 'slack-shellbot/info.rb'
- 'lib/commands/help.rb'
- 'lib/info.rb'

# Offense count: 19
# Offense count: 17
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 163
Max: 150
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Changelog

* 2020/11/22. [#22](https://github.com/slack-ruby/slack-shellbot/pull/22): Migrate app to granular scopes and events API - [@dblock](https://github.com/dblock).
* 2018/9/10, [#6](https://github.com/slack-ruby/slack-shellbot/issues/6): Fix `Unmatched double quote` errors - [@dblock](https://github.com/dblock).
* 2016/3/2, [#5](https://github.com/slack-ruby/slack-shellbot/issues/5): `:q` will quit `vi` without saving the file - [@dblock](https://github.com/dblock).
* 2016/3/2, [#4](https://github.com/slack-ruby/slack-shellbot/issues/4): Edit messages in-place with `vi` - [@dblock](https://github.com/dblock).
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ gem 'rack-robotz'
gem 'rack-server-pages'
gem 'slack-ruby-bot-server'
gem 'slack-ruby-bot-server-mailchimp'
gem 'slack-ruby-bot-server-rtm'
gem 'slack-ruby-bot-server-events'
gem 'unicorn'

group :development, :test do
Expand Down
23 changes: 8 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ GEM
console (~> 1.10)
nio4r (~> 2.3)
timers (~> 4.1)
async-io (1.30.1)
async (~> 1.14)
async-websocket (0.8.0)
async-io
websocket-driver (~> 0.7.0)
bson (4.11.1)
builder (3.2.4)
capybara (3.33.0)
Expand Down Expand Up @@ -49,7 +44,7 @@ GEM
dry-container (0.7.2)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-core (0.4.9)
dry-core (0.4.10)
concurrent-ruby (~> 1.0)
dry-equalizer (0.3.0)
dry-inflector (0.2.0)
Expand Down Expand Up @@ -160,7 +155,7 @@ GEM
newrelic-slack-ruby-bot (0.2.2)
newrelic_rpm
slack-ruby-bot (>= 0.10.5)
newrelic_rpm (6.13.1)
newrelic_rpm (6.14.0)
nio4r (2.5.4)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
Expand All @@ -185,7 +180,7 @@ GEM
raindrops (0.19.1)
rake (13.0.1)
regexp_parser (1.8.2)
reline (0.1.8)
reline (0.1.9)
io-console (~> 0.5)
representable (3.0.4)
declarative (< 0.1.0)
Expand All @@ -212,7 +207,7 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.0)
rubocop (1.3.0)
rubocop (1.3.1)
parallel (~> 1.10)
parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0)
Expand All @@ -232,7 +227,7 @@ GEM
slack-ruby-bot (0.16.0)
hashie
slack-ruby-client (>= 0.14.0)
slack-ruby-bot-server (1.0.0)
slack-ruby-bot-server (1.1.0)
async
foreman
grape
Expand All @@ -243,13 +238,11 @@ GEM
rack-rewrite
rack-server-pages
slack-ruby-client
slack-ruby-bot-server-events (0.2.0)
slack-ruby-bot-server (>= 0.12.0)
slack-ruby-bot-server-mailchimp (0.2.0)
mailchimp_api_v3
slack-ruby-bot-server (>= 0.10.0)
slack-ruby-bot-server-rtm (0.1.1)
async-websocket (~> 0.8.0)
slack-ruby-bot (>= 0.12.0)
slack-ruby-bot-server (>= 1.0.0)
slack-ruby-client (0.14.6)
activesupport
faraday (>= 0.9)
Expand Down Expand Up @@ -307,8 +300,8 @@ DEPENDENCIES
rubocop
selenium-webdriver
slack-ruby-bot-server
slack-ruby-bot-server-events
slack-ruby-bot-server-mailchimp
slack-ruby-bot-server-rtm
unicorn
vcr
webmock
Expand Down
12 changes: 4 additions & 8 deletions slack-shellbot.rb → app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@

Mongoid.load! File.expand_path('../config/mongoid.yml', __FILE__), ENV['RACK_ENV']

require 'slack-shellbot/error'
require 'slack-shellbot/version'
require 'slack-shellbot/info'
require 'slack-shellbot/models'
require 'slack-shellbot/api'
require 'slack-shellbot/app'
require 'slack-shellbot/server'
require 'slack-shellbot/commands'
require_relative 'lib/version'
require_relative 'lib/info'
require_relative 'lib/models'
require_relative 'lib/commands'
21 changes: 6 additions & 15 deletions config.ru
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
# frozen_string_literal: true

ENV['RACK_ENV'] ||= 'development'
require_relative 'app'

require 'bundler/setup'
Bundler.require :default, ENV['RACK_ENV']
NewRelic::Agent.manual_start

require 'slack-ruby-bot-server'
require 'slack-shellbot'
SlackRubyBotServer::App.instance.prepare!
SlackRubyBotServer::Service.start!

SlackShellbot::App.instance.prepare!

Thread.abort_on_exception = true

Thread.new do
SlackRubyBotServer::Service.instance.start_from_database!
end

run Api::Middleware.instance
run SlackRubyBotServer::Api::Middleware.instance
29 changes: 0 additions & 29 deletions config/initializers/slack-ruby-bot/client.rb

This file was deleted.

51 changes: 0 additions & 51 deletions config/initializers/slack-ruby-bot/hooks/message.rb

This file was deleted.

4 changes: 4 additions & 0 deletions config/initializers/slack_ruby_bot_server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SlackRubyBotServer.configure do |config|
config.oauth_version = :v2
config.oauth_scope = ['chat:write', 'im:history', 'mpim:history', 'channels:history', 'groups:history']
end
18 changes: 18 additions & 0 deletions config/initializers/slack_ruby_bot_server_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
SlackRubyBotServer::Events.configure do |config|
config.on :event, 'event_callback', 'message' do |event|
# SlackShellbot::Commands::Base.logger.info event
# SlackShellbot::Commands::Base.logger.info "SUBTYPE: #{event['event']['subtype']}"
next true if event['event']['subtype'] # updates, etc.
# SlackShellbot::Commands::Base.logger.info "AUTH: #{event['authorizations'][0]['user_id']} vs. #{event['event']['user']}"
next true if event['authorizations'][0]['user_id'] == event['event']['user'] # self

data = Hashie::Mash.new(event['event'])
# SlackShellbot::Commands::Base.logger.info "MESSAGE: #{data.text}"
team = Team.where(team_id: event['team_id']).first
next true unless team

client = SlackShellbot::Web::Client.new(token: team.token, team: team)
SlackShellbot::Commands::Base.call(client, data)
true
end
end
34 changes: 34 additions & 0 deletions config/initializers/slack_ruby_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'slack-ruby-client'

module SlackShellbot
module Web
class Client < Slack::Web::Client
attr_reader :owner

def initialize(options = {})
@owner = options[:team] if options && options.key?(:team)
super
end

def update(options = {})
text = options[:text]
if text
Thread.current[:stdout] << text
chat_update(options.merge(text: "```#{text}```", as_user: true))
else
chat_update(method, options.merge(as_user: true))
end
end

def say(options = {})
text = options[:text]
if text
Thread.current[:stdout] << text
chat_postMessage(options.merge(text: "```#{text}```", as_user: true))
else
chat_postMessage(method, options.merge(as_user: true))
end
end
end
end
end
14 changes: 14 additions & 0 deletions lib/commands.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require_relative 'commands/base'
require_relative 'commands/help'
require_relative 'commands/pwd'
require_relative 'commands/ls'
require_relative 'commands/mkdir'
require_relative 'commands/rmdir'
require_relative 'commands/cd'
require_relative 'commands/touch'
require_relative 'commands/rm'
require_relative 'commands/echo'
require_relative 'commands/cat'
require_relative 'commands/uname'
require_relative 'commands/whoami'
require_relative 'commands/vi'
Loading

0 comments on commit 2a19607

Please sign in to comment.