Skip to content

Commit 6df2317

Browse files
Improve default logging. Add resubs
1 parent 462e82f commit 6df2317

12 files changed

Lines changed: 73 additions & 15 deletions

File tree

lib/tmi.ex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ defmodule TMI do
216216
Logger.debug("[#{bot_string(module)}] WHISPER - <#{event.user_login}> #{event.message}")
217217
end
218218

219+
def default_handle_event(%TMI.Events.Unrecognized{msg: %ExIRC.Message{} = msg}, module) do
220+
Logger.debug("[#{bot_string(module)}] [#{msg.cmd}] #{inspect(msg.args)}")
221+
end
222+
219223
def default_handle_event(event, module) do
220224
Logger.debug("[#{bot_string(module)}] EVENT\n#{inspect(event, pretty: true)}")
221225
end
@@ -353,6 +357,11 @@ defmodule TMI do
353357
params ->
354358
tag_string
355359
|> TMI.IRC.Tags.parse!()
360+
|> tap(fn tags ->
361+
if Map.get(tags, "custom-reward-id") do
362+
IO.inspect(msg, pretty: true)
363+
end
364+
end)
356365
|> TMI.Event.from_map_with_name(:message, params)
357366
end
358367

lib/tmi/events/channel_update.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ defmodule TMI.Events.ChannelUpdate do
33
When we get a ROOMSTATE notice in IRC or a chat settings update from EventSub.
44
"""
55
use TMI.Event, fields: [
6-
# TODO: Follower-only, sub-only, slow-mode, unique (is that r9k?)?
76
:emote_only?,
7+
:followers_only?,
8+
:unique_only?,
9+
:subs_only?,
10+
:slow_delay,
811
:channel_id,
912
:channel
1013
]

lib/tmi/events/message.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ defmodule TMI.Events.Message do
2020
:timestamp,
2121
:user_id,
2222
:user_login,
23-
:user_type
23+
:user_type,
24+
:reward_id
2425
]
2526
end

lib/tmi/events/resub.ex

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
defmodule TMI.Events.Resub do
2+
@moduledoc """
3+
Sub event.
4+
IRC `msg-id` is `sub` and EventSub name is `sub`.
5+
"""
6+
use TMI.Event,
7+
fields: [
8+
:id,
9+
:channel_id,
10+
:channel,
11+
:plan,
12+
:plan_name,
13+
:system_message,
14+
:timestamp,
15+
:gifted?,
16+
:goal_type,
17+
:goal_current,
18+
:goal_target,
19+
:goal_contributions,
20+
:share_streak?,
21+
:months,
22+
:badge_info,
23+
:badges,
24+
:color,
25+
:cumulative_months,
26+
:login,
27+
:display_name,
28+
:is_mod?,
29+
:is_turbo?,
30+
:is_sub?,
31+
:is_vip?,
32+
:user_id,
33+
:user_type
34+
]
35+
end

lib/tmi/events/sub.ex

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ defmodule TMI.Events.Sub do
1919
:goal_contributions,
2020
:share_streak?,
2121
:months,
22-
# --- user fields ---
2322
:badge_info,
2423
:badges,
2524
:color,
@@ -31,10 +30,6 @@ defmodule TMI.Events.Sub do
3130
:is_sub?,
3231
:is_vip?,
3332
:user_id,
34-
:user_type,
35-
# --- recipient fields ---
36-
:recipient_display_name,
37-
:recipient_id,
38-
:recipient_login
33+
:user_type
3934
]
4035
end

lib/tmi/fields.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ defmodule TMI.Fields do
419419
Applies only to messages with more than 9 characters. Is `true` if users must
420420
post unique messages; otherwise, `false`.
421421
"""
422-
@type r9k? :: boolean()
422+
@type unique_only? :: boolean()
423423

424424
@typedoc """
425425
Twitch IRC tag `returning-chatter`.
@@ -609,6 +609,12 @@ defmodule TMI.Fields do
609609
"""
610610
@type is_vip? :: boolean()
611611

612+
@typedoc """
613+
[UNDOCUMENTED]
614+
Twitch IRC tag `custom-reward-id`. Got this in a message that was a custom reward.
615+
"""
616+
@type reward_id :: String.t()
617+
612618
## Unrecognized stuff...
613619

614620
@typedoc """

lib/tmi/handler.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule TMI.Handler do
55

66
## The common bits...
77

8-
@callback handle_event(TMI.event()) :: any
8+
@callback handle_event(event :: TMI.event()) :: any
99

1010
@callback handle_mention(message :: String.t(), sender :: String.t(), channel :: String.t()) ::
1111
any

lib/tmi/irc/parsing/event_mapping.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ defmodule TMI.IRC.Parsing.EventMapping do
2828
# "" => :sub,
2929
# "" => :sub_message,
3030
# "" => :sub_end,
31-
# "" => :resub,
31+
"resub" => :resub,
3232
# "" => :sub_gift,
3333
"submysterygift" => :community_sub_gift,
3434
"subgift" => :sub_gift,

lib/tmi/irc/parsing/tag_mapping.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ defmodule TMI.IRC.Parsing.TagMapping do
88
"bits" => :bits,
99
"client-nonce" => :client_nonce,
1010
"color" => :color,
11+
"custom-reward-id" => :reward_id,
1112
"display-name" => :display_name,
1213
"emotes" => :emotes,
1314
"emote-only" => :emote_only?,
@@ -69,7 +70,7 @@ defmodule TMI.IRC.Parsing.TagMapping do
6970
"pinned-chat-paid-exponent" => :exponent,
7071
"pinned-chat-paid-is-system-message" => :system_message?,
7172
"pinned-chat-paid-level" => :level,
72-
"r9k" => :r9k?,
73+
"r9k" => :unique_only?,
7374
"reply-parent-display-name" => :parent_user_display_name,
7475
"reply-parent-msg-body" => :parent_message,
7576
"reply-parent-msg-id" => :parent_id,

lib/tmi/irc/tags.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ defmodule TMI.IRC.Tags do
200200
{tag_name(key), String.to_integer(val)}
201201
end
202202

203+
defp tag_map({"slow" = key, val}) do
204+
{tag_name(key), String.to_integer(val)}
205+
end
206+
203207
defp tag_map({"user-type" = key, val}) do
204208
type =
205209
case val do
@@ -276,6 +280,10 @@ defmodule TMI.IRC.Tags do
276280
{tag_name(key), val == "1"}
277281
end
278282

283+
defp tag_map({"r9k" = key, val}) do
284+
{tag_name(key), val == "1"}
285+
end
286+
279287
defp tag_map({"msg-param-prior-gifter-anonymous" = key, val}) do
280288
{tag_name(key), val == "true"}
281289
end

0 commit comments

Comments
 (0)