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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/boty/action.rb +8 -0
- data/lib/boty/bot.rb +32 -2
- data/lib/boty/cli.rb +1 -1
- data/lib/boty/version.rb +1 -1
- data/locale/en.yml +11 -2
- data/locale/pt-br.yml +11 -2
- data/script/knows.rb +27 -7
- data/script/pug.rb +1 -1
- data/script/remember.rb +8 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc1c058cb4c902d4905be90809d77bfbbb6cdcfc
|
4
|
+
data.tar.gz: bd3dfd1478dc9a5bffeb6298f9ea211c66316f2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06b5a68da3320987f4841b0ac8581e359ee0c834a2481eb86335db5605377398959108ce50a8b2a4c18ec4dd47fdb7fc2fa62dc190484970ffb8fdb8db29edc0
|
7
|
+
data.tar.gz: ee0bb00924a2a9ae56d33e829e4d2a85ac44b6db970ae6334cf01f0fc32d6747e30fe32759a0caa88c8a4972d9bb960fa998171b829ae2b266070acb02b16416
|
data/Gemfile.lock
CHANGED
data/lib/boty/action.rb
CHANGED
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
data/lib/boty/version.rb
CHANGED
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:
|
10
|
-
|
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:
|
9
|
-
|
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
|
1
|
+
desc "knows", I18n.t("scripts.knows")
|
2
2
|
respond(/knows/i) do
|
3
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
data/script/remember.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
-
desc
|
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
|
7
|
+
im I18n.t("scripts.remember.response")
|
7
8
|
end
|
8
9
|
|
9
|
-
desc "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
|
13
|
-
|
14
|
-
|
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.
|
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-
|
11
|
+
date: 2015-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|