kybus-bot 0.4.1 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 189f024f3c6411b1c2c7d918a7ccfca6afd2cffe096c53f76522932c74be1b17
4
- data.tar.gz: 9f9b3928b68ea6b1fc1e6ae204d5e0a34223c3e909b2986bae0c477b848d73ca
3
+ metadata.gz: d09b1584001474f51cbe4085e6755ebc11b60aa24b1eef8bf9c8a9b574761148
4
+ data.tar.gz: 004db2811733eb668e6206f1d010be444c91eea4f3e5ccd7af439236fa1e167a
5
5
  SHA512:
6
- metadata.gz: 234bf15cd1c11549de4b8d3513a7abc50f76ffaae56aeb2248a112007b540fccf0e6a42f195c67b7a2a5032d13930e20f2384fb117ab86194d564c30ebb1d423
7
- data.tar.gz: f3c6e1743cea030340a677d6b7674932ded040e2ac4febfcc24eacfb76e7f36d39bbec85a908c52fe7e06bf782364a11abebc4f941b1d314b60e48fed7ed7766
6
+ metadata.gz: 375b62ad3c9beedce1f47cef05ab80acf6ff22365ecf82c685a5f61de50d68bff5c08e0acac12d9f387e18d9c3a0fdef1ca27e294a106e7b78cc186294eb84a4
7
+ data.tar.gz: 88bed84b3baba6dfadefe2536678b3308e9f1db923bba4baa8795ce52fe5050fa2540711209d0abc10fe33160db863dfd0704e36c773735e9f6f09ab4c7e4e7e
@@ -8,9 +8,10 @@ module Kybus
8
8
  # Wraps a debugging message inside a class.
9
9
  class DebugMessage < Kybus::Bot::Message
10
10
  # It receives a string with the raw text and the id of the channel
11
- def initialize(text, channel)
11
+ def initialize(text, channel, attachments = {})
12
12
  @text = text
13
13
  @channel = channel
14
+ @attachments = attachments
14
15
  end
15
16
 
16
17
  # Returns the channel id
@@ -64,7 +64,7 @@ module Kybus
64
64
  from: message.from.to_h)
65
65
  return TelegramMessage.new(message)
66
66
  end
67
- rescue Telegram::Bot::Exceptions::ResponseError => e
67
+ rescue ::Telegram::Bot::Exceptions::ResponseError => e
68
68
  log_error('An error ocurred while calling to Telegram API', e)
69
69
  end
70
70
  end
@@ -78,7 +78,7 @@ module Kybus
78
78
  def send_message(channel_name, contents)
79
79
  puts "#{channel_name} => #{contents}" if @config['debug']
80
80
  @client.api.send_message(chat_id: channel_name, text: contents)
81
- rescue Telegram::Bot::Exceptions::ResponseError => err
81
+ rescue ::Telegram::Bot::Exceptions::ResponseError => err
82
82
  return if err[:error_code] == '403'
83
83
  end
84
84
 
@@ -16,8 +16,17 @@ module Kybus
16
16
  include Kybus::Logger
17
17
  attr_reader :provider
18
18
 
19
+ class BotError < StandardError; end
20
+
21
+ class EmptyMessageError < BotError
22
+ def initialize
23
+ super('Message is empty')
24
+ end
25
+ end
26
+
19
27
  def send_message(content, channel = nil)
20
- @provider.send_message(channel || current_channel, content)
28
+ raise(EmptyMessageError) unless content
29
+ provider.send_message(channel || current_channel, content)
21
30
  end
22
31
 
23
32
  def rescue_from(klass, &block)
@@ -25,11 +34,11 @@ module Kybus
25
34
  end
26
35
 
27
36
  def send_image(content, channel = nil)
28
- @provider.send_image(channel || current_channel, content)
37
+ provider.send_image(channel || current_channel, content)
29
38
  end
30
39
 
31
40
  def send_audio(content, channel = nil)
