From 130e680739221ad5b33b82f8429da9fb59c7723e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Bersier?= <loic.bersier1@gmail.com>
Date: Sat, 12 Oct 2024 21:11:27 +0200
Subject: [PATCH] Use prefix from config

---
 config/config.example.exs | 3 ++-
 lib/events/messages.ex    | 7 ++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/config/config.example.exs b/config/config.example.exs
index ddea0e3..1e29cd7 100644
--- a/config/config.example.exs
+++ b/config/config.example.exs
@@ -8,4 +8,5 @@ config :nostrum,
     :guild_messages,
     :message_content,
     :guild_message_reactions
-  ]
+  ],
+  prefix: "haha "
diff --git a/lib/events/messages.ex b/lib/events/messages.ex
index a0007ee..846544b 100644
--- a/lib/events/messages.ex
+++ b/lib/events/messages.ex
@@ -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