boty 0.0.9 → 0.0.10

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: b15b8096419aa755624c59ba1c22e35d7c62a6e3
4
- data.tar.gz: 52b507f57d34b6ed50d838c8cd96ed117e39fc98
3
+ metadata.gz: 21a4d56f540118ad8858dc94e9e2bd2e193ab74d
4
+ data.tar.gz: db894f4d3e4a3c2b73ede86fc46270a25ace7ace
5
5
  SHA512:
6
- metadata.gz: 3d933754cd44b578e03335dd53977748662d2cb893c0ab28e44ec51bd39335116947b79777dca9583deeef63ce8e43bc654170b434ab4f9ac225650464a2bc14
7
- data.tar.gz: 961c2bf18e65662c8eb0a3c5cdc02ed3882c52b3b6326f3acc9d31845e0c0ce0e53b5f8823a27955308b7e2fc022cb5367a889b116594f64ea8b3d48d62a7a52
6
+ metadata.gz: b5c89bbaaafd1af6e2220b49c48723d472459eebc0e6d37ebce5d0fcd61469e03e16f642810984cc785eba23066704cec3138317f2a035921026058ea3055d5c
7
+ data.tar.gz: 9a8da21b939af7e7d386b956bd63f1244bd13ecd04794d459432bdab17da262b83d19158f34589502685badfb00f9e7cdf56d72cfd2f1f9d036b8e0b521f11ac
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- boty (0.0.9)
4
+ boty (0.0.10)
5
5
  eventmachine
6
6
  faye-websocket
7
7
  thor
data/lib/boty/bot.rb CHANGED
@@ -51,6 +51,15 @@ module Boty
51
51
  }
52
52
  end
53
53
 
54
+ def im(message)
55
+ logger.debug { "sending im messge to #{@_message.user.name}" }
56
+ Slack.chat.post_im @_message.user.id, message
57
+ end
58
+
59
+ def brain
60
+ @brain ||= {}
61
+ end
62
+
54
63
  private
55
64
 
56
65
  def scripts_to_load
data/lib/boty/cli.rb CHANGED
@@ -13,14 +13,9 @@ module Boty
13
13
  "Creates a BOT_NAME dir with your new bot structure."
14
14
  def new(bot_name)
15
15
  @bot_name = bot_name
16
- acquire_bot_info bot_name
16
+ acquire_bot_info
17
17
  directory "project", bot_name, verbose: verbose
18
- inside bot_name do
19
- # for some reason the example .rspec isn't been copied
20
- create_file ".rspec", "--require=spec_helper"
21
- run "chmod +x bot"
22
- run "bundle install"
23
- end
18
+ after_create
24
19
  end
25
20
 
26
21
  private
@@ -29,9 +24,18 @@ module Boty
29
24
  options[:verbose]
30
25
  end
31
26
 
32
- def acquire_bot_info(bot_name)
27
+ def acquire_bot_info
33
28
  @company = ask("What is your Slack company name?") || "acme"
34
29
  @api_key = ask("What is the #{@bot_name} api key?") || "omg-lol-bbq"
35
30
  end
31
+
32
+ def after_create
33
+ inside @bot_name do
34
+ # for some reason the example .rspec isn't been copied
35
+ create_file ".rspec", "--require=spec_helper"
36
+ run "chmod +x bot"
37
+ run "bundle install"
38
+ end
39
+ end
36
40
  end
37
41
  end
data/lib/boty/message.rb CHANGED
@@ -4,9 +4,8 @@ module Boty
4
4
  attr_reader :match
5
5
 
6
6
  def initialize(data, match: nil)
7
- @id = data["user"]
8
7
  @text = data["text"]
9
- @user = data["user"]
8
+ @user = Slack.users.info data["user"]
10
9
  @channel = data["channel"]
11
10
  @ts = data["ts"]
12
11
  @team = data["team"]
@@ -15,9 +14,9 @@ module Boty
15
14
 
16
15
  def from?(author)
17
16
  if author.respond_to? :id
18
- @id == author.id
17
+ @user.id == author.id
19
18
  else
20
- @id == author
19
+ @user.id == author
21
20
  end
22
21
  end
23
22
  end
data/lib/boty/slack.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  require "boty/slack/url"
2
+ require "boty/slack/channel"
3
+ require "boty/slack/im"
4
+ require "boty/slack/user"
5
+ require "boty/slack/users"
2
6
  require "boty/slack/chat"
