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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/twitch/bot.rb +1 -0
- data/lib/twitch/bot/command_handler.rb +31 -0
- data/lib/twitch/bot/version.rb +1 -1
- data/spec/twitch/bot/command_handler_spec.rb +19 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59dabc57f451a9054c650af520cacc2b05b2532538d22080404a19a30be51c35
|
4
|
+
data.tar.gz: d6f75053e902744d29c512abc89ebfca97acfb46fc4f7a5362c61faec9902534
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d25aae7bfcf9b00aca8d9cfde3d76e480c933aa12ac03ea7b74406f96645db3d374455b5152dd420e854bb87f15048ffa03eea59e7b266fe5c9a5207df25d43
|
7
|
+
data.tar.gz: 5baf4cf1ca8392c2d92c80b1d7582c01fe0a9ec3911e14decd8aca2d0e72503f7a20cb3521367c833e7c6de4f874dbbeeb62cbde6f3dfcd365cdc714cd20e264
|
data/CHANGELOG.md
CHANGED
data/lib/twitch/bot.rb
CHANGED
@@ -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
|
data/lib/twitch/bot/version.rb
CHANGED
@@ -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
|
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
|