simple_slack 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4552ddfc4885e198e7c98a5b5f7ee583afe1ec88
4
- data.tar.gz: 96e80bf46675b41f1d75a882b74d7dfb90851e72
3
+ metadata.gz: 9f2abe241d1d93aa6b813b9b0a1564436fa20e15
4
+ data.tar.gz: a26b0b73e8c5ff56b19a44ef72d0af03eea6d73d
5
5
  SHA512:
6
- metadata.gz: 88ede11adf46abd7558ff44e07c4f886bff723f4d982617dcd845bbe764d90672a8b8e46b78f9275b802f949bcd8303a58e8cd79f8750355b197d03da455ede0
7
- data.tar.gz: 8db0863a0da1f6d880b76aeeee1971544fb5f2640916256a62afc5dc441f6c4bc07c91dbaa79ab13872e272c04233bb716bdaf30f6e1aaa809fa6fc90a8c114e
6
+ metadata.gz: bf241673669d0bb7d40be14d12b69f1552329f65afeab4e969e47ee4ab9955828b5984095672a6d7d13ad2819ae3cabb83c91fea06906abcfedfc6d87abe0aa4
7
+ data.tar.gz: 33045caf1d4b62f7b3c2e4ba013ecd77da8c763e3d35e7925bc3ce5585d7707ea777f57957860552cbcc77d7e0ff21265c619574f2ab1d9ee6d9767fbea8f6e4
@@ -44,7 +44,12 @@ class SimpleSlack::Botter
44
44
  if @responce_block.nil?
45
45
  @client.post.channel(to: @responce_channel, text: @responce_text, name: @responce_user)
46
46
  else
47
- @responce_block.call(data)
47
+ responce = {}.tap do |res|
48
+ res[:user] = @client.get.user(data["user"])[:name] rescue "unknown"
49
+ res[:channel] = @client.get.channel(data["channel"])[:name] rescue "unknown"
50
+ res[:text] = data["text"]
51
+ end
52
+ @responce_block.call(data, responce)
48
53
  end
49
54
  end
50
55
 
@@ -79,7 +84,7 @@ class SimpleSlack::Botter
79
84
  when String
80
85
  @client.get.channel(channel)
81
86
  when Array
82
- channle.map {|ch| @client.get.channel(ch.to_s) }
87
+ channel.map {|ch| @client.get.channel(ch.to_s) }
83
88
  when Hash
84
89
  channel
85
90
  when Symbol
@@ -52,6 +52,25 @@ class SimpleSlack::Getter
52
52
  @image_list.find{|user| user[:id] == id }
53
53
  end
54
54
 
55
+ def ims
56
+ im_list = @slack.im_list
57
+ im_list["ims"].map do |info|
58
+ im_user = if info["user"] == "USLACKBOT"
59
+ { id: info["user"], name: "owner" }
60
+ else
61
+ user(info["user"])
62
+ end
63
+ { id: info["id"], user: im_user }
64
+ end
65
+ end
66
+
67
+ def im(key)
68
+ im_user = user(key)
69
+ @im_list ||= ims
70
+
71
+ @im_list.find{|info| info[:user][:id] == im_user[:id] }
72
+ end
73
+
55
74
  def chats
56
75
  "yet"
57
76
  end
@@ -5,9 +5,8 @@ class SimpleSlack::Poster
5
5
  end
6
6
 
7
7
  def channel(to: , text: , name: "slacker")
8
- to.to_s =~ /\AC0.{7}\Z/ ? id = to : id = convert(to)
9
- result = @slack.chat_postMessage(username: name, channel: id, text: text)
10
- result["ok"]
8
+ to.to_s =~ /\AC0.{7}\Z/ ? id = to : id = convert_channel(to)
9
+ send_chat(username: name, channel: id, text: text)
11
10
  end
12
11
 
13
12
  def user(to: , text: , name: "slacker")
@@ -22,10 +21,25 @@ class SimpleSlack::Poster
22
21
  end
23
22
  end
24
23
 
24
+ def im(to: , text: , name: "slacker")
25
+ to.to_s =~ /\AD0.{7}\Z/ ? id = to : id = convert_im(to)
26
+ send_chat(username: name, channel: id, text: text)
27
+ end
28
+
25
29
  private
26
30
 
27
- def convert(name)
31
+ def send_chat(username: , channel: , text: , icon_emoji: ":ghost:")
32
+ result = @slack.chat_postMessage(username: username, channel: channel, text: text, icon_emoji: icon_emoji)
33
+ result["ok"]
34
+ end
35
+
36
+ def convert_channel(name)
28
37
  channel = @simple_slack.get.channel(name)
29
38
  channel[:id]
30
39
  end
40
+
41
+ def convert_im(name)
42
+ im = @simple_slack.get.im(name)
43
+ im[:id]
44
+ end
31
45
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleSlack
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - toririn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-27 00:00:00.000000000 Z
11
+ date: 2016-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler