Described in doc what happens and replaced "apply" with "Module.concat"

This commit is contained in:
Loïc Bersier 2024-10-12 21:30:30 +02:00
parent 95d6cc17b5
commit c0dba0633b

View file

@ -1,6 +1,13 @@
defmodule HahaYes.Events.MessagesConsumer do
@moduledoc """
Parse messages to execute commands
1. Remove the prefix from the message.
2. Split the messages by spaces
3. Get the first result
4. Make it all lowercase
5. Make the first letter capitalized.
6. Call the execute function on the command.
"""
use Nostrum.Consumer
@ -8,13 +15,13 @@ defmodule HahaYes.Events.MessagesConsumer do
def handle_event({:MESSAGE_CREATE, msg, ws_state}) when msg.author.bot != true do
prefix = Application.get_env(:nostrum, :prefix)
if String.starts_with?(msg.content, prefix) do
msg.content
msg.content
|> String.replace(prefix, "")
|> String.split(" ")
|> Enum.at(0)
|> String.downcase()
|> String.capitalize()
|> then(& apply(String.to_atom("#{HahaYes.Commands}.#{&1}"), :execute, [msg, ws_state, String.split(String.replace(msg.content, "h3h3 download ", ""))]))
|> then(& Module.concat(HahaYes.Commands, &1).execute(msg, ws_state, String.split(String.replace(msg.content, "h3h3 download ", ""))))
end
end
end