Skip to content

Commit

Permalink
Merge pull request #528 from BrandtHill/master
Browse files Browse the repository at this point in the history
Check OTP version on startup and update deprecated Logger.warn/2 calls
  • Loading branch information
jchristgit authored Nov 1, 2023
2 parents 39e93c8 + 14ed75e commit 4fabfc5
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 17 deletions.
18 changes: 15 additions & 3 deletions lib/nostrum/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ defmodule Nostrum.Application do
def start(_type, _args) do
Token.check_token!()
check_executables()
check_otp_version()
Logger.add_translator({Nostrum.StateMachineTranslator, :translate})

children = [
Expand All @@ -46,19 +47,19 @@ defmodule Nostrum.Application do

cond do
is_binary(ff) and is_nil(System.find_executable(ff)) ->
Logger.warn("""
Logger.warning("""
#{ff} was not found in your path. By default, Nostrum requires ffmpeg to use voice.
If you don't intend to use voice with ffmpeg, configure :nostrum, :ffmpeg to nil to suppress.
""")

is_binary(yt) and is_nil(System.find_executable(yt)) ->
Logger.warn("""
Logger.warning("""
#{yt} was not found in your path. Nostrum supports youtube-dl for voice.
If you don't require youtube-dl support, configure :nostrum, :youtubedl to nil to suppress.
""")

is_binary(sl) and is_nil(System.find_executable(sl)) ->
Logger.warn("""
Logger.warning("""
#{sl} was not found in your path. Nostrum supports streamlink for voice.
If you don't require streamlink support, configure :nostrum, :streamlink to nil to suppress.
""")
Expand All @@ -67,4 +68,15 @@ defmodule Nostrum.Application do
:ok
end
end

defp check_otp_version do
_module_info = :pg.module_info()

unless function_exported?(:pg, :monitor, 2) do
Logger.critical("""
Your Erlang/OTP version needs to be 25.1 or newer to use Nostrum 0.9 and newer.
Current major version: #{System.otp_release()}
""")
end
end
end
2 changes: 1 addition & 1 deletion lib/nostrum/shard/dispatch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ defmodule Nostrum.Shard.Dispatch do
end

def handle_event(event, p, state) do
Logger.warn("UNHANDLED GATEWAY DISPATCH EVENT TYPE: #{event}, #{inspect(p)}")
Logger.warning("UNHANDLED GATEWAY DISPATCH EVENT TYPE: #{event}, #{inspect(p)}")
{event, p, state}
end
end
2 changes: 1 addition & 1 deletion lib/nostrum/shard/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ defmodule Nostrum.Shard.Event do
end

def handle(event, _payload, state) do
Logger.warn("UNHANDLED GATEWAY EVENT #{event}")
Logger.warning("UNHANDLED GATEWAY EVENT #{event}")
{state, []}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/nostrum/shard/session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ defmodule Nostrum.Shard.Session do
heartbeat_later}
else
# Our last heartbeat was not acknowledged. Disconnect and try to resume.
Logger.warn("Heartbeat ack not received in time, reconnecting")
Logger.warning("Heartbeat ack not received in time, reconnecting")
:ok = :gun.ws_send(conn, stream, :close)
connect = {:next_event, :internal, :connect}
{:next_state, :disconnected, %{data | stream: nil}, connect}
Expand Down
4 changes: 2 additions & 2 deletions lib/nostrum/shard/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Nostrum.Shard.Supervisor do
3. The payload is then written to the cache. To make sure we're not overrunning
the cache, especially at startup with `request_guild_members` or other heavy
payloads, this is done in the shard itself.
payloads, this is done in the shard itself.
4. The cache updates itself from the new data. In some cases, such as update or
delete events, it may send out a second "old" object as well, that helps the
Expand Down Expand Up @@ -48,7 +48,7 @@ defmodule Nostrum.Shard.Supervisor do
defp cast_shard_range(gateway_shards, gateway_shards), do: {1, gateway_shards, gateway_shards}

defp cast_shard_range(gateway_shards, count) when is_integer(count) and count > 0 do
Logger.warn(
Logger.warning(
"Configured shard count (#{count}) " <>
"differs from Discord Gateway's recommended shard count (#{gateway_shards}). " <>
"Consider using `num_shards: :auto` option in your Nostrum config."
Expand Down
2 changes: 1 addition & 1 deletion lib/nostrum/voice/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ defmodule Nostrum.Voice.Event do
end

def handle(event, _payload, state) do
Logger.warn("UNHANDLED VOICE GATEWAY EVENT #{event}")
Logger.debug("UNHANDLED VOICE GATEWAY EVENT #{event}")
state
end
end
16 changes: 8 additions & 8 deletions lib/nostrum/voice/session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ defmodule Nostrum.Voice.Session do
end

def handle_continue(%VoiceState{channel_id: channel_id, guild_id: guild_id} = voice, nil) do
%{name: guild_name, channels: %{^channel_id => %{name: channel_name}}} =
GuildCache.get!(guild_id)
case GuildCache.get(guild_id) do
{:ok, %{name: guild_name, channels: %{^channel_id => %{name: channel_name}}}} ->
Logger.metadata(guild: ~s|"#{guild_name}"|, channel: ~s|"#{channel_name}"|)

Logger.metadata(
guild: ~s|"#{guild_name}"|,
channel: ~s|"#{channel_name}"|
)
_error ->
Logger.metadata(guild: guild_id, channel: channel_id)
end

[host, port] = String.split(voice.gateway, ":")

Expand Down Expand Up @@ -128,7 +128,7 @@ defmodule Nostrum.Voice.Session do
def handle_info({:gun_up, worker, _proto}, state) do
stream = :gun.ws_upgrade(worker, @gateway_qs)
{:upgrade, ["websocket"], _} = :gun.await(worker, stream, @timeout_ws_upgrade)
Logger.warn("Reconnected after connection broke")
Logger.warning("Reconnected after connection broke")
{:noreply, %{state | heartbeat_ack: true}}
end

Expand All @@ -154,7 +154,7 @@ defmodule Nostrum.Voice.Session do
end

def handle_cast(:heartbeat, %{heartbeat_ack: false, heartbeat_ref: timer_ref} = state) do
Logger.warn("heartbeat_ack not received in time, disconnecting")
Logger.warning("heartbeat_ack not received in time, disconnecting")
{:ok, :cancel} = :timer.cancel(timer_ref)
:gun.ws_send(state.conn, state.stream, :close)
{:noreply, state}
Expand Down

0 comments on commit 4fabfc5

Please # to comment.