boty 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/bin/bot +5 -3
- data/boty.gemspec +1 -0
- data/lib/boty/logger.rb +42 -0
- data/lib/boty/version.rb +1 -1
- data/lib/boty.rb +12 -14
- data/locale/en.yml +10 -0
- data/locale/pt-br.yml +9 -0
- data/script/knows.rb +1 -1
- data/script/pug.rb +2 -2
- data/script/remember.rb +2 -4
- data/template/project/bot.tt +5 -3
- metadata +18 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74d5b3c5eae3f0ce09247e0fd42830d3ec717f27
|
4
|
+
data.tar.gz: 2b0ef8bcf092a0dcc0d4054761c60e39274b4333
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ab94e2b871edade5c5c0b5e6d1780c5a51b60d7cc0cf37896663ed6eb49539d911585904cfe84193dea3af8d2595f0886a13fadcf24cdbaba1f3a382973ef3c
|
7
|
+
data.tar.gz: df59c71175b656ab20c5944c7be14406e6b06fd7620919d952e84cfc1ce64daa4aa37c5a4ccdf9b979aa773f84731dcc5aee19f7fa736d8645ec8f9932703422
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
boty (0.0.
|
4
|
+
boty (0.0.11)
|
5
5
|
eventmachine
|
6
6
|
faye-websocket
|
7
|
+
i18n
|
7
8
|
thor
|
8
9
|
|
9
10
|
GEM
|
@@ -19,6 +20,7 @@ GEM
|
|
19
20
|
websocket-driver (>= 0.5.1)
|
20
21
|
foreman (0.78.0)
|
21
22
|
thor (~> 0.19.1)
|
23
|
+
i18n (0.7.0)
|
22
24
|
rake (10.4.2)
|
23
25
|
rspec (3.4.0)
|
24
26
|
rspec-core (~> 3.4.0)
|
data/bin/bot
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require "./lib/boty"
|
3
3
|
|
4
|
+
Boty.locale = ARGV.pop || :en
|
5
|
+
|
4
6
|
session = Boty::Session.new
|
5
7
|
session.start do |bot|
|
6
|
-
bot.desc "
|
7
|
-
bot.message(/#{bot.name}
|
8
|
+
bot.desc I18n.t "template.presence", bot_name: bot.name
|
9
|
+
bot.message(/#{bot.name}/i) do |message|
|
8
10
|
next if message.from? self
|
9
|
-
say "
|
11
|
+
say I18n.t "template.hello", user_name: message.user.name
|
10
12
|
end
|
11
13
|
end
|
data/boty.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_runtime_dependency "eventmachine"
|
25
25
|
spec.add_runtime_dependency "faye-websocket"
|
26
26
|
spec.add_runtime_dependency "thor"
|
27
|
+
spec.add_runtime_dependency "i18n"
|
27
28
|
|
28
29
|
spec.add_development_dependency "bundler", "~> 1.10"
|
29
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/boty/logger.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "logger"
|
2
|
+
module Boty
|
3
|
+
module Logger
|
4
|
+
attr_writer :logger
|
5
|
+
|
6
|
+
def self.adapter=(adapter)
|
7
|
+
@adapter = adapter
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.adapter
|
11
|
+
@adapter ||= ::Logger.new(STDOUT).tap { |logger|
|
12
|
+
logger.level = ::Logger::DEBUG
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def logger
|
17
|
+
Logger.adapter
|
18
|
+
end
|
19
|
+
|
20
|
+
def log_level(level)
|
21
|
+
logger.level = level
|
22
|
+
end
|
23
|
+
|
24
|
+
class Memory < ::Logger
|
25
|
+
attr_reader :logs
|
26
|
+
|
27
|
+
def initialize(*args)
|
28
|
+
@logs = []
|
29
|
+
end
|
30
|
+
|
31
|
+
def add(*args, &block)
|
32
|
+
_, _, message = args
|
33
|
+
@logs << message
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Null < ::Logger
|
38
|
+
def initialize(*args); end
|
39
|
+
def add(*args, &block); end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/boty/version.rb
CHANGED
data/lib/boty.rb
CHANGED
@@ -9,28 +9,26 @@ begin
|
|
9
9
|
rescue LoadError
|
10
10
|
end
|
11
11
|
|
12
|
-
require "logger"
|
13
12
|
require "faye/websocket"
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
require "i18n"
|
15
|
+
locales = Dir[File.expand_path("../../locale/**/*", __FILE__)]
|
16
|
+
I18n.load_path += locales
|
18
17
|
|
19
|
-
|
20
|
-
@logger ||= ::Logger.new(STDOUT).tap { |logger|
|
21
|
-
logger.level = ::Logger::DEBUG
|
22
|
-
}
|
23
|
-
end
|
18
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
24
19
|
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
module Boty
|
21
|
+
def self.locale=(lang)
|
22
|
+
I18n.locale = lang
|
28
23
|
end
|
29
|
-
end
|
30
24
|
|
31
|
-
|
25
|
+
def self.locale
|
26
|
+
I18n.locale ||= :en
|
27
|
+
end
|
28
|
+
end
|
32
29
|
|
33
30
|
require "boty/version"
|
31
|
+
require "boty/logger"
|
34
32
|
require "boty/slack"
|
35
33
|
require "boty/session"
|
36
34
|
require "boty/message"
|
data/locale/en.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
en:
|
2
|
+
template:
|
3
|
+
presence: "Responds when the bot name (%{bot_name}) is mentioned in a message."
|
4
|
+
hello: "Ohay <@%{user_name}>! I'm here, that's for sure."
|
5
|
+
scripts:
|
6
|
+
knows: "List all the commands known by this bot."
|
7
|
+
pugme: "Send some nice pug in the channel."
|
8
|
+
pugbomb: "Send X pugs in the channel."
|
9
|
+
remember: "Instructs %{name} about something happening with the user."
|
10
|
+
about: "Retrieves information stored in the brain section :user for \"julian\"."
|
data/locale/pt-br.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
pt-br:
|
2
|
+
template:
|
3
|
+
presence: "Responde quando o nome do bot (%{bot_name}) é mencionado em uma mensagem."
|
4
|
+
scripts:
|
5
|
+
knows: "Lista os comandos conhecidos por esse bot."
|
6
|
+
pug_me: "Manda um belo pug no canal."
|
7
|
+
pug_bomb: "Manda X belos pugs no canal."
|
8
|
+
remember: "Ensina %{name} alguma informação fornecida pelo usuário."
|
9
|
+
about: "Busca informação no cérebro na seção :user para \"julian\"."
|
data/script/knows.rb
CHANGED
data/script/pug.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
desc "
|
1
|
+
desc I18n.t "scripts.pug_me"
|
2
2
|
respond(/pug me/i) do
|
3
3
|
response = JSON.parse Net::HTTP.get(URI "http://pugme.herokuapp.com/random")
|
4
4
|
say "<#{response["pug"]}>"
|
5
5
|
end
|
6
6
|
|
7
|
-
desc "pug bomb X", "
|
7
|
+
desc "pug bomb X", I18n.t("scripts.pug_bomb")
|
8
8
|
respond(/pug bomb( (\d+))?/i) do |message|
|
9
9
|
count = message.match[2] || 5
|
10
10
|
response = JSON.parse Net::HTTP.get(URI "http://pugme.herokuapp.com/bomb?count=#{count}")
|
data/script/remember.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
desc "remember: I'm at the dentist",
|
2
|
-
"Instructs #{name} about something happening with the user."
|
1
|
+
desc "remember: I'm at the dentist", I18n.t("scripts.remember", name: name)
|
3
2
|
respond(/remember(:?) (.+)/i) do |message|
|
4
3
|
brain[:user] ||= {}
|
5
4
|
brain[:user][message.user.name] ||= []
|
@@ -7,8 +6,7 @@ respond(/remember(:?) (.+)/i) do |message|
|
|
7
6
|
im "No worries, your secrets aren't safe with me... oh wait..."
|
8
7
|
end
|
9
8
|
|
10
|
-
desc "about user julian",
|
11
|
-
"Retrieves information stored in the brain section :user for \"julian\"."
|
9
|
+
desc "about user julian", I18n.t("scripts.about")
|
12
10
|
respond(/about (\w+\b)(:?) (.+)/i) do |message|
|
13
11
|
user = message.match[3]
|
14
12
|
im "I'm glad you need my knowlege on #{message.match[1]}, #{message.user.name}."
|
data/template/project/bot.tt
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require "./<%= bot_name %>"
|
3
3
|
|
4
|
+
Boty.locale = ARGV.pop || :en
|
5
|
+
|
4
6
|
session = Boty::Session.new
|
5
7
|
session.start do |bot|
|
6
|
-
desc "
|
7
|
-
bot.message(/<%=
|
8
|
+
bot.desc I18n.t "template.presence", bot_name: bot.name
|
9
|
+
bot.message(/<%= bot.name %>/i) do |message|
|
8
10
|
next if message.from? self
|
9
|
-
say "
|
11
|
+
say I18n.t "template.hello", user_name: message.user.name
|
10
12
|
end
|
11
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Valeriano
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: i18n
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -178,6 +192,7 @@ files:
|
|
178
192
|
- lib/boty/bot.rb
|
179
193
|
- lib/boty/cli.rb
|
180
194
|
- lib/boty/dsl.rb
|
195
|
+
- lib/boty/logger.rb
|
181
196
|
- lib/boty/message.rb
|
182
197
|
- lib/boty/rspec.rb
|
183
198
|
- lib/boty/session.rb
|
@@ -191,6 +206,8 @@ files:
|
|
191
206
|
- lib/boty/slack/users.rb
|
192
207
|
- lib/boty/version.rb
|
193
208
|
- lib/tasks/.keep
|
209
|
+
- locale/en.yml
|
210
|
+
- locale/pt-br.yml
|
194
211
|
- log/.keep
|
195
212
|
- script/knows.rb
|
196
213
|
- script/pug.rb
|