32
- @provider.send_audio(channel || current_channel, content)
41
+ provider.send_audio(channel || current_channel, content)
33
42
  end
34
43
 
35
44
  # Configurations needed:
@@ -42,6 +51,7 @@ module Kybus
42
51
  @pool_size = configs['pool_size']
43
52
  @provider = Kybus::Bot::Adapter.from_config(configs['provider'])
44
53
  @commands = Kybus::Bot::CommandDefinition.new
54
+ register_command('default') do; end
45
55
 
46
56
  # TODO: move this to config
47
57
  @repository = Kybus::Storage::Repository.from_config(
@@ -61,7 +71,7 @@ module Kybus
61
71
  @pool = Array.new(@pool_size) do
62
72
  # TODO: Create a subclass with the context execution
63
73
  Kybus::DRY::Daemon.new(@pool_size, true) do
64
- message = @provider.read_message
74
+ message = provider.read_message
65
75
  @last_message = message
66
76
  process_message(message)
67
77
  end
@@ -136,7 +146,11 @@ module Kybus
136
146
  end
137
147
 
138
148
  def mention(name)
139
- @provider.mention(name)
149
+ provider.mention(name)
150
+ end
151
+
152
+ def registered_commands
153
+ @commands.registered_commands
140
154
  end
141
155
 
142
156
  # Loads command from state
@@ -174,7 +188,7 @@ module Kybus
174
188
  # Sends a message to get the next parameter from the user
175
189
  def ask_param(param)
176
190
  log_debug('I\'m going to ask the next param', param: param)
177
- @provider.send_message(current_channel,
191
+ provider.send_message(current_channel,
178
192
  "I need you to tell me #{param}")
179
193
  @state[:requested_param] = param.to_s
180
194
  end
@@ -36,6 +36,10 @@ module Kybus
36
36
  @commands[name] = Command.new(params, block)
37
37
  end
38
38
 
39
+ def registered_commands
40
+ @commands.keys
41
+ end
42
+
39
43
  # Returns a command with the name
40
44
  def [](name)
41
45
  @commands[name]
@@ -0,0 +1,32 @@
1
+ require_relative 'base'
2
+ require_relative 'adapters/debug'
3
+
4
+ module Kybus
5
+ module Bot
6
+ class Base
7
+ CONFIG = {
8
+ 'name' => 'test',
9
+ 'state_repository' => {
10
+ 'name' => 'json',
11
+ 'storage' => 'storage'
12
+ },
13
+ 'pool_size' => 1,
14
+ 'provider' => {
15
+ 'name' => 'debug',
16
+ 'echo' => true,
17
+ 'channels' => { 'testing' => [] }
18
+ }
19
+ }.freeze
20
+
21
+ def self.make_test_bot
22
+ new(CONFIG)
23
+ end
24
+
25
+ def receives(msg, attachments = {})
26
+ msg = ::Kybus::Bot::Adapter::DebugMessage.new(msg, 'testing', attachments)
27
+ @last_message = msg
28
+ process_message(msg)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kybus
4
4
  module Bot
5
- VERSION = '0.4.1'
5
+ VERSION = '0.4.5'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kybus-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilberto Vargas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-15 00:00:00.000000000 Z
11
+ date: 2022-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kybus-core
@@ -222,6 +222,7 @@ files:
222
222
  - lib/kybus/bot/command_definition.rb
223
223
  - lib/kybus/bot/message.rb
224
224
  - lib/kybus/bot/migrator.rb
225
+ - lib/kybus/bot/test.rb
225
226
  - lib/kybus/bot/testing.rb
226
227
  - lib/kybus/bot/version.rb
227
228
  homepage: https://github.com/tachomex/kybus
@@ -243,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
244
  - !ruby/object:Gem::Version
244
245
  version: '0'
245
246
  requirements: []
246
- rubygems_version: 3.1.4
247
+ rubygems_version: 3.2.32
247
248
  signing_key:
248
249
  specification_version: 4
249
250
  summary: Provides a framework for building bots with ruby