Skip to content

Commit

Permalink
Upgraded nostrum, fixed breaking changes (#76)
Browse files Browse the repository at this point in the history
* Upgraded nostrum, fixed breaking changes

* checkpoint
  • Loading branch information
lucapasquale authored May 15, 2024
1 parent 8cd5966 commit df5b0fc
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
strategy:
matrix:
otp: ['26.2.1']
elixir: ['1.16.1']
elixir: ['1.16.2']

steps:
- name: Set up Elixir
Expand Down
2 changes: 1 addition & 1 deletion lib/botchini_discord/consumer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule BotchiniDiscord.Consumer do
Logger.info("Bot started! v#{version}")
end

def handle_event({:GUILD_CREATE, {guild}, _ws_state}) do
def handle_event({:GUILD_CREATE, guild, _ws_state}) do
Discord.upsert_guild(Integer.to_string(guild.id))
end

Expand Down
25 changes: 4 additions & 21 deletions lib/botchini_discord/creators/interactions/list.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ defmodule BotchiniDiscord.Creators.Interactions.List do
Handles /list slash command
"""

alias Nostrum.Cache.ChannelCache
alias Nostrum.Constants.InteractionCallbackType
alias Nostrum.Struct.{ApplicationCommand, Embed, Interaction}
alias Nostrum.Struct.{ApplicationCommand, Interaction}

alias Botchini.{Creators, Discord}
alias BotchiniDiscord.InteractionBehaviour
Expand Down Expand Up @@ -51,30 +50,14 @@ defmodule BotchiniDiscord.Creators.Interactions.List do
{:ok, following} ->
%{
type: InteractionCallbackType.channel_message_with_source(),
data: %{embeds: [guild_following_embed(following)]}
data: guild_following_embed(following)
}
end
end

defp guild_following_embed(following) do
channel_groups = Enum.group_by(following, fn {channel_id, _} -> channel_id end)
stream_codes = Enum.map(following, fn {_channel_id, name} -> " - #{name}" end)

fields =
channel_groups
|> Enum.reduce([], fn {channel_id, following}, acc ->
{:ok, channel} = ChannelCache.get(String.to_integer(channel_id))
stream_codes = Enum.map(following, &elem(&1, 1))

acc ++
[
%Embed.Field{
name: "#" <> channel.name,
value: Enum.join(stream_codes, "\n"),
inline: true
}
]
end)

%Embed{title: "Following streams", fields: fields}
%{content: "Following streams:\n#{Enum.join(stream_codes, "\n")}"}
end
end
6 changes: 3 additions & 3 deletions lib/botchini_web/controllers/twitch_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule BotchiniWeb.TwitchController do

@spec callback(Plug.Conn.t(), any) :: Plug.Conn.t()
def callback(conn, _params) do
case is_request_valid?(conn, Application.fetch_env!(:botchini, :environment)) do
case request_is_valid?(conn, Application.fetch_env!(:botchini, :environment)) do
false ->
conn
|> put_status(:not_found)
Expand All @@ -20,9 +20,9 @@ defmodule BotchiniWeb.TwitchController do
end
end

defp is_request_valid?(_conn, :dev), do: true
defp request_is_valid?(_conn, :dev), do: true

defp is_request_valid?(conn, _) do
defp request_is_valid?(conn, _) do
message_id = get_header(conn, "twitch-eventsub-message-id")
message_timestamp = get_header(conn, "twitch-eventsub-message-timestamp")
[body] = Map.get(conn.assigns, :raw_body)
Expand Down
6 changes: 3 additions & 3 deletions lib/botchini_web/controllers/youtube_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule BotchiniWeb.YoutubeController do

@spec notification(Plug.Conn.t(), any) :: Plug.Conn.t()
def notification(conn, _params) do
case is_request_valid?(conn, Application.fetch_env!(:botchini, :environment)) do
case request_is_valid?(conn, Application.fetch_env!(:botchini, :environment)) do
false ->
conn
|> put_status(:not_found)
Expand All @@ -29,9 +29,9 @@ defmodule BotchiniWeb.YoutubeController do
end
end

defp is_request_valid?(_conn, :dev), do: true
defp request_is_valid?(_conn, :dev), do: true

defp is_request_valid?(conn, _) do
defp request_is_valid?(conn, _) do
[raw_body] = Map.get(conn.assigns, :raw_body)
webhook_secret = Application.fetch_env!(:botchini, :youtube_webhook_secret)

Expand Down
6 changes: 3 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ defmodule Botchini.MixProject do
def project do
[
app: :botchini,
version: "8.9.0",
elixir: "~> 1.16.1",
version: "8.9.1",
elixir: "~> 1.16.2",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand All @@ -27,7 +27,7 @@ defmodule Botchini.MixProject do
defp deps do
[
# Discord
{:nostrum, git: "https://github.com/Kraigie/nostrum.git", runtime: Mix.env() != :test},
{:nostrum, "~> 0.9.1", runtime: Mix.env() != :test},
{:cowlib, "~> 2.11", hex: :remedy_cowlib, override: true},
# Phoenix
{:phoenix, "~> 1.6.16"},
Expand Down
Loading

0 comments on commit df5b0fc

Please sign in to comment.