ruboty-slack_reaction_added 0.1.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2dcd98854d9802c80d92d7e30a0664e08c20d52c018e0c002198c03cf0ab28df
4
- data.tar.gz: 3349bee5d5d493039bcd854ca87ef105dd1286dd39dc0b933d81c025d627dd97
3
+ metadata.gz: 1ca6920891abfa02fd0e7162e5cdd2e2d94393679864ce2a5b4aecea703b85ed
4
+ data.tar.gz: f3ac649b33bbcbb8ef255c05f5deca320a966c7a7b951f53a6b6f7f0857652e2
5
5
  SHA512:
6
- metadata.gz: 4b48b80274a8964da2e4441b806997a0641b8236375517a76f70cc7c26dfe3b1295e76063ae04faac01d079a9b9072ff3738a5bc16dce81f6533c813bb4b58ac
7
- data.tar.gz: f58de517b4c83ae6b0ddb9b6a482cd93eeaa48a43001eab57fca8a3134d6ee07bb3cd2b609dd31f7bca23fffab8e8d3ec5f3f541d83132bf41ed015c541d98cd
6
+ metadata.gz: 3cf1db3dc1ab545efabc599c3d7333244ab7d184e5c30e26668193d99a7beaf7cf57e14f23720f14ad26fd955f7213deef07c759ae234d70eeb40447dfb6c81b
7
+ data.tar.gz: dfe78b77ccd75da575dc4a9b4ecf00dab9521ffa7f406f65145a3b6cb63f295a47d87ea68c14340b645541134b8a22f96c62672e6d24b52b50900dd36d8c8092
data/README.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # ruboty-slack_reaction_added
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/ruboty-slack_reaction_added.svg)](https://badge.fury.io/rb/ruboty-slack_reaction_added)
4
+
3
5
  Slack Reaction added event extension for [RubotySlackRTM][].
4
6
 
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'ruboty-slack_reaction_added'
12
+
13
+ ## ENV
14
+
15
+ * `DISABLE_DEFAULT_REACTION_HANDLERS` : Disable ruboty-slack_reaction_added handlers
16
+ * `@bot reaction ping` message reaction added: reply pong again
17
+ * `@bot reaction name` message reaction added: reply reaction name
18
+ * :bookmark: reaction : reply permalink
19
+ * :+1: reaction : bot +1
20
+
21
+ ## Handler options
22
+
23
+ * `allow_reaction` : handler is also called on the event to which the reaction_added
24
+ * `raction_only` : handler will only be called on the event to which the reaction_added
25
+
26
+ ## Message
27
+
28
+ * `message.reaction` : get reaction name
29
+ * `message.reaction_by`: get reaction_added user name
30
+
31
+ ## Example
32
+
33
+ https://github.com/srz-zumix/ruboty-slack_reaction_added/blob/main/lib/ruboty/slack_reaction_added/handlers/handler.rb
34
+
35
+ ![Example](https://user-images.githubusercontent.com/1439172/110792563-ebffca00-82b6-11eb-928a-741de77659b9.png)
36
+
5
37
  [RubotySlackRTM]:https://github.com/rosylilly/ruboty-slack_rtm
@@ -3,6 +3,7 @@ require 'ruboty/slack_reaction_added/extension/action'
3
3
  require 'ruboty/slack_reaction_added/extension/adapter'
4
4
  require 'ruboty/slack_reaction_added/extension/client'
5
5
  require 'ruboty/slack_reaction_added/extension/message'
6
+ require 'ruboty/slack_reaction_added/extension/robot'
6
7
 
7
8
  if ENV["DISABLE_DEFAULT_REACTION_HANDLERS"] != "1"
8
9
  require 'ruboty/slack_reaction_added/handlers/handler.rb'
@@ -0,0 +1,19 @@
1
+
2
+ module Ruboty
3
+ module SlackReactionAdded
4
+ module Actions
5
+ class Permalink < Ruboty::Actions::Base
6
+
7
+ def call
8
+ unless message.reaction_by == message.robot.name
9
+ case message.reaction
10
+ when 'bookmark'
11
+ message.reply(message.permalink)
12
+ end
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+
2
+ module Ruboty
3
+ module SlackReactionAdded
4
+ module Actions
5
+ class ReactionName < Ruboty::Actions::Base
6
+
7
+ def call
8
+ unless message.reaction_by == message.robot.name
9
+ message.reply(":#{message.reaction}: => `:#{message.reaction}:`")
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
16
+ end
@@ -5,7 +5,9 @@ module Ruboty
5
5
  class ReactionPing < Ruboty::Actions::Base
6
6
 
7
7
  def call
8
- message.reply('pong')
8
+ unless message.reaction_by == message.robot.name
9
+ message.reply('pong')
10
+ end
9
11
  end
10
12
 
11
13
  end
@@ -7,7 +7,7 @@ module Ruboty
7
7
  def call
8
8
  # Ruboty.logger.info message.reaction
9
9
  # Ruboty.logger.info message.reaction_by
10
- unless message.reaction_by == Ruboty::Robot.name
10
+ unless message.reaction_by == message.robot.name
11
11
  case message.reaction
12
12
  when '+1'
13
13
  message.add_reaction('thumbsup')
@@ -8,8 +8,6 @@ module Ruboty
8
8
  channel = data['item']['channel']
9
9
  histories = @client.conversations_history(channel: channel, latest: data['item']['ts'], inclusive: true, limit: 1)
10
10
  message = histories['messages'][0]
11
- permalink = @client.chat_getPermalink(channel: channel, message_ts: data['item']['ts'])
12
- message['permalink'] = permalink['permalink']
13
11
  message['channel'] = channel
14
12
  message['reaction_added'] = data
15
13
  # Ruboty.logger.info message
@@ -60,6 +58,24 @@ module Ruboty
60
58
  end
61
59
  end
62
60
  end
61
+
62
+ def channel_info(channel_id)
63
+ @channel_info_caches[channel_id] ||= begin
64
+ resp = case channel_id
65
+ when /^C/, /^D/, /^G/
66
+ client.conversations_info(channel: channel_id)
67
+ else
68
+ {}
69
+ end
70
+
71
+ resp['channel']
72
+ end
73
+ end
74
+
75
+ def permalink(channel_id, ts)
76
+ permalink = @client.chat_getPermalink(channel: channel_id, message_ts: ts)
77
+ permalink['permalink']
78
+ end
63
79
  end
64
80
 
65
81
  prepend ReactionAddedSlackRTM
@@ -8,6 +8,10 @@ module Ruboty
8
8
  robot.add_reaction(reaction, channel_id, timestamp)
9
9
  end
10
10
 
11
+ def permalink
12
+ robot.permalink(@original[:channel]["id"], @original[:ts])
13
+ end
14
+
11
15
  def reaction
12
16
  @original[:reaction]
13
17
  end
@@ -0,0 +1,15 @@
1
+ require 'ruboty/robot'
2
+
3
+ module Ruboty
4
+ module ReactionAddedClient
5
+ module Robot
6
+ delegate :permalink, to: :adapter
7
+
8
+ def permalink(channel_id, timestamp)
9
+ adapter.permalink(channel_id, timestamp)
10
+ end
11
+ end
12
+ end
13
+
14
+ Robot.include ReactionAddedClient::Robot
15
+ end
@@ -1,3 +1,5 @@
1
+ require 'ruboty/slack_reaction_added/actions/permalink.rb'
2
+ require 'ruboty/slack_reaction_added/actions/reaction_name.rb'
1
3
  require 'ruboty/slack_reaction_added/actions/reaction_ping.rb'
2
4
  require 'ruboty/slack_reaction_added/actions/thumbup.rb'
3
5
 
@@ -6,25 +8,43 @@ module Ruboty
6
8
  module Handlers
7
9
  class Handler < Ruboty::Handlers::Base
8
10
 
9
- on /ping\z/,
10
- name: 'reaction_able_ping',
11
- description: 'ping allow reaction',
12
- allow_reaction: true
11
+ on /reaction ping\z/,
12
+ name: 'reaction_able_ping',
13
+ description: 'ping allow reaction',
14
+ allow_reaction: true
13
15
 
14
- on /.*\z/,
15
- name: 'thumbup',
16
- description: 'thumbup',
17
- reaction_only: true,
18
- all: true
16
+ on /reaction name\z/,
17
+ name: 'reaction_name',
18
+ description: 'reaction name say on readciont_added',
19
+ reaction_only: true
20
+
21
+ on /.*\z/m,
22
+ name: 'thumbup',
23
+ description: 'thumbup',
24
+ reaction_only: true,
25
+ all: true
26
+
27
+ on /.*\z/m,
28
+ name: 'permalink',
29
+ description: 'permalink',
30
+ reaction_only: true,
31
+ all: true
19
32
 
20
33
  def reaction_able_ping(message)
21
34
  Ruboty::SlackReactionAdded::Actions::ReactionPing.new(message).call
22
35
  end
23
36
 
37
+ def reaction_name(message)
38
+ Ruboty::SlackReactionAdded::Actions::ReactionName.new(message).call
39
+ end
40
+
24
41
  def thumbup(message)
25
42
  Ruboty::SlackReactionAdded::Actions::Thumbup.new(message).call
26
43
  end
27
44
 
45
+ def permalink(message)
46
+ Ruboty::SlackReactionAdded::Actions::Permalink.new(message).call
47
+ end
28
48
  end
29
49
  end
30
50
  end
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module SlackReactionAdded
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.6.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-slack_reaction_added
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - srz_zumix
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-11 00:00:00.000000000 Z
11
+ date: 2021-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -142,12 +142,15 @@ files:
142
142
  - Rakefile
143
143
  - docker-compose.yml
144
144
  - lib/ruboty/slack_reaction_added.rb
145
+ - lib/ruboty/slack_reaction_added/actions/permalink.rb
146
+ - lib/ruboty/slack_reaction_added/actions/reaction_name.rb
145
147
  - lib/ruboty/slack_reaction_added/actions/reaction_ping.rb
146
148
  - lib/ruboty/slack_reaction_added/actions/thumbup.rb
147
149
  - lib/ruboty/slack_reaction_added/extension/action.rb
148
150
  - lib/ruboty/slack_reaction_added/extension/adapter.rb
149
151
  - lib/ruboty/slack_reaction_added/extension/client.rb
150
152
  - lib/ruboty/slack_reaction_added/extension/message.rb
153
+ - lib/ruboty/slack_reaction_added/extension/robot.rb
151
154
  - lib/ruboty/slack_reaction_added/handlers/handler.rb
152
155
  - lib/ruboty/slack_reaction_added/version.rb
153
156
  - ruboty-slack_reaction_added.gemspec