@@ -217,7 +217,7 @@ defmodule TMI do
217217 end
218218
219219 def default_handle_event ( event , module ) do
220- Logger . debug ( "[#{ bot_string ( module ) } ] [ #{ event . channel } ] EVENT\n #{ inspect ( event , pretty: true ) } " )
220+ Logger . debug ( "[#{ bot_string ( module ) } ] EVENT\n #{ inspect ( event , pretty: true ) } " )
221221 end
222222
223223 @ doc """
@@ -284,6 +284,36 @@ defmodule TMI do
284284 % { channel: channel }
285285 end
286286
287+ @ doc """
288+ Parse a NOTICE message.
289+
290+ ## Example:
291+
292+ iex> args = "tmi.twitch.tv NOTICE #ryanwinchester_ :This room is no longer in emote-only mode."
293+ iex> notice_args_to_map(args)
294+ %{channel: "#ryanwinchester_"}
295+
296+ """
297+ def notice_args_to_map ( message ) do
298+ [ _server , notice ] = :binary . split ( message , " NOTICE " )
299+ [ channel , _rest ] = :binary . split ( notice , " :" )
300+ % { channel: channel }
301+ end
302+
303+ @ doc """
304+ Parse a ROOMSTATE message.
305+
306+ ## Example:
307+
308+ iex> roomstate_args_to_map("tmi.twitch.tv ROOMSTATE #ryanwinchester_")
309+ %{channel: "#ryanwinchester_"}
310+
311+ """
312+ def roomstate_args_to_map ( message ) do
313+ [ _server , channel ] = :binary . split ( message , " ROOMSTATE " )
314+ % { channel: channel }
315+ end
316+
287317 @ doc """
288318 Parse Twitch tags, if they are enabled.
289319
@@ -304,17 +334,11 @@ defmodule TMI do
304334 # Convert the ExIRC message to bot message.
305335 # ----------------------------------------------------------------------------
306336
307- # def parse_message(message) do
308- # ed
309-
310- ## WITH tags
311-
312337 # TODO: I think I will want to recursively parse the message args until I get
313338 # one of the `PRIVMSG`, `USERNOTICE`, etc. messages.
314339 # As it is now, if we get a message or system_msg or anything that has this
315340 # text, we could get unexpected results since `String.contains?/2` could match.
316- @ doc false
317- def apply_incoming_to_bot ( { :unrecognized , tag_string , % ExIRC.Message { args: [ arg ] } } , bot ) do
341+ def parse_message ( { :unrecognized , tag_string , % ExIRC.Message { args: [ arg ] } = msg } ) do
318342 cond do
319343 String . contains? ( arg , "PRIVMSG" ) ->
320344 case message_args_to_map ( arg ) do
@@ -325,34 +349,51 @@ defmodule TMI do
325349 params
326350 | message: String . trim_trailing ( message , << 0x01 >> )
327351 } )
328- |> bot . handle_event ( )
329352
330353 params ->
331354 tag_string
332355 |> TMI.IRC.Tags . parse! ( )
333356 |> TMI.Event . from_map_with_name ( :message , params )
334- |> bot . handle_event ( )
335357 end
336358
337359 String . contains? ( arg , "USERNOTICE" ) ->
338360 tag_string
339361 |> TMI.IRC.Tags . parse! ( )
340362 |> TMI.Event . from_map ( usernotice_args_to_map ( arg ) )
341- |> bot . handle_event ( )
363+
364+ String . contains? ( arg , "NOTICE" ) ->
365+ tag_string
366+ |> TMI.IRC.Tags . parse! ( )
367+ |> TMI.Event . from_map ( notice_args_to_map ( arg ) )
368+
369+ String . contains? ( arg , "ROOMSTATE" ) ->
370+ tag_string
371+ |> TMI.IRC.Tags . parse! ( )
372+ |> TMI.Event . from_map_with_name ( :channel_update , roomstate_args_to_map ( arg ) )
342373
343374 String . contains? ( arg , "WHISPER" ) ->
344375 tag_string
345376 |> TMI.IRC.Tags . parse! ( )
346377 |> TMI.Event . from_map_with_name ( :whisper , whisper_args_to_map ( arg ) )
347- |> bot . handle_event ( )
348378
349379 true ->
350380 tag_string
351381 |> TMI.IRC.Tags . parse! ( )
352- |> bot . handle_unrecognized ( arg )
382+ |> TMI.Event . from_map_with_name ( :unrecognized , % { msg: msg } )
353383 end
354384 end
355385
386+ def parse_message ( { :unrecognized , _cmd , % ExIRC.Message { } = msg } ) do
387+ TMI.Event . from_map_with_name ( % { } , :unrecognized , % { msg: msg } )
388+ end
389+
390+ ## WITH tags
391+
392+ @ doc false
393+ def apply_incoming_to_bot ( { :unrecognized , _tag_string , % ExIRC.Message { } } = msg , bot ) do
394+ parse_message ( msg ) |> bot . handle_event ( )
395+ end
396+
356397 ## Without tags
357398
358399 def apply_incoming_to_bot ( { :connected , server , port } , bot ) do
0 commit comments