From c0dba0633bafe4b6f381cf90f0fd06b79ae772fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bersier?= Date: Sat, 12 Oct 2024 21:30:30 +0200 Subject: [PATCH] Described in doc what happens and replaced "apply" with "Module.concat" --- lib/events/messages.ex | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/events/messages.ex b/lib/events/messages.ex index 846544b..ab71328 100644 --- a/lib/events/messages.ex +++ b/lib/events/messages.ex @@ -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