twitch-bot 4.0.1 → 4.1.0

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
  SHA256:
3
- metadata.gz: 8e4f03406f61c87e0daa72edc415d45fe13acfe5b33514c75a2028c119d52212
4
- data.tar.gz: 2e5336cff0e7304f91725d05ec7ff5e813ad54a0127554d0f3349d72d435d5d7
3
+ metadata.gz: 59dabc57f451a9054c650af520cacc2b05b2532538d22080404a19a30be51c35
4
+ data.tar.gz: d6f75053e902744d29c512abc89ebfca97acfb46fc4f7a5362c61faec9902534
5
5
  SHA512:
6
- metadata.gz: e634d550cbd5b2dfb8f80216f11284c015aa9e6e78cb9a08557af848b92f1505f8ac66c70270ce5329aa6eccc2bc3b2f8fba39b690032f5b7e7c8d0941a5fe1f
7
- data.tar.gz: cc44b72bb4656a743321e5da2596da419e8eb078e759bea9742cfffa5a2047156caae7588a4cc3a3fcb7e302999a92b00c07a7531a9105d22137bc5a44268d04
6
+ metadata.gz: 9d25aae7bfcf9b00aca8d9cfde3d76e480c933aa12ac03ea7b74406f96645db3d374455b5152dd420e854bb87f15048ffa03eea59e7b266fe5c9a5207df25d43
7
+ data.tar.gz: 5baf4cf1ca8392c2d92c80b1d7582c01fe0a9ec3911e14decd8aca2d0e72503f7a20cb3521367c833e7c6de4f874dbbeeb62cbde6f3dfcd365cdc714cd20e264
@@ -1,5 +1,9 @@
1
1
  # Changelog Twitch::Bot
2
2
 
3
+ ## v4.1.0
4
+
5
+ * [NEW] New `CommandHandler` class that simplifies building chat commands.
6
+
3
7
  ## v4.0.1
4
8
 
5
9
  * [FIXED] Fixed test crash due to incomplete DotEnv initialization.
@@ -8,6 +8,7 @@ require_relative "bot/config"
8
8
  require_relative "bot/logger"
9
9
  require_relative "bot/event"
10
10
  require_relative "bot/event_handler"
11
+ require_relative "bot/command_handler"
11
12
  require_relative "bot/default_handlers"
12
13
  require_relative "bot/message"
13
14
  require_relative "bot/irc_message"
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Twitch
4
+ module Bot
5
+ # Base class for implementing chat commands
6
+ class CommandHandler < EventHandler
7
+ def initialize(event:, client:)
8
+ super
9
+ @command_aliases = []
10
+ end
11
+
12
+ def call
13
+ if event.command? && command_aliases.include?(event.command)
14
+ handle_command
15
+ end
16
+ end
17
+
18
+ def command_alias(command_alias)
19
+ @command_aliases << command_alias
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :command_aliases
25
+
26
+ def handle_command
27
+ raise NotImplementedError
28
+ end
29
+ end
30
+ end
31
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Twitch
4
4
  module Bot
5
- VERSION = "4.0.1"
5
+ VERSION = "4.1.0"
6
6
  end
7
7
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Twitch::Bot::CommandHandler do
4
+ it "responds to a known command" do
5
+ config = Twitch::Bot::Config.new
6
+ client = Twitch::Bot::Client.new(config: config)
7
+ message = Twitch::Bot::Message::UserMessage.new(
8
+ text: "!mycommand test",
9
+ user: "testuser",
10
+ )
11
+ handler = described_class.new(event: message, client: client)
12
+ handler.command_alias("mycommand")
13
+ allow(handler).to receive(:handle_command)
14
+
15
+ handler.call
16
+
17
+ expect(handler).to have_received(:handle_command)
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitch-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jochen Lillich
@@ -194,6 +194,7 @@ files:
194
194
  - lib/twitch/bot/adapter/terminal.rb
195
195
  - lib/twitch/bot/channel.rb
196
196
  - lib/twitch/bot/client.rb
197
+ - lib/twitch/bot/command_handler.rb
197
198
  - lib/twitch/bot/config.rb
198
199
  - lib/twitch/bot/default_handlers.rb
199
200
  - lib/twitch/bot/event.rb
@@ -209,6 +210,7 @@ files:
209
210
  - spec/spec_helper.rb
210
211
  - spec/twitch/bot/adapter/terminal_spec.rb
211
212
  - spec/twitch/bot/client_spec.rb
213
+ - spec/twitch/bot/command_handler_spec.rb
212
214
  - spec/twitch/bot/config_spec.rb
213
215
  - spec/twitch/bot/memory/hash_spec.rb
214
216
  - spec/twitch/bot/memory/redis_spec.rb
@@ -243,6 +245,7 @@ test_files:
243
245
  - spec/spec_helper.rb
244
246
  - spec/twitch/bot/adapter/terminal_spec.rb
245
247
  - spec/twitch/bot/client_spec.rb
248
+ - spec/twitch/bot/command_handler_spec.rb
246
249
  - spec/twitch/bot/config_spec.rb
247
250
  - spec/twitch/bot/memory/hash_spec.rb
248
251
  - spec/twitch/bot/memory/redis_spec.rb