From bc55be1e8beb32bf1c2bbf603765af7ffec497ce Mon Sep 17 00:00:00 2001 From: Aram Menocci Date: Fri, 30 Oct 2020 18:35:59 -0300 Subject: [PATCH 1/6] [channel] added new channels --- lib/Structs/Channels/channel.ex | 10 +++++++--- lib/Structs/Channels/news_channel.ex | 23 +++++++++++++++++++++++ lib/Structs/Channels/store_channel.ex | 24 ++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 lib/Structs/Channels/news_channel.ex create mode 100644 lib/Structs/Channels/store_channel.ex diff --git a/lib/Structs/Channels/channel.ex b/lib/Structs/Channels/channel.ex index 0f25cc4..0dab838 100644 --- a/lib/Structs/Channels/channel.ex +++ b/lib/Structs/Channels/channel.ex @@ -9,7 +9,9 @@ defmodule Alchemy.Channel do ChannelCategory, VoiceChannel, DMChannel, - GroupDMChannel + GroupDMChannel, + NewsChannel, + StoreChannel } alias Alchemy.User @@ -159,7 +161,7 @@ defmodule Alchemy.Channel do Whether or not the channel is considered nsfw - `last_message_id` - + The id of the last message sent in the channel, if any - `parent_id` @@ -222,7 +224,7 @@ defmodule Alchemy.Channel do The id of the guild this channel belongs to - `position` - + The sorting position of this channel in the guild - `permission_overwrites` @@ -324,6 +326,8 @@ defmodule Alchemy.Channel do 2 -> VoiceChannel.from_map(map) 3 -> GroupDMChannel.from_map(map) 4 -> ChannelCategory.from_map(map) + 5 -> NewsChannel.from_map(map) + 6 -> StoreChannel.from_map(map) end end end diff --git a/lib/Structs/Channels/news_channel.ex b/lib/Structs/Channels/news_channel.ex new file mode 100644 index 0000000..a0071d6 --- /dev/null +++ b/lib/Structs/Channels/news_channel.ex @@ -0,0 +1,23 @@ +defmodule Alchemy.Channel.NewsChannel do + @moduledoc false + alias Alchemy.OverWrite + import Alchemy.Structs + + defstruct [ + :id, + :guild_id, + :position, + :permission_overwrites, + :name, + :topic, + :nsfw, + :last_message_id, + :parent_id + ] + + def from_map(map) do + map + |> field_map("permission_overwrites", &map_struct(&1, OverWrite)) + |> to_struct(__MODULE__) + end +end diff --git a/lib/Structs/Channels/store_channel.ex b/lib/Structs/Channels/store_channel.ex new file mode 100644 index 0000000..cfd8b15 --- /dev/null +++ b/lib/Structs/Channels/store_channel.ex @@ -0,0 +1,24 @@ +defmodule Alchemy.Channel.StoreChannel do + @moduledoc false + alias Alchemy.OverWrite + import Alchemy.Structs + + # Note: should never encounter a store channel, as they're not something + # bots can send/read to. It's "the store." + + defstruct [ + :id, + :guild_id, + :position, + :permission_overwrites, + :name, + :last_message_id, + :parent_id + ] + + def from_map(map) do + map + |> field_map("permission_overwrites", &map_struct(&1, OverWrite)) + |> to_struct(__MODULE__) + end +end From 7e4da8a16aa762efd5b2a385f35262265aa1dfa5 Mon Sep 17 00:00:00 2001 From: Aram Menocci Date: Wed, 4 Nov 2020 15:01:40 -0300 Subject: [PATCH 2/6] [channel] removed unused --- lib/Structs/Channels/channel.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Structs/Channels/channel.ex b/lib/Structs/Channels/channel.ex index 0dab838..53a57e4 100644 --- a/lib/Structs/Channels/channel.ex +++ b/lib/Structs/Channels/channel.ex @@ -15,7 +15,6 @@ defmodule Alchemy.Channel do } alias Alchemy.User - import Alchemy.Structs @moduledoc """ This module contains useful functions for operating on `Channels`. From 3c3a488b7b978cc51e0e2c5edb7447fcdfbe5a18 Mon Sep 17 00:00:00 2001 From: Aram Menocci Date: Wed, 4 Nov 2020 15:01:54 -0300 Subject: [PATCH 3/6] [mix] version bump --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 78411c0..f0b1bbf 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Alchemy.Mixfile do def project do [ app: :alchemy, - version: "0.6.6", + version: "0.6.7", elixir: "~> 1.8", build_embedded: Mix.env() == :prod, start_permanent: Mix.env() == :prod, From 89656c82d608aa1beb1d74231a3370762247e1d1 Mon Sep 17 00:00:00 2001 From: Aram Menocci Date: Tue, 22 Sep 2020 21:32:55 -0300 Subject: [PATCH 4/6] [cogs] removed unused alias --- lib/cogs.ex | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/cogs.ex b/lib/cogs.ex index bc83811..8a565e0 100644 --- a/lib/cogs.ex +++ b/lib/cogs.ex @@ -3,7 +3,6 @@ defmodule Alchemy.Cogs do alias Alchemy.Cogs.CommandHandler alias Alchemy.Cogs.EventRegistry alias Alchemy.Events - alias Alchemy.Guild require Logger @moduledoc """ @@ -604,7 +603,7 @@ defmodule Alchemy.Cogs do @doc """ Returns a map from command name (string) to the command information. - Each command is either `{module, arity, function_name}`, or + Each command is either `{module, arity, function_name}`, or `{module, arity, function_name, parser}`. This can be useful for providing some kind of help command, or telling @@ -643,7 +642,7 @@ defmodule Alchemy.Cogs do Returns the permission bitset of the current member in the channel the command was called from. - If you just want the base permissions of the member in the guild, + If you just want the base permissions of the member in the guild, see `guild_permissions`. Returns `{:ok, perms}`, or `{:error, why}`. Fails if not called from a guild, or the guild or the member couldn't be fetched from the cache. From 2aa09e7fc3c7b362428b38920c5ce025e09441c2 Mon Sep 17 00:00:00 2001 From: Aram Menocci Date: Tue, 22 Sep 2020 21:33:53 -0300 Subject: [PATCH 5/6] [emoji] added map cases into resolve/1 --- lib/Structs/Messages/Reactions/emoji.ex | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/Structs/Messages/Reactions/emoji.ex b/lib/Structs/Messages/Reactions/emoji.ex index 587393d..b57cdb9 100644 --- a/lib/Structs/Messages/Reactions/emoji.ex +++ b/lib/Structs/Messages/Reactions/emoji.ex @@ -5,11 +5,34 @@ defmodule Alchemy.Reaction.Emoji do defstruct [:id, :name] + @type t :: %__MODULE__{id: String.t(), name: String.t()} - @doc false + + @doc """ + Returns the %Emoji{} struct, + resolving its values according with the data type of the parameter `emoji`. + + ## Example + ```shell + iex(1)> Alchemy.Reaction.Emoji.resolve(%Emoji{id: nil, name: "✅"}) + %Emoji{id: nil, name: "✅"} + + iex(2)> Alchemy.Reaction.Emoji.resolve(%{id: nil, name: "✅"}) + %Emoji{id: nil, name: "✅"} + + iex(3)> Alchemy.Reaction.Emoji.resolve(%{"id" => nil, "name" => "✅"}) + %Emoji{id: nil, name: "✅"} + + iex(4)> Alchemy.Reaction.Emoji.resolve("✅") + %Emoji{id: nil, name: "✅"} + ``` + """ + @spec resolve(emoji :: any()) :: Emoji.t() def resolve(emoji) do case emoji do %__MODULE__{} = em -> em + %{"id" => id, "name" => name} -> %__MODULE__{id: id, name: name} + %{id: id, name: name} -> %__MODULE__{id: id, name: name} unicode -> %__MODULE__{name: unicode} end end From 14a09ebe7ff7bb115ba970a28158723865075654 Mon Sep 17 00:00:00 2001 From: Aram Menocci Date: Tue, 22 Sep 2020 21:34:23 -0300 Subject: [PATCH 6/6] [mix] version bump to 0.6.8 --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index f0b1bbf..48d85da 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Alchemy.Mixfile do def project do [ app: :alchemy, - version: "0.6.7", + version: "0.6.8", elixir: "~> 1.8", build_embedded: Mix.env() == :prod, start_permanent: Mix.env() == :prod,