Adding event structs and the handle_event/1 callback.
All the other handle_* functions will be deprecated (but still work). Eventually they will be removed in future version, but should not be soon.
Every message we get from twitch chat will be converted to an event struct.
Then, instead of handle_message, handle_action, handle_join, handle_foo, handle_bar,..., ... it will be just one function (handle_event/1), and you match on the event structs you care about.
Example:
alias TMI.Events
def handle_event(%Events.Message{} = msg) do
# do stuff with messages
end
def handle_event(%Events.Resub{} = resub)do
# do stuff with resubs
end
def handle_event(_) do
# NO-OP: don't care about any more
:ok
end
The nice thing is you won't need a bunch of different functions with a different number of args for each, it's one function with one event struct argument and they have all the relevant info you'd want in the struct with a type definition (incoming).
Example:
defmodule TMI.Events.Resub do
defstruct [:channel, :message, :total_months, :streak_months, :plan, :plan_name, :tags]
end
Adding event structs and the
handle_event/1
callback.All the other
handle_*
functions will be deprecated (but still work). Eventually they will be removed in future version, but should not be soon.Every message we get from twitch chat will be converted to an event struct. Then, instead of
handle_message
,handle_action
,handle_join
,handle_foo
,handle_bar
,..., ... it will be just one function (handle_event/1
), and you match on the event structs you care about.Example:
The nice thing is you won't need a bunch of different functions with a different number of args for each, it's one function with one event struct argument and they have all the relevant info you'd want in the struct with a type definition (incoming).
Example: