Use prefix from config

This commit is contained in:
Loïc Bersier 2024-10-12 21:11:27 +02:00
parent dec96177f5
commit 130e680739
2 changed files with 6 additions and 4 deletions

View file

@ -8,4 +8,5 @@ config :nostrum,
:guild_messages,
:message_content,
:guild_message_reactions
]
],
prefix: "haha "

View file

@ -6,14 +6,15 @@ defmodule HahaYes.Events.MessagesConsumer do
use Nostrum.Consumer
def handle_event({:MESSAGE_CREATE, msg, ws_state}) when msg.author.bot != true do
if String.starts_with?(msg.content, "h3h3 ") do
prefix = Application.get_env(:nostrum, :prefix)
if String.starts_with?(msg.content, prefix) do
msg.content
|> String.replace("h3h3 ", "")
|> 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.replace(msg.content, "h3h3 download ", "")]))
|> then(& apply(String.to_atom("#{HahaYes.Commands}.#{&1}"), :execute, [msg, ws_state, String.split(String.replace(msg.content, "h3h3 download ", ""))]))
end
end
end