mirror of
https://codeberg.org/godmaire/sergei.git
synced 2024-09-20 00:08:25 +00:00
feat: switch to using global commands in prod
This commit is contained in:
parent
bad3ea3679
commit
c4834abfe3
2 changed files with 29 additions and 16 deletions
|
@ -3,6 +3,9 @@ import Config
|
||||||
config :nostrum,
|
config :nostrum,
|
||||||
youtubedl: "/usr/bin/yt-dlp"
|
youtubedl: "/usr/bin/yt-dlp"
|
||||||
|
|
||||||
|
config :sergei,
|
||||||
|
env: config_env()
|
||||||
|
|
||||||
# Import environment specific config. This must remain at the bottom
|
# Import environment specific config. This must remain at the bottom
|
||||||
# of this file so it overrides the configuration defined above.
|
# of this file so it overrides the configuration defined above.
|
||||||
import_config "#{config_env()}.exs"
|
import_config "#{config_env()}.exs"
|
||||||
|
|
|
@ -25,10 +25,11 @@ defmodule Sergei.Consumer do
|
||||||
Consumer.start_link(__MODULE__)
|
Consumer.start_link(__MODULE__)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Bulk overwrite commands per guild. While this is efficient enough for now, moving
|
# Initialization of the Discord Client
|
||||||
# to global commands in the future is probably a good idea.
|
def handle_event({:READY, %{guilds: guilds} = _event, _ws_state}) do
|
||||||
@spec register_commands!(integer) :: :ok
|
# Playing some tunes
|
||||||
def register_commands!(guild_id) do
|
Api.update_status(:online, "some tunes", 0)
|
||||||
|
|
||||||
commands =
|
commands =
|
||||||
Enum.map(@slash_commands, fn {name, description, options} ->
|
Enum.map(@slash_commands, fn {name, description, options} ->
|
||||||
%{
|
%{
|
||||||
|
@ -38,19 +39,28 @@ defmodule Sergei.Consumer do
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
case Application.get_env(:sergei, :env) do
|
||||||
|
:prod ->
|
||||||
|
case Api.bulk_overwrite_global_application_commands(commands) do
|
||||||
|
{:ok, _res} -> :ok
|
||||||
|
{:error, err} -> raise err
|
||||||
|
end
|
||||||
|
|
||||||
|
# Overwrite commands by guild in dev for a faster dev cycle
|
||||||
|
:dev ->
|
||||||
|
guilds
|
||||||
|
|> Enum.map(fn guild -> guild.id end)
|
||||||
|
|> Enum.each(fn guild_id ->
|
||||||
case Api.bulk_overwrite_guild_application_commands(guild_id, commands) do
|
case Api.bulk_overwrite_guild_application_commands(guild_id, commands) do
|
||||||
{:ok, _res} -> :ok
|
{:ok, _res} -> :ok
|
||||||
{:error, err} -> raise err
|
{:error, err} -> raise err
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
Logger.error("invalid environment: expected dev or prod")
|
||||||
|
System.stop(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Initialization of the Discord Client
|
|
||||||
def handle_event({:READY, %{guilds: guilds} = _event, _ws_state}) do
|
|
||||||
Api.update_status(:online, "some tunes", 0)
|
|
||||||
|
|
||||||
guilds
|
|
||||||
|> Enum.map(fn guild -> guild.id end)
|
|
||||||
|> Enum.each(®ister_commands!/1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_event({:VOICE_STATE_UPDATE, state, _ws_state}) do
|
def handle_event({:VOICE_STATE_UPDATE, state, _ws_state}) do
|
||||||
|
|
Loading…
Reference in a new issue