Commit 0754898d authored by Peter van der meulen's avatar Peter van der meulen

rerun test

parent 8baffd58
......@@ -67,11 +67,11 @@ defmodule SnugglesApp.Accounts do
|> Repo.insert()
end
def handle_user_auth_request(%{"level" => _, "author_id" => author_id, "channel_id" => _, "content" => content}) do
def handle_user_auth_request(%{"level" => _, "author_id" => author_id, "channel_id" => _, "content" => content, "mentions" => _}) do
case Regex.run(~r/!auth-(.+?)$/, content) do
nil ->
Logger.info("Account unmatched auth req: #{content}")
extracted_content ->
extracted_content ->
link_discord_to_user(List.last(extracted_content), author_id)
end
end
......@@ -79,7 +79,7 @@ defmodule SnugglesApp.Accounts do
defp link_discord_to_user(auth_token, author_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")
user ->
user ->
{:ok, _} = update_user(user, %{
auth_token: nil,
discord_id: Integer.to_string(author_id)
......@@ -150,11 +150,12 @@ defmodule SnugglesApp.Accounts do
{:ok}
"""
def handle_admin_request(%{"author_id" => author_id, "content" => content} = _payload) do
def handle_admin_request(%{"author_id" => author_id, "content" => content, "mentions" => mentions} = _payload) do
case String.downcase(content) do
"help" -> Discord.send_admin_help_message(author_id)
"help" -> Discord.send_admin_help_message(author_id)
"add corp discord" -> send_admin_corp_creation_help_message(author_id)
_ -> Discord.send_admin_fallback_message(author_id)
"rerun " <> _ -> force_user_update(mentions)
_ -> Discord.send_admin_fallback_message(author_id)
end
end
......@@ -163,6 +164,18 @@ defmodule SnugglesApp.Accounts do
Discord.send_admin_corp_help_message(author_id, user)
end
defp force_user_update([nil | _]), do: Discord.send_message_to_admin("No user mentioned")
defp force_user_update([discord_user | _]) do
case Repo.get_by(User, discord_id: Integer.to_string(discord_user["id"])) do
nil ->
Discord.send_message_to_admin("User is fully unauthed already")
user ->
update_user(user, %{access: nil})
SnugglesApp.RabbitService.publish_json("account.events", %{"user_id" => user.id})
Discord.send_message_to_admin("User <@#{user.discord_id}>: scheduled to update" )
end
end
@doc """
Creates corporation
......@@ -180,7 +193,7 @@ defmodule SnugglesApp.Accounts do
end
cond do
user == nil ->
user == nil ->
Discord.send_message("Hey <@#{object["author_id"]}>, You need to auth yourself in the alliance first", object["channel_id"])
corp != nil ->
Discord.send_message("Hey <@#{object["author_id"]}>, It looks like your corp is already registered with a discord server", object["channel_id"])
......
......@@ -16,7 +16,7 @@ defmodule SnugglesApp.Discord.PostWorker do
def handle_event({:MESSAGE_CREATE, {msg}, _ws_state}) do
cond do
msg.author.id == @snuggles_id ->
msg.author.id == @snuggles_id ->
{:ok, "ignore"}
msg.channel_id == @auth_channel_id && msg.content == "!auth-corp" ->
{:ok, _} = RabbitService.publish_json("account.events", strip_message(msg, "corp-member"))
......@@ -48,7 +48,7 @@ defmodule SnugglesApp.Discord.PostWorker do
defp corp_creation_message?(msg) do
to_snuggles?(msg.mentions) &&
msg.guild_id != @guild_id &&
Regex.run(~r/add corp/, msg.content) &&
Regex.run(~r/add corp/, msg.content) &&
Enum.count(msg.mention_roles) == 1
end
......@@ -64,7 +64,8 @@ defmodule SnugglesApp.Discord.PostWorker do
level: level,
author_id: msg.author.id,
channel_id: msg.channel_id,
content: msg.content
content: msg.content,
mentions: msg.mentions
}
end
......
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