Described in doc what happens and replaced "apply" with "Module.concat"
This commit is contained in:
parent
95d6cc17b5
commit
c0dba0633b
1 changed files with 9 additions and 2 deletions
|
@ -1,6 +1,13 @@
|
||||||
defmodule HahaYes.Events.MessagesConsumer do
|
defmodule HahaYes.Events.MessagesConsumer do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Parse messages to execute commands
|
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
|
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
|
def handle_event({:MESSAGE_CREATE, msg, ws_state}) when msg.author.bot != true do
|
||||||
prefix = Application.get_env(:nostrum, :prefix)
|
prefix = Application.get_env(:nostrum, :prefix)
|
||||||
if String.starts_with?(msg.content, prefix) do
|
if String.starts_with?(msg.content, prefix) do
|
||||||
msg.content
|
msg.content
|
||||||
|> String.replace(prefix, "")
|
|> String.replace(prefix, "")
|
||||||
|> String.split(" ")
|
|> String.split(" ")
|
||||||
|> Enum.at(0)
|
|> Enum.at(0)
|
||||||
|> String.downcase()
|
|> String.downcase()
|
||||||
|> String.capitalize()
|
|> 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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue