Commit 2b08fd06 authored by Peter van der meulen's avatar Peter van der meulen

More feedback

parent 06e2aee9
......@@ -73,23 +73,41 @@ defmodule SnugglesApp.Accounts do
def handle_user_auth_request(%{
"level" => _,
"author_id" => author_id,
"channel_id" => _,
"channel_id" => channel_id,
"content" => content,
"mentions" => _
}) do
case Regex.run(~r/!auth-(.+?)$/, content) do
nil ->
{:ok, reply} =
Discord.send_message(
"Hey <@#{author_id}>, something looks wrong with your code, please contact leadership if this happens again",
channel_id
)
spawn(fn -> remove_message(reply) end)
Logger.info("Account unmatched auth req: #{content}")
extracted_content ->
link_discord_to_user(List.last(extracted_content), author_id)
{:ok, reply} =
Discord.send_message(
"Hey <@#{author_id}>, Thanks!! I will run some checks, change your display name and give you access to our member channels if you should have access",
channel_id
)
spawn(fn -> remove_message(reply) end)
link_discord_to_user(List.last(extracted_content), author_id, channel_id)
end
end
defp link_discord_to_user(auth_token, author_id) do
defp link_discord_to_user(auth_token, author_id, channel_id) do
case Repo.one(from(u in User, where: u.auth_token == ^auth_token and is_nil(u.discord_id))) do
nil ->
Logger.info("No account found for token")
{:ok, reply} =
Discord.send_message(
"Hey <@#{author_id}>, It looks like your token is faulty, or you have already registered. Please try again",
channel_id
)
spawn(fn -> remove_message(reply) end)
user ->
{:ok, _} =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment