Discord_Elixir_test/lib/events/messages.ex

28 lines
847 B
Elixir
Raw Normal View History

2024-10-12 17:06:08 +02:00
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.
2024-10-12 17:06:08 +02:00
"""
use Nostrum.Consumer
2024-10-12 17:57:24 +02:00
def handle_event({:MESSAGE_CREATE, msg, ws_state}) when msg.author.bot != true do
2024-10-12 21:11:27 +02:00
prefix = Application.get_env(:nostrum, :prefix)
if String.starts_with?(msg.content, prefix) do
msg.content
2024-10-12 21:11:27 +02:00
|> String.replace(prefix, "")
2024-10-12 17:06:08 +02:00
|> String.split(" ")
|> Enum.at(0)
|> String.downcase()
|> String.capitalize()
|> then(& Module.concat(HahaYes.Commands, &1).execute(msg, ws_state, String.split(String.replace(msg.content, "h3h3 download ", ""))))
2024-10-12 17:06:08 +02:00
end
end
end