boty 0.0.6 → 0.0.7

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: 6c95fa76730f4a41c13d06ff314d53c0a9ee1f1c
4
- data.tar.gz: 22567a320540d0fb327cdf9a0c863a10da787b82
3
+ metadata.gz: ec2bf939ca3aff3761d4019b065287e836d6859c
4
+ data.tar.gz: acd79aba96e84b017fff702f11fb9f20a6cd9d97
5
5
  SHA512:
6
- metadata.gz: a44d246026394e6d097e83d8405d1fdfcd73bed586790dd807fa975da6a330b548b8b85a3840b2d27c0da2b166e673d623b27524db02ee89504c4ec4d7fdfd2a
7
- data.tar.gz: e82866d26ad78cc4de3cd4f875d4a52fa59208f745823a0172142a3e8e4cb4e63931c67dd33cd4d340495d349d518c145e1f513f6e86d694d08561a18699696f
6
+ metadata.gz: 9c5edc1117584ea21477c080b246f89ee8653b118daf83469f78215c9961f12442bc680733f0ec51b2a01a2c02c411b58cf139d4607f8fbee9270817a1a09443
7
+ data.tar.gz: 41ddccf73cc09e48e89854c21941640e38498ef8ce6e7e69e3fbfac77b05ceb3f8f35b086c524820add7ecc7273f4c6b1841ad00042721213b66cd1a6ad1abcf
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- boty (0.0.6)
4
+ boty (0.0.7)
5
5
  eventmachine
6
6
  faye-websocket
7
7
  thor
data/bin/bot CHANGED
@@ -2,9 +2,7 @@
2
2
  require "./lib/boty"
3
3
 
4
4
  session = Boty::Session.new
5
- session.verbose = true
6
5
  session.start do |bot|
7
- bot.verbose = true
8
6
  bot.message(/are you there\?/i) do |message|
9
7
  next if message.from? self
10
8
  say "Ohay <@#{message.user}>! I'm here, that's for sure."
data/lib/boty.rb CHANGED
@@ -9,14 +9,29 @@ begin
9
9
  rescue LoadError
10
10
  end
11
11
 
12
+ require "logger"
12
13
  require "faye/websocket"
13
14
 
15
+ module Boty
16
+ module Logger
17
+ attr_writer :logger
18
+
19
+ def logger
20
+ @logger ||= ::Logger.new(STDOUT).tap { |logger|
21
+ logger.level = ::Logger::DEBUG
22
+ }
23
+ end
24
+
25
+ def log_level(level)
26
+ logger.level = level
27
+ end
28
+ end
29
+ end
30
+
14
31
  $:.unshift File.expand_path("../../lib", __FILE__)
32
+
15
33
  require "boty/version"
16
34
  require "boty/slack"
17
35
  require "boty/session"
18
36
  require "boty/message"
19
37
  require "boty/bot"
20
-
21
- module Boty
22
- end
data/lib/boty/bot.rb CHANGED
@@ -1,11 +1,10 @@
1
1
  module Boty
2
2
  class Bot
3
- attr_writer :verbose
3
+ include Boty::Logger
4
4
  attr_reader :id, :name
5
5
 
6
6
  def initialize(bot_info, session)
7
7
  @raw_info, @id, @name = bot_info, bot_info["id"], bot_info["name"]
8
- @verbose = false
9
8
  @events = {}
10
9
  load_default_scripts
11
10
  end
@@ -36,7 +35,7 @@ module Boty
36
35
  # ignores if the mentions was sent by the bot itself, avoid infinite
37
36
  # loops.
38
37
  next if message_from_bot_itself? data
39
- debug "message wasn't from bot itself, so continuing..."
38
+ logger.debug { "message wasn't from bot itself, so continuing..." }
40
39
  yield_message_if_matches(data, block) do
41
40
  has_mention?(data) && regex.match(data["text"])
42
41
  end
@@ -47,22 +46,11 @@ module Boty
47
46
  channel = (@_message && @_message.channel) || "general"
