Skip to content

Commit 7e48d86

Browse files
Improve default logging. Add resubs
1 parent 462e82f commit 7e48d86

16 files changed

Lines changed: 164 additions & 34 deletions

File tree

lib/tmi.ex

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ defmodule TMI do
137137

138138
@impl TMI.Handler
139139
def handle_kick(channel, user, kicker) do
140-
Logger.debug("[#{TMI.bot_string(__MODULE__)}] [#{channel}] #{user} was kicked by #{kicker}")
140+
Logger.debug(
141+
"[#{TMI.bot_string(__MODULE__)}] [#{channel}] #{user} was kicked by #{kicker}"
142+
)
141143
end
142144

143145
@impl TMI.Handler
@@ -152,7 +154,9 @@ defmodule TMI do
152154

153155
@impl TMI.Handler
154156
def handle_mention(message, sender, channel) do
155-
Logger.debug("[#{TMI.bot_string(__MODULE__)}] [#{channel}] MENTION - <#{sender}> #{message}")
157+
Logger.debug(
158+
"[#{TMI.bot_string(__MODULE__)}] [#{channel}] MENTION - <#{sender}> #{message}"
159+
)
156160
end
157161

158162
@impl TMI.Handler
@@ -172,7 +176,9 @@ defmodule TMI do
172176

173177
@impl TMI.Handler
174178
def handle_unrecognized(msg) do
175-
Logger.debug("[#{TMI.bot_string(__MODULE__)}] UNRECOGNIZED: #{inspect(msg, pretty: true)}")
179+
Logger.debug(
180+
"[#{TMI.bot_string(__MODULE__)}] UNRECOGNIZED: #{inspect(msg, pretty: true)}"
181+
)
176182
end
177183

178184
defoverridable(
@@ -205,17 +211,25 @@ defmodule TMI do
205211

206212
@doc false
207213
def default_handle_event(%TMI.Events.Message{} = event, module) do
208-
Logger.debug("[#{bot_string(module)}] [#{event.channel}] <#{event.user_login}> #{event.message}")
214+
Logger.debug(
215+
"[#{bot_string(module)}] [#{event.channel}] <#{event.user_login}> #{event.message}"
216+
)
209217
end
210218

211219
def default_handle_event(%TMI.Events.ChatAction{} = event, module) do
212-
Logger.debug("[#{bot_string(module)}] [#{event.channel}] * <#{event.user_id}> #{event.message}")
220+
Logger.debug(
221+
"[#{bot_string(module)}] [#{event.channel}] * <#{event.user_id}> #{event.message}"
222+
)
213223
end
214224

215225
def default_handle_event(%TMI.Events.Whisper{} = event, module) do
216226
Logger.debug("[#{bot_string(module)}] WHISPER - <#{event.user_login}> #{event.message}")
217227
end
218228

229+
def default_handle_event(%TMI.Events.Unrecognized{msg: %ExIRC.Message{} = msg}, module) do
230+
Logger.debug("[#{bot_string(module)}] [#{msg.cmd}] #{inspect(msg.args)}")
231+
end
232+
219233
def default_handle_event(event, module) do
220234
Logger.debug("[#{bot_string(module)}] EVENT\n#{inspect(event, pretty: true)}")
221235
end
@@ -353,6 +367,11 @@ defmodule TMI do
353367
params ->
354368
tag_string
355369
|> TMI.IRC.Tags.parse!()
370+
|> tap(fn tags ->
371+
if Map.get(tags, "custom-reward-id") do
372+
IO.inspect(msg, pretty: true)
373+
end
374+
end)
356375
|> TMI.Event.from_map_with_name(:message, params)
357376
end
358377

lib/tmi/events/channel_update.ex

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ defmodule TMI.Events.ChannelUpdate do
22
@moduledoc """
33
When we get a ROOMSTATE notice in IRC or a chat settings update from EventSub.
44
"""
5-
use TMI.Event, fields: [
6-
# TODO: Follower-only, sub-only, slow-mode, unique (is that r9k?)?
7-
:emote_only?,
8-
:channel_id,
9-
:channel
10-
]
5+
use TMI.Event,
6+
fields: [
7+
:emote_only?,
8+
:followers_only?,
9+
:unique_only?,
10+
:subs_only?,
11+
:slow_delay,
12+
:channel_id,
13+
:channel
14+
]
1115
end

lib/tmi/events/emote_mode.ex

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
defmodule TMI.Events.EmoteMode do
22
@moduledoc false
3-
use TMI.Event, fields: [
4-
:channel,
5-
:emote_only?
6-
]
3+
use TMI.Event,
4+
fields: [
5+
:channel,
6+
:emote_only?
7+
]
78
end

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,

0 commit comments

Comments
 (0)