cronokirby / alchemy

A discord library for Elixir
MIT License
152 stars 34 forks source link

[feature | breaking] Better events API #71

Open curz46 opened 5 years ago

curz46 commented 5 years ago

Overview

Current Alchemy.Events usage:

Events.on_user_ban(:handler)
def handler(user, guild) do
  ...
end

Suggested usage:

Events.on_user_ban(:handler)
def handler(event = %UserBanEvent{}) do
  %{guild: guild, user: user} = event
  ...
end

Description

All Events.on_*** functions would have their handler function changed from (arg1, arg2, arg3, ... -> any) to (event -> any) where event is a named struct for the specific event e.g. %UserBanEvent{guild: guild, user: user}.

Justification

The current usage is non-intuitive and awkward to use:

Advantages to the suggested usage:

Dylan