twitch-bot 4.1.1 → 5.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{.env.dist → .env.sample} +0 -0
- data/CHANGELOG.md +14 -0
- data/lib/twitch/bot/adapter/irc.rb +7 -6
- data/lib/twitch/bot/client.rb +2 -2
- data/lib/twitch/bot/logger.rb +1 -1
- data/lib/twitch/bot/memory/redis.rb +8 -8
- data/lib/twitch/bot/message/user_message.rb +1 -1
- data/lib/twitch/bot/message.rb +13 -13
- data/lib/twitch/bot/version.rb +1 -1
- data/spec/twitch/bot/memory/hash_spec.rb +21 -0
- data/spec/twitch/bot/memory/redis_spec.rb +39 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e01b9b202dc484cc6f55788d1adc6cc7b6272c1bb3ff67fcb2e0615956ea761
|
4
|
+
data.tar.gz: d819d7d5be9b59fdbdf9bcb1ebb100272f79fcb8377a887ad3e4450aee3b437a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96ab9830ae76529ef3f8f92e9876fb043e01afa2f7d4ee354dae4014e377df3f3e427c1a6f54dfdb515e7b2ec0018416f39874420f74e5659f8d83453b2d293b
|
7
|
+
data.tar.gz: 16a25b0062f8a1066442305ffc54c6d9ed1b573bfc836f990830f6c075738c6438876da82bdc4caa0220e88f1fa5e1cbd64ab151e7479fadb4dba00378dbda28
|
data/{.env.dist → .env.sample}
RENAMED
File without changes
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Changelog Twitch::Bot
|
2
2
|
|
3
|
+
## v5.0.2
|
4
|
+
|
5
|
+
- [FIX] `PART` command caused a crash when not in a channel.
|
6
|
+
|
7
|
+
## v5.0.1
|
8
|
+
|
9
|
+
- [FIX] Environment variable `REDIS_URL` now has precedence over configuration
|
10
|
+
object values.
|
11
|
+
|
12
|
+
## v5.0.0
|
13
|
+
|
14
|
+
- [BREAKING] Complex values like arrays and hashes get serialized as JSON before
|
15
|
+
being stored in Redis.
|
16
|
+
|
3
17
|
## v4.1.1
|
4
18
|
|
5
19
|
- [NEW] `CommandHandler` by default responds to `:user_message` events.
|
@@ -9,6 +9,7 @@ module Twitch
|
|
9
9
|
class Irc
|
10
10
|
def initialize(client:)
|
11
11
|
@client = client
|
12
|
+
@channel = nil
|
12
13
|
|
13
14
|
open_socket
|
14
15
|
end
|
@@ -29,7 +30,7 @@ module Twitch
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def send_message(text)
|
32
|
-
privmsg = "PRIVMSG ##{channel.name} :#{text}"
|
33
|
+
privmsg = "PRIVMSG ##{@channel.name} :#{text}"
|
33
34
|
send_data(privmsg)
|
34
35
|
end
|
35
36
|
|
@@ -37,19 +38,19 @@ module Twitch
|
|
37
38
|
send_data_to_socket(data)
|
38
39
|
end
|
39
40
|
|
40
|
-
def join_channel(
|
41
|
-
@channel =
|
42
|
-
send_data "JOIN ##{channel.name}"
|
41
|
+
def join_channel(channel_object)
|
42
|
+
@channel = channel_object
|
43
|
+
send_data "JOIN ##{@channel.name}"
|
43
44
|
end
|
44
45
|
|
45
46
|
def part_channel
|
46
|
-
send_data "PART ##{channel.name}"
|
47
|
+
send_data "PART ##{@channel.name}" if @channel
|
47
48
|
@channel = nil
|
48
49
|
end
|
49
50
|
|
50
51
|
private
|
51
52
|
|
52
|
-
attr_reader :socket, :client
|
53
|
+
attr_reader :socket, :client
|
53
54
|
|
54
55
|
def open_socket
|
55
56
|
@socket = ::TCPSocket.new(
|
data/lib/twitch/bot/client.rb
CHANGED
@@ -11,7 +11,7 @@ module Twitch
|
|
11
11
|
# Represent the event triggered when quitting the client loop.
|
12
12
|
class StopEvent < Twitch::Bot::Event
|
13
13
|
def initialize
|
14
|
-
|
14
|
+
super(type: :stop)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -22,7 +22,7 @@ module Twitch
|
|
22
22
|
attr_reader :channel, :config, :memory
|
23
23
|
|
24
24
|
def initialize(
|
25
|
-
channel: nil,
|
25
|
+
config:, channel: nil, &block
|
26
26
|
)
|
27
27
|
@config = config
|
28
28
|
@channel = Twitch::Bot::Channel.new(channel) if channel
|
data/lib/twitch/bot/logger.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "redis"
|
4
|
+
require "json"
|
4
5
|
|
5
6
|
module Twitch
|
6
7
|
module Bot
|
@@ -13,11 +14,12 @@ module Twitch
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def store(key, value)
|
16
|
-
redis.set(key, value)
|
17
|
+
redis.set(key, value.to_json)
|
17
18
|
end
|
18
19
|
|
19
20
|
def retrieve(key)
|
20
|
-
redis.get(key)
|
21
|
+
value = redis.get(key)
|
22
|
+
JSON.parse(value)
|
21
23
|
end
|
22
24
|
|
23
25
|
private
|
@@ -25,17 +27,15 @@ module Twitch
|
|
25
27
|
attr_reader :client, :redis
|
26
28
|
|
27
29
|
def connect_db
|
28
|
-
url =
|
30
|
+
url = ENV["REDIS_URL"] || redis_config_url
|
29
31
|
::Redis.new(url: url)
|
30
32
|
end
|
31
33
|
|
32
34
|
def redis_config_url
|
33
35
|
config = client.config
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
"redis://#{host}:#{port}"
|
38
|
-
end
|
36
|
+
host = config.setting("redis_host") || "localhost"
|
37
|
+
port = config.setting("redis_port") || 6379
|
38
|
+
"redis://#{host}:#{port}"
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
data/lib/twitch/bot/message.rb
CHANGED
@@ -5,8 +5,8 @@ module Twitch
|
|
5
5
|
module Message
|
6
6
|
# This class is the abstract base class for IRC events.
|
7
7
|
class Base < Twitch::Bot::Event
|
8
|
-
def initialize(
|
9
|
-
|
8
|
+
def initialize(type: :unknown)
|
9
|
+
super(type: type)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -16,7 +16,7 @@ module Twitch
|
|
16
16
|
|
17
17
|
def initialize(message)
|
18
18
|
@message = message
|
19
|
-
|
19
|
+
super(type: :not_supported)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -26,7 +26,7 @@ module Twitch
|
|
26
26
|
|
27
27
|
def initialize(hostname:)
|
28
28
|
@hostname = hostname
|
29
|
-
|
29
|
+
super(type: :ping)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -37,21 +37,21 @@ module Twitch
|
|
37
37
|
def initialize(user:, mode:)
|
38
38
|
@user = user
|
39
39
|
@mode = mode
|
40
|
-
|
40
|
+
super(type: :mode)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
# This class stores the details of an Authenticated event.
|
45
45
|
class Authenticated < Base
|
46
46
|
def initialize
|
47
|
-
|
47
|
+
super(type: :authenticated)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
# This class stores the details of a Join event.
|
52
52
|
class Join < Base
|
53
53
|
def initialize
|
54
|
-
|
54
|
+
super(type: :join)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -61,7 +61,7 @@ module Twitch
|
|
61
61
|
|
62
62
|
def initialize(user:)
|
63
63
|
@user = user
|
64
|
-
|
64
|
+
super(type: :subscription)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -71,7 +71,7 @@ module Twitch
|
|
71
71
|
|
72
72
|
def initialize(user:)
|
73
73
|
@user = user
|
74
|
-
|
74
|
+
super(type: :login_failed)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -82,7 +82,7 @@ module Twitch
|
|
82
82
|
def initialize(status:, channel:)
|
83
83
|
@status = status
|
84
84
|
@channel = channel
|
85
|
-
|
85
|
+
super(type: :slow_mode)
|
86
86
|
end
|
87
87
|
|
88
88
|
def enabled?
|
@@ -96,7 +96,7 @@ module Twitch
|
|
96
96
|
|
97
97
|
def initialize(status:)
|
98
98
|
@status = status
|
99
|
-
|
99
|
+
super(type: :followers_only_mode)
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
@@ -107,7 +107,7 @@ module Twitch
|
|
107
107
|
def initialize(status:, channel:)
|
108
108
|
@status = status
|
109
109
|
@channel = channel
|
110
|
-
|
110
|
+
super(type: :subs_only_mode)
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
@@ -118,7 +118,7 @@ module Twitch
|
|
118
118
|
def initialize(status:, channel:)
|
119
119
|
@status = status
|
120
120
|
@channel = channel
|
121
|
-
|
121
|
+
super(type: :r9k_mode)
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
data/lib/twitch/bot/version.rb
CHANGED
@@ -9,5 +9,26 @@ RSpec.describe Twitch::Bot::Memory::Hash do
|
|
9
9
|
|
10
10
|
expect(mem.retrieve("foo")).to eq "bar"
|
11
11
|
end
|
12
|
+
|
13
|
+
it "persists an Array" do
|
14
|
+
mem = described_class.new(client: nil)
|
15
|
+
|
16
|
+
mem.store("foo", [1, 2])
|
17
|
+
|
18
|
+
result = mem.retrieve("foo")
|
19
|
+
expect(result).to be_an Array
|
20
|
+
expect(result[0]).to eq 1
|
21
|
+
expect(result[1]).to eq 2
|
22
|
+
end
|
23
|
+
|
24
|
+
it "persists a Hash" do
|
25
|
+
mem = described_class.new(client: nil)
|
26
|
+
|
27
|
+
mem.store("foo", { "bar" => "baz" })
|
28
|
+
|
29
|
+
result = mem.retrieve("foo")
|
30
|
+
expect(result).to be_a Hash
|
31
|
+
expect(result["bar"]).to eq "baz"
|
32
|
+
end
|
12
33
|
end
|
13
34
|
end
|
@@ -40,5 +40,44 @@ RSpec.describe Twitch::Bot::Memory::Redis do
|
|
40
40
|
|
41
41
|
expect(mem.retrieve("foo")).to eq "bar"
|
42
42
|
end
|
43
|
+
|
44
|
+
it "persists an Array" do
|
45
|
+
config = Twitch::Bot::Config.new(
|
46
|
+
settings: {
|
47
|
+
bot_user: "testuser",
|
48
|
+
},
|
49
|
+
)
|
50
|
+
client = Twitch::Bot::Client.new(
|
51
|
+
config: config,
|
52
|
+
channel: "testchannel",
|
53
|
+
)
|
54
|
+
mem = described_class.new(client: client)
|
55
|
+
|
56
|
+
mem.store("foo", [1, 2])
|
57
|
+
|
58
|
+
result = mem.retrieve("foo")
|
59
|
+
expect(result).to be_an Array
|
60
|
+
expect(result[0]).to eq 1
|
61
|
+
expect(result[1]).to eq 2
|
62
|
+
end
|
63
|
+
|
64
|
+
it "persists a Hash" do
|
65
|
+
config = Twitch::Bot::Config.new(
|
66
|
+
settings: {
|
67
|
+
bot_user: "testuser",
|
68
|
+
},
|
69
|
+
)
|
70
|
+
client = Twitch::Bot::Client.new(
|
71
|
+
config: config,
|
72
|
+
channel: "testchannel",
|
73
|
+
)
|
74
|
+
mem = described_class.new(client: client)
|
75
|
+
|
76
|
+
mem.store("foo", { "bar" => "baz" })
|
77
|
+
|
78
|
+
result = mem.retrieve("foo")
|
79
|
+
expect(result).to be_a Hash
|
80
|
+
expect(result["bar"]).to eq "baz"
|
81
|
+
end
|
43
82
|
end
|
44
83
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitch-bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jochen Lillich
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -174,7 +174,7 @@ extensions: []
|
|
174
174
|
extra_rdoc_files: []
|
175
175
|
files:
|
176
176
|
- ".editorconfig"
|
177
|
-
- ".env.
|
177
|
+
- ".env.sample"
|
178
178
|
- ".github/workflows/main.yml"
|
179
179
|
- ".gitignore"
|
180
180
|
- ".rspec"
|
@@ -221,7 +221,7 @@ homepage: https://github.com/geewiz/twitch-bot
|
|
221
221
|
licenses:
|
222
222
|
- MIT
|
223
223
|
metadata: {}
|
224
|
-
post_install_message:
|
224
|
+
post_install_message:
|
225
225
|
rdoc_options: []
|
226
226
|
require_paths:
|
227
227
|
- lib
|
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
237
|
version: '0'
|
238
238
|
requirements: []
|
239
239
|
rubygems_version: 3.0.3
|
240
|
-
signing_key:
|
240
|
+
signing_key:
|
241
241
|
specification_version: 4
|
242
242
|
summary: twitch-bot is a Twitch chat client that uses Twitch IRC that can be used
|
243
243
|
as a Twitch chat bot engine.
|