twitch-bot 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +14 -7
- data/CHANGELOG.md +4 -0
- data/README.md +2 -0
- data/docker-compose.yml +7 -0
- data/lib/twitch/bot.rb +1 -0
- data/lib/twitch/bot/client.rb +1 -1
- data/lib/twitch/bot/memory/hash.rb +4 -2
- data/lib/twitch/bot/memory/redis.rb +38 -0
- data/lib/twitch/bot/version.rb +1 -1
- data/spec/twitch/bot/client_spec.rb +1 -1
- data/spec/twitch/bot/memory/hash_spec.rb +1 -1
- data/spec/twitch/bot/memory/redis_spec.rb +22 -0
- data/twitch-bot.gemspec +2 -0
- metadata +19 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f73427a772e3b29804f8ef6066b2d4ea44259f0c095218a9e63b1caddae7dd3
|
4
|
+
data.tar.gz: 282e8a62f638085d855c1a6fca1717b314b0f5b3fe6671fb5e4c07fd32e4bf17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72e2a1d4d0292645703d1110109004d2b20b346decd30677432dc5d3890c39b5a869a9b2cc31774e9adf37ffbe4fcaf90ec1d7a6f1784756f032100603f0826c
|
7
|
+
data.tar.gz: 41e166ebb07600f9d667bee2c88599e0c51874b572b63a9e3ded8047f67fbe339e9be7e1b753df0a935ae251748a09b49891c6c65f4832976fa9a8e64718ee20
|
data/.github/workflows/main.yml
CHANGED
@@ -7,20 +7,27 @@ on:
|
|
7
7
|
jobs:
|
8
8
|
test:
|
9
9
|
runs-on: ubuntu-latest
|
10
|
-
|
10
|
+
container: ruby:2.6
|
11
|
+
services:
|
12
|
+
redis:
|
13
|
+
image: redis
|
14
|
+
options: >-
|
15
|
+
--health-cmd "redis-cli ping"
|
16
|
+
--health-interval 10s
|
17
|
+
--health-timeout 5s
|
18
|
+
--health-retries 5
|
11
19
|
steps:
|
12
20
|
- uses: actions/checkout@v2
|
13
|
-
- name: Set up Ruby
|
14
|
-
uses: actions/setup-ruby@v1
|
15
|
-
with:
|
16
|
-
ruby-version: 2.6.x
|
17
21
|
- name: Bundle
|
18
22
|
run: |
|
19
23
|
gem install bundler
|
20
24
|
bundle install --jobs 4 --retry 3
|
21
|
-
- name:
|
25
|
+
- name: Test
|
22
26
|
run: |
|
23
27
|
bundle exec rake test
|
28
|
+
env:
|
29
|
+
REDIS_HOST: redis
|
30
|
+
REDIS_PORT: 6379
|
24
31
|
|
25
32
|
release:
|
26
33
|
if: startsWith(github.ref, 'refs/tags/v')
|
@@ -28,7 +35,7 @@ jobs:
|
|
28
35
|
runs-on: ubuntu-latest
|
29
36
|
steps:
|
30
37
|
- uses: actions/checkout@v2
|
31
|
-
- name:
|
38
|
+
- name: Setup
|
32
39
|
uses: actions/setup-ruby@v1
|
33
40
|
with:
|
34
41
|
ruby-version: 2.6.x
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Twitch::Bot
|
2
2
|
|
3
|
+
![](https://github.com/geewiz/twitch-bot/workflows/Ruby%20Gem/badge.svg)
|
4
|
+
|
3
5
|
`twitch-bot` provides a Twitch chat client object that can be used for building Twitch chat bots.
|
4
6
|
|
5
7
|
This gem is based on [`twitch-chat`](https://github.com/EnotPoloskun/twitch-chat).
|
data/docker-compose.yml
ADDED
data/lib/twitch/bot.rb
CHANGED
@@ -13,6 +13,7 @@ require_relative "bot/message"
|
|
13
13
|
require_relative "bot/irc_message"
|
14
14
|
require_relative "bot/message_parser"
|
15
15
|
require_relative "bot/memory/hash"
|
16
|
+
require_relative "bot/memory/redis"
|
16
17
|
require_relative "bot/channel"
|
17
18
|
require_relative "bot/adapter/irc"
|
18
19
|
require_relative "bot/adapter/terminal"
|
data/lib/twitch/bot/client.rb
CHANGED
@@ -34,7 +34,7 @@ module Twitch
|
|
34
34
|
setup_logging
|
35
35
|
|
36
36
|
memory_class = config.setting("memory") || "Twitch::Bot::Memory::Hash"
|
37
|
-
@memory = Object.const_get(memory_class).new
|
37
|
+
@memory = Object.const_get(memory_class).new(client: self)
|
38
38
|
|
39
39
|
adapter_class = config.setting("adapter") || "Twitch::Bot::Adapter::Irc"
|
40
40
|
@adapter = Object.const_get(adapter_class).new(client: self)
|
@@ -4,8 +4,10 @@ module Twitch
|
|
4
4
|
module Bot
|
5
5
|
# Manage a key/value store for our bot
|
6
6
|
module Memory
|
7
|
+
# Implement an ephemeral memory using a Hash
|
7
8
|
class Hash
|
8
|
-
def initialize
|
9
|
+
def initialize(client:)
|
10
|
+
@client = client
|
9
11
|
@kvstore = {}
|
10
12
|
end
|
11
13
|
|
@@ -19,7 +21,7 @@ module Twitch
|
|
19
21
|
|
20
22
|
private
|
21
23
|
|
22
|
-
attr_reader :kvstore
|
24
|
+
attr_reader :client, :kvstore
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "redis"
|
4
|
+
|
5
|
+
module Twitch
|
6
|
+
module Bot
|
7
|
+
module Memory
|
8
|
+
# Implement persistent memory based on Redis
|
9
|
+
class Redis
|
10
|
+
def initialize(client:)
|
11
|
+
@client = client
|
12
|
+
@redis = connect_db
|
13
|
+
end
|
14
|
+
|
15
|
+
def store(key, value)
|
16
|
+
redis.set(key, value)
|
17
|
+
end
|
18
|
+
|
19
|
+
def retrieve(key)
|
20
|
+
redis.get(key)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :client, :redis
|
26
|
+
|
27
|
+
def connect_db
|
28
|
+
config = client.config
|
29
|
+
host = config.setting("redis_host") ||
|
30
|
+
ENV["REDIS_HOST"] || "localhost"
|
31
|
+
port = config.setting("redis_port") ||
|
32
|
+
ENV["REDIS_PORT"] || 6379
|
33
|
+
::Redis.new(host: host, port: port)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/twitch/bot/version.rb
CHANGED
@@ -14,7 +14,7 @@ RSpec.describe Twitch::Bot::Client do
|
|
14
14
|
)
|
15
15
|
end
|
16
16
|
|
17
|
-
describe "#
|
17
|
+
describe "#dispath" do
|
18
18
|
it "responds to a Ping message" do
|
19
19
|
ping_message_fake = Struct.new(:type, :hostname, :user)
|
20
20
|
message = ping_message_fake.new(:ping, "test.twitch", nil)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Twitch::Bot::Memory::Redis do
|
4
|
+
describe "#store" do
|
5
|
+
it "persists a value for a key" do
|
6
|
+
config = Twitch::Bot::Config.new(
|
7
|
+
settings: {
|
8
|
+
bot_user: "testuser",
|
9
|
+
},
|
10
|
+
)
|
11
|
+
client = Twitch::Bot::Client.new(
|
12
|
+
config: config,
|
13
|
+
channel: "testchannel",
|
14
|
+
)
|
15
|
+
mem = described_class.new(client: client)
|
16
|
+
|
17
|
+
mem.store("foo", "bar")
|
18
|
+
|
19
|
+
expect(mem.retrieve("foo")).to eq "bar"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/twitch-bot.gemspec
CHANGED
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
|
25
|
+
spec.add_dependency "redis", "~> 4.1"
|
26
|
+
|
25
27
|
spec.add_development_dependency "bundler", "~> 2.0"
|
26
28
|
spec.add_development_dependency "freistil-rubocop"
|
27
29
|
spec.add_development_dependency "guard", "~> 2.16"
|
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: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jochen Lillich
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2020-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.1'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -187,6 +201,7 @@ files:
|
|
187
201
|
- LICENSE.txt
|
188
202
|
- README.md
|
189
203
|
- Rakefile
|
204
|
+
- docker-compose.yml
|
190
205
|
- lib/twitch/bot.rb
|
191
206
|
- lib/twitch/bot/adapter/irc.rb
|
192
207
|
- lib/twitch/bot/adapter/terminal.rb
|
@@ -199,6 +214,7 @@ files:
|
|
199
214
|
- lib/twitch/bot/irc_message.rb
|
200
215
|
- lib/twitch/bot/logger.rb
|
201
216
|
- lib/twitch/bot/memory/hash.rb
|
217
|
+
- lib/twitch/bot/memory/redis.rb
|
202
218
|
- lib/twitch/bot/message.rb
|
203
219
|
- lib/twitch/bot/message/user_message.rb
|
204
220
|
- lib/twitch/bot/message_parser.rb
|
@@ -207,6 +223,7 @@ files:
|
|
207
223
|
- spec/twitch/bot/client_spec.rb
|
208
224
|
- spec/twitch/bot/config_spec.rb
|
209
225
|
- spec/twitch/bot/memory/hash_spec.rb
|
226
|
+
- spec/twitch/bot/memory/redis_spec.rb
|
210
227
|
- spec/twitch/bot/message/user_message_spec.rb
|
211
228
|
- spec/twitch/bot/message_parser_spec.rb
|
212
229
|
- twitch-bot.gemspec
|
@@ -239,5 +256,6 @@ test_files:
|
|
239
256
|
- spec/twitch/bot/client_spec.rb
|
240
257
|
- spec/twitch/bot/config_spec.rb
|
241
258
|
- spec/twitch/bot/memory/hash_spec.rb
|
259
|
+
- spec/twitch/bot/memory/redis_spec.rb
|
242
260
|
- spec/twitch/bot/message/user_message_spec.rb
|
243
261
|
- spec/twitch/bot/message_parser_spec.rb
|