3
7
  require "boty/slack/rtm"
4
8
 
@@ -7,6 +11,7 @@ module Boty
7
11
  class << self
8
12
  def chat; @chat ||= Chat.new end
9
13
  def rtm; @rtm ||= RTM.new end
14
+ def users; @users ||= Users.new end
10
15
  end
11
16
  end
12
17
  end
@@ -0,0 +1,11 @@
1
+ module Boty
2
+ module Slack
3
+ class Channel
4
+ attr_accessor :id
5
+
6
+ def initialize(id:, info:)
7
+ @id, @info = id, info
8
+ end
9
+ end
10
+ end
11
+ end
@@ -4,6 +4,8 @@ module Boty
4
4
  include Slack::URL
5
5
  url "https://slack.com/api/chat.postMessage"
6
6
 
7
+ def im; @im ||= IM.new end
8
+
7
9
  def post_message(message, parameters = {})
8
10
  defaults = {
9
11
  as_user: true,
@@ -12,6 +14,11 @@ module Boty
12
14
  }
13
15
  URL.get parameterize(defaults.merge parameters)
14
16
  end
17
+
18
+ def post_im(user, message)
19
+ channel = im.open user
20
+ post_message message, channel: channel.id
21
+ end
15
22
  end
16
23
  end
17
24
  end
@@ -0,0 +1,15 @@
1
+ module Boty
2
+ module Slack
3
+ class IM
4
+ include Slack::URL
5
+ url "https://slack.com/api/im"
6
+
7
+ def open(user, parameters = {})
8
+ defaults = { user: user }
9
+ url = parameterize defaults.merge(parameters), path: ".open"
10
+ info = URL.get(url) || {}
11
+ Slack::Channel.new id: Hash(info["channel"])["id"], info: info
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Boty
2
+ module Slack
3
+ class User
4
+ attr_accessor :id, :name
5
+
6
+ def initialize(info)
7
+ @id, @name = info["id"], info["name"]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module Boty
2
+ module Slack
3
+ class Users
4
+ include Slack::URL
5
+ url "https://slack.com/api/users"
6
+
7
+ def info(user_id, parameters = {})
8
+ defaults = { user: user_id }
9
+ url = parameterize defaults.merge(parameters), path: ".info"
10
+ info = URL.get url
11
+ Slack::User.new info["user"]
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/boty/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Boty
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -0,0 +1,18 @@
1
+ desc "remember: I'm at the dentist",
2
+ "Instructs #{name} about something happening with the user."
3
+ respond(/remember(:?) (.+)/i) do |message|
4
+ brain[:user] ||= {}
5
+ brain[:user][message.user.name] ||= []
6
+ brain[:user][message.user.name] << message.match[2]
7
+ im "No worries, your secrets aren't safe with me... oh wait..."
8
+ end
9
+
10
+ desc "about user julian",
11
+ "Retrieves information stored in the brain section :user for \"julian\"."
12
+ respond(/about (\w+\b)(:?) (.+)/i) do |message|
13
+ user = message.match[3]
14
+ im "I'm glad you need my knowlege on #{message.match[1]}, #{message.user.name}."
15
+ im "I can tell you somethings about #{user}."
16
+ im "What I know... lets see..."
17
+ brain[message.match[1].to_sym][user].each do |info| im info end
18
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Valeriano
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-24 00:00:00.000000000 Z
11
+ date: 2015-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -182,14 +182,19 @@ files:
182
182
  - lib/boty/rspec.rb
183
183
  - lib/boty/session.rb
184
184
  - lib/boty/slack.rb
185
+ - lib/boty/slack/channel.rb
185
186
  - lib/boty/slack/chat.rb
187
+ - lib/boty/slack/im.rb
186
188
  - lib/boty/slack/rtm.rb
187
189
  - lib/boty/slack/url.rb
190
+ - lib/boty/slack/user.rb
191
+ - lib/boty/slack/users.rb
188
192
  - lib/boty/version.rb
189
193
  - lib/tasks/.keep
190
194
  - log/.keep
191
195
  - script/knows.rb
192
196
  - script/pug.rb
197
+ - script/remember.rb
193
198
  - template/project/%bot_name%.rb
194
199
  - template/project/.env.local.tt
195
200
  - template/project/Gemfile