Skip to content

Commit 8e0c156

Browse files
Merge pull request #4 from taylorfinnell/fixes-for-new-messages
fixes for new message data
2 parents 404e9fa + 9af3fc2 commit 8e0c156

File tree

6 files changed

+1220
-14
lines changed

6 files changed

+1220
-14
lines changed

shard.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: hqtrivia
2-
version: 0.2.0
2+
version: 0.2.2
33

44
authors:
55
- Taylor Finnell <[email protected]>
66

7-
crystal: 0.24.2
7+
crystal: 0.26.0
88

99
license: MIT
1010

spec/data/new_messages

+1,201
Large diffs are not rendered by default.

spec/hqtrivia/bot_spec.cr

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ end
2121
module HqTrivia
2222
describe Bot do
2323
it "works" do
24-
messages = File.read("./spec/data/fullgame").each_line.to_a
24+
messages = File.read("./spec/data/new_messages").each_line.to_a
2525
show = Model::Show.new(active: true, show_type: "hq-us", prize: 100, show_id: 666, start_time: Time.now)
2626
connection = Connection::Local.new(messages)
2727

2828
bot = MyBot.new(show, LocalCoordinator.new("us"))
2929
bot.play(connection)
3030

31-
bot.words.values.max.should eq(328)
31+
bot.words.values.max.should eq(70)
3232
bot.start_time.should eq(show.start_time)
3333
bot.show_id.should eq(show.show_id)
3434
bot.prize.should eq(show.prize)

src/hqtrivia/model/interaction.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module HqTrivia
1919
user_id: {key: "userId", type: Int32},
2020
message: String,
2121
avatar_url: {key: "avatarUrl", type: String?},
22-
interaction: String,
22+
interaction: String?,
2323
username: String,
2424
})
2525
end

src/hqtrivia/model/raw_web_socket_message.cr

+13-8
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@ module HqTrivia
99
})
1010

1111
macro decode(json)
12-
decoded = {{@type}}.from_json({{json}})
13-
case decoded.type
14-
{% for msg, index in Model::MessageTypes.constant("MESSAGE_LIST") %}
15-
when {{msg}}
16-
Model::{{msg.camelcase.id}}.from_json({{json}})
17-
{% end %}
18-
else
19-
Model::UnknownMessage.new({{json}}, Time.utc_now)
12+
begin
13+
decoded = {{@type}}.from_json({{json}})
14+
case decoded.type
15+
{% for msg, index in Model::MessageTypes.constant("MESSAGE_LIST") %}
16+
when {{msg}}
17+
Model::{{msg.camelcase.id}}.from_json({{json}})
18+
{% end %}
19+
else
20+
Model::UnknownMessage.new({{json}}, Time.utc_now)
21+
end
22+
rescue jme : JSON::MappingError
23+
HqTrivia.logger.error("Failed to parse json: #{{{json}}}")
24+
raise jme
2025
end
2126
end
2227
end

src/hqtrivia/version.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module HqTrivia
22
# Current HqTrivia version
3-
VERSION = "0.2.0"
3+
VERSION = "0.2.2"
44
end

0 commit comments

Comments
 (0)