48
47
  options = { channel: channel }.merge api_parameters
49
48
  post_response = Slack.chat.post_message message, options
50
- debug nil, post_response
49
+ logger.debug { "post response: #{post_response}" }
51
50
  end
52
51
 
53
52
  private
54
53
 
55
- def verbose?; @verbose; end
56
-
57
- def debug(message, *stuff)
58
- return unless verbose?
59
-
60
- $stdout.puts message
61
- method = $stdout.respond_to?(:pp) ? :pp : :p
62
- talker = $stdout.method method
63
- stuff.each do |printable| talker.call printable end
64
- end
65
-
66
54
  def load_default_scripts
67
55
  # TODO: guarantee that we not load the same file twice
68
56
  Dir["script/**/*.rb"].each do |file|
@@ -77,9 +65,9 @@ module Boty
77
65
 
78
66
  def event_type(data)
79
67
  type = data["type"].to_sym
80
- debug "bot specifc event[#{type}] arrived", data
68
+ logger.debug { "bot specifc event[#{type}] arrived: #{data}" }
81
69
  unless @events[type]
82
- debug "no action binded to #{type}"
70
+ logger.debug "no action binded to #{type}"
83
71
  return
84
72
  end
85
73
  type
data/lib/boty/session.rb CHANGED
@@ -3,12 +3,8 @@ require "net/http"
3
3
 
4
4
  module Boty
5
5
  class Session
6
+ include Boty::Logger
6
7
  attr_reader :bot
7
- attr_writer :verbose
8
-
9
- def initialize(verbose: false)
10
- @verbose = verbose
11
- end
12
8
 
13
9
  def start(&block)
14
10
  EM.run do
@@ -24,41 +20,32 @@ module Boty
24
20
  end
25
21
 
26
22
  private
27
- def verbose?; @verbose; end
28
-
29
- def debug(message, *stuff)
30
- return unless verbose?
31
- $stdout.puts message
32
- method = $stdout.respond_to?(:pp) ? :pp : :p
33
- talker = $stdout.method method
34
- stuff.each do |printable| talker.call printable end
35
- end
36
23
 
37
24
  def login
38
- debug "logging in against slack right now"
25
+ logger.debug { "logging in against slack right now" }
39
26
  @slack_info = Slack.rtm.start
40
- debug "yep! logged in!"
27
+ logger.debug { "yep! logged in!" }
41
28
  @session_url = @slack_info["url"]
42
29
  end
43
30
 
44
31
  def initialize_bot(&block)
45
32
  Bot.new(@slack_info["self"], self).tap { |bot|
46
33
  block.call bot if block_given?
47
- debug "bot is configured and ready to go!"
34
+ logger.debug { "bot is configured and ready to go!" }
48
35
  }
49
36
  end
50
37
 
51
38
  def on_message(event, bot)
52
- debug "message arrived", event.data
39
+ logger.debug { "message arrived #{event.data}" }
53
40
  bot.event JSON.parse(event.data)
54
41
  end
55
42
 
56
43
  def on_close
57
- debug "bye byeb."
44
+ logger.debug { "bye byeb." }
58
45
  end
59
46
 
60
47
  def stablish_connection
61
- debug "starting to listen on #{@session_url}"
48
+ logger.debug { "starting to listen on #{@session_url}" }
62
49
  ws = Faye::WebSocket::Client.new @session_url
63
50
  ws.on :close do on_close end
64
51
  yield ws if block_given?
data/lib/boty/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Boty
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -2,9 +2,7 @@
2
2
  require "./<%= bot_name %>"
3
3
 
4
4
  session = Boty::Session.new
5
- session.verbose = true
6
5
  session.start do |bot|
7
- bot.verbose = true
8
6
  bot.message(/<%= bot_name %>/i) do |message|
9
7
  next if message.from? self
10
8
  say "Ohay <@#{message.user}>! I'm here, that's for sure."
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.6
4
+ version: 0.0.7
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-19 00:00:00.000000000 Z
11
+ date: 2015-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine