rmcafee / discord_ex

Discord Elixir Library
MIT License
47 stars 13 forks source link

Proposal to make :guild_create event handler #45

Open tielur opened 6 years ago

tielur commented 6 years ago

Right now the library currently is handling the guild_create event inside of the library and not exposing it as with other events. From what I understand it's labeling these events as "static" events.

@static_events [:ready, :guild_create, :voice_state_update] source

def handle_event({:guild_create, payload}, state) do

    guild = %{guild_id: payload.data[:id],
              voice_states: payload.data[:voice_states]}
    new_guilds = state[:guilds] ++ [guild]
    new_state = Map.merge(state, %{guilds: new_guilds})

    {:ok, new_state}
  end

source

There might be a good reason to expose this as a public event. The guild_create event has some good information in it that we are currently throwing away. For example a list of members for that guild. I don't think we should stick all of the data into the state, for obvious reasons but it would be nice to be able to at least let the user of the library ( and their bot ) decide what information they need.

Right now the library requires that at least the list of guilds is a part of the gen server state. What do you think about continuing to add the guilds to the state but then also calling out and passing the payload to a guild_create event that the user of the library (and their bot) can hook into?

I'm more then happy to open a PR with this but I wanted to start a conversation first.