boty 0.0.12 → 0.0.13

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: 0749389ac8167b5c06f3ee78ec7d4c19808ac002
4
- data.tar.gz: b325acd68074482902b5c7a4ff07d24036e9dfc3
3
+ metadata.gz: dc1c058cb4c902d4905be90809d77bfbbb6cdcfc
4
+ data.tar.gz: bd3dfd1478dc9a5bffeb6298f9ea211c66316f2d
5
5
  SHA512:
6
- metadata.gz: de267e986d1510895eac1a16cd1ba3c573b040773e0a8cf81606baae5eb68f3a30583910a2ae232813c791a73bbd033fbdfcba57791c9c9d79f4990020d1768e
7
- data.tar.gz: ea8eb6e86724a64586a32c39ffcc0149c04c650fbec1585775214302b00dcf6e6881ecab470df679e33bad96baf4300bd76da6c4291a48152a047dff6e4c8842
6
+ metadata.gz: 06b5a68da3320987f4841b0ac8581e359ee0c834a2481eb86335db5605377398959108ce50a8b2a4c18ec4dd47fdb7fc2fa62dc190484970ffb8fdb8db29edc0
7
+ data.tar.gz: ee0bb00924a2a9ae56d33e829e4d2a85ac44b6db970ae6334cf01f0fc32d6747e30fe32759a0caa88c8a4972d9bb960fa998171b829ae2b266070acb02b16416
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- boty (0.0.12)
4
+ boty (0.0.13)
5
5
  eventmachine
6
6
  faye-websocket
7
7
  i18n
data/lib/boty/action.rb CHANGED
@@ -31,5 +31,13 @@ module Boty
31
31
  regex: regex)
32
32
  @regex, @desc, @action = regex, description, action
33
33
  end
34
+
35
+ def is_this?(regex, block)
36
+ if block
37
+ regex == self.regex && block == self.action
38
+ else
39
+ regex == self.regex
40
+ end
41
+ end
34
42
  end
35
43
  end
data/lib/boty/bot.rb CHANGED
@@ -5,6 +5,8 @@ module Boty
5
5
 
6
6
  def initialize(bot_info, session)
7
7
  @raw_info, @id, @name = bot_info, bot_info["id"], bot_info["name"]
8
+ @handlers ||= []
9
+ @commands ||= []
8
10
  @events = {}
9
11
  load_default_scripts
10
12
  on :message, &method(:message_handler)
@@ -23,16 +25,44 @@ module Boty
23
25
  @events[event_type.to_sym] << block
24
26
  end
25
27
 
28
+ def off(event_type, &block)
29
+ if block_given?
30
+ @events[event_type].delete_if { |b| b == block }
31
+ else
32
+ @events[event_type] = []
33
+ end
34
+ end
35
+
26
36
  def message(regex, &block)
27
- @handlers ||= []
28
37
  @handlers << create_action(regex, &block)
29
38
  end
30
39
 
40
+ def no_message(regex, &block)
41
+ @handlers.delete_if do |action|
42
+ action.is_this? regex, block
43
+ end
44
+ end
45
+
31
46
  def respond(regex, &block)
32
- @commands ||= []
33
47
  @commands << create_action(regex, &block)
34
48
  end
35
49
 
50
+ def no_respond(regex, &block)
51
+ @commands.delete_if do |action|
52
+ action.is_this? regex, block
53
+ end
54
+ end
55
+
56
+ def no(command)
57
+ @handlers.delete_if do |action|
58
+ action.desc.command == command
59
+ end
60
+
61
+ @commands.delete_if do |action|
62
+ action.desc.command == command
63
+ end
64
+ end
65
+
36
66
  def say(message, api_parameters = {})
37
67
  channel = (@_message && @_message.channel) || "general"
38
68
  options = { channel: channel }.merge api_parameters
data/lib/boty/cli.rb CHANGED
@@ -3,7 +3,7 @@ require "thor"
3
3
  module Boty
4
4
  class CLI < Thor
5
5
  include Thor::Actions
6
- class_option :verbose, type: :boolean, default: true
6
+ class_option :verbose, type: :boolean, default: true, aliases: "-v"
7
7
 
8
8
  attr_reader :bot_name, :company, :api_key
9
9
 
data/lib/boty/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Boty
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
data/locale/en.yml CHANGED
@@ -6,5 +6,14 @@ en:
6
6
  knows: "List all the commands known by this bot."
7
7
  pug_me: "Send some nice pug in the channel."
8
8
  pug_bomb: "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\"."
9
+ remember:
10
+ command: "remember: [some stuff about you]"
11
+ desc: "Instructs %{name} about something happening or about you."
12
+ response: "No worries, your secrets aren't safe with me... oh wait..."
13
+ about:
14
+ command: "about user [@SOME_USER]"
15
+ desc: "Retrieves information stored in the brain section :user for \"@SOME_USER\"."
16
+ response: |
17
+ I'm glad you need my knowlege on %{brain_area}, %{user_asking}.
18
+ I can tell you somethings about %{user_about}.
19
+ What I know... lets see...
data/locale/pt-br.yml CHANGED
@@ -5,5 +5,14 @@ pt-br:
5
5
  knows: "Lista os comandos conhecidos por esse bot."
6
6
  pug_me: "Manda um belo pug no canal."
7
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\"."
8
+ remember:
9
+ command: "remember: [alguma coisa sobre você]"
10
+ desc: "Ensina %{name} algo sobre você."
11
+ response: "Não se preocupe, minha boca é um `túmbalo`... não... péra..."
12
+ about:
13
+ command: "about user [@SOME_USER]"
14
+ desc: "Recupera informação na seção :user do cérebro para o usuário \"@SOME_USER\"."
15
+ response: |
16
+ Que bom que precisa de meus conhecimentos sobre %{brain_area}, %{user_asking}.
17
+ Acho que posso dizer algumas coisas sobre %{user_about}.
18
+ O que eu sei?... Vamos ver...
data/script/knows.rb CHANGED
@@ -1,10 +1,30 @@
1
- desc I18n.t "scripts.knows"
1
+ desc "knows", I18n.t("scripts.knows")
2
2
  respond(/knows/i) do
3
- message = know_how.inject("") { |_message, command|
3
+ say KnownFormmater.new(know_how).format
4
+ end
5
+
6
+ class KnownFormmater
7
+ def initialize(actions)
8
+ @actions = actions
9
+ @max_size = @actions.keys.map(&:length).max
10
+ end
11
+
12
+ def format
13
+ @actions.inject("```\n") { |_message, command|
14
+ _message << format_command(command) + "\n"
15
+ } + "```"
16
+ end
17
+
18
+ private
19
+
20
+ def name(command_name)
21
+ pad = @max_size - command_name.length
22
+ (" " * pad) + command_name
23
+ end
4
24
 
5
- _message << command.first
6
- _message << ": #{command.last}" if command.last
7
- _message << "\n"
8
- }
9
- say message
25
+ def format_command(command)
26
+ message = name command.first
27
+ message << ": #{command.last}" if command.last
28
+ message
29
+ end
10
30
  end
data/script/pug.rb CHANGED
@@ -1,4 +1,4 @@
1
- desc I18n.t "scripts.pug_me"
1
+ desc "pug me", 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"]}>"
data/script/remember.rb CHANGED
@@ -1,16 +1,18 @@
1
- desc "remember: I'm at the dentist", I18n.t("scripts.remember", name: name)
1
+ desc I18n.t("scripts.remember.command"),
2
+ I18n.t("scripts.remember.desc", name: name)
2
3
  respond(/remember(:?) (.+)/i) do |message|
3
4
  brain[:user] ||= {}
4
5
  brain[:user][message.user.name] ||= []
5
6
  brain[:user][message.user.name] << message.match[2]
6
- im "No worries, your secrets aren't safe with me... oh wait..."
7
+ im I18n.t("scripts.remember.response")
7
8
  end
8
9
 
9
- desc "about user julian", I18n.t("scripts.about")
10
+ desc I18n.t("scripts.about.command"), I18n.t("scripts.about.desc")
10
11
  respond(/about (\w+\b)(:?) (.+)/i) do |message|
11
12
  user = message.match[3]
12
- im "I'm glad you need my knowlege on #{message.match[1]}, #{message.user.name}."
13
- im "I can tell you somethings about #{user}."
14
- im "What I know... lets see..."
13
+ im I18n.t "scripts.about.response",
14
+ brain_area: message.match[1],
15
+ user_asking: message.user.name,
16
+ user_about: user
15
17
  brain[message.match[1].to_sym][user].each do |info| im info end
16
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.12
4
+ version: 0.0.13
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-25 00:00:00.000000000 Z
11
+ date: 2015-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine