mirror of
https://github.com/ash-project/ash_hq.git
synced 2024-09-20 05:13:23 +12:00
fix: make listener do private responses, fix urls
This commit is contained in:
parent
f603bb6a0d
commit
1231fd1b95
1 changed files with 26 additions and 7 deletions
|
@ -4,7 +4,7 @@ defmodule AshHq.Discord.Listener do
|
||||||
"""
|
"""
|
||||||
use Nostrum.Consumer
|
use Nostrum.Consumer
|
||||||
|
|
||||||
# alias Nostrum.Api
|
import Bitwise
|
||||||
|
|
||||||
def start_link do
|
def start_link do
|
||||||
Consumer.start_link(__MODULE__)
|
Consumer.start_link(__MODULE__)
|
||||||
|
@ -75,8 +75,6 @@ defmodule AshHq.Discord.Listener do
|
||||||
"all libraries"
|
"all libraries"
|
||||||
end
|
end
|
||||||
|
|
||||||
url = AshHqWeb.Endpoint.url()
|
|
||||||
|
|
||||||
if item_list do
|
if item_list do
|
||||||
item_list = Enum.take(item_list, 10)
|
item_list = Enum.take(item_list, 10)
|
||||||
|
|
||||||
|
@ -92,25 +90,39 @@ defmodule AshHq.Discord.Listener do
|
||||||
"""
|
"""
|
||||||
Found #{count} #{result_type} in #{library}:
|
Found #{count} #{result_type} in #{library}:
|
||||||
|
|
||||||
#{Enum.map_join(item_list, "\n", &render_search_result(&1, url))}
|
#{Enum.map_join(item_list, "\n", &render_search_result(&1))}
|
||||||
"""
|
"""
|
||||||
else
|
else
|
||||||
"Something went wrong."
|
"Something went wrong."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp render_search_result(item, url) do
|
defp render_search_result(item) do
|
||||||
link = Path.join(url, AshHqWeb.DocRoutes.doc_link(item))
|
link = Path.join("https://ash-hq.org", AshHqWeb.DocRoutes.doc_link(item))
|
||||||
|
|
||||||
"* #{item.name}: #{link}"
|
"* #{item.name}: #{link}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_event({:INTERACTION_CREATE, %Nostrum.Struct.Interaction{} = interaction, _ws_state}) do
|
def handle_event({:INTERACTION_CREATE, %Nostrum.Struct.Interaction{} = interaction, _ws_state}) do
|
||||||
|
public? =
|
||||||
|
interaction.data.options
|
||||||
|
|> Enum.find_value(fn option ->
|
||||||
|
if option.name == "public" do
|
||||||
|
option.value
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
response = %{
|
response = %{
|
||||||
# ChannelMessageWithSource
|
# ChannelMessageWithSource
|
||||||
type: 4,
|
type: 4,
|
||||||
data: %{
|
data: %{
|
||||||
content: search_results!(interaction)
|
content: search_results!(interaction),
|
||||||
|
flags:
|
||||||
|
if public? do
|
||||||
|
0
|
||||||
|
else
|
||||||
|
1 <<< 6
|
||||||
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,6 +198,13 @@ defmodule AshHq.Discord.Listener do
|
||||||
value: name
|
value: name
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
# ApplicationCommandType::STRING
|
||||||
|
type: 5,
|
||||||
|
name: "public",
|
||||||
|
description: "If the results should be shown publicly in the channel",
|
||||||
|
required: false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue