Skip to content

Commit 3d11894

Browse files
committed
2 parents 52d570e + eb7320f commit 3d11894

5 files changed

Lines changed: 59 additions & 59 deletions

File tree

‎lib/nosedrum/converters.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule Nosedrum.Converters do
1111

1212
alias Nostrum.Error.ApiError
1313
alias Nostrum.Snowflake
14-
alias Nostrum.Struct.Guild.{Member, Role}
14+
alias Nostrum.Struct.Guild.Role
1515
alias Nostrum.Struct.{Channel, Guild}
1616

1717
@typedoc """

‎lib/octocon/workers/simply_plural_import_worker.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,5 +449,5 @@ defmodule Octocon.Workers.SimplyPluralImportWorker do
449449
defp parse_color("#" <> _ = color) when byte_size(color) == 7, do: color
450450
defp parse_color(color) when byte_size(color) == 6, do: color
451451
defp parse_color(color) when color == "", do: nil
452-
defp parse_color(nil), do: nil
452+
defp parse_color(_color), do: nil
453453
end

‎lib/octocon_discord/guild_cache.ex‎

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ defmodule OctoconDiscord.GuildCache do
6767

6868
@impl GuildCache
6969
@doc "Get a guild from the cache."
70-
@spec get(Guild.id()) :: {:ok, Guild.t()} | {:error, :not_found}
7170
def get(guild_id) do
7271
:mnesia.activity(:sync_transaction, fn ->
7372
case :mnesia.read(table(), guild_id) do
@@ -78,8 +77,6 @@ defmodule OctoconDiscord.GuildCache do
7877
end
7978

8079
@impl GuildCache
81-
@doc since: "0.10.0"
82-
@spec all() :: Enumerable.t(Guild.t())
8380
def all do
8481
ms = [{{:_, :_, :"$1"}, [], [:"$1"]}]
8582

@@ -102,7 +99,6 @@ defmodule OctoconDiscord.GuildCache do
10299

103100
@impl GuildCache
104101
@doc "Create a guild from upstream data."
105-
@spec create(map()) :: Guild.t()
106102
def create(payload) do
107103
guild = Guild.to_struct(payload) |> strip_guild()
108104
record = {record_name(), guild.id, guild}
@@ -135,7 +131,6 @@ defmodule OctoconDiscord.GuildCache do
135131

136132
@impl GuildCache
137133
@doc "Remove the given guild from the cache."
138-
@spec delete(Guild.id()) :: Guild.t() | nil
139134
def delete(guild_id) do
140135
:mnesia.activity(:sync_transaction, fn ->
141136
case :mnesia.read(table(), guild_id, :write) do
@@ -151,7 +146,6 @@ defmodule OctoconDiscord.GuildCache do
151146

152147
@impl GuildCache
153148
@doc "Create the given channel for the given guild in the cache."
154-
@spec channel_create(Guild.id(), map()) :: Channel.t()
155149
def channel_create(guild_id, channel) do
156150
new_channel = Channel.to_struct(channel) |> Map.take([:id, :type, :parent_id])
157151

@@ -165,7 +159,6 @@ defmodule OctoconDiscord.GuildCache do
165159

166160
@impl GuildCache
167161
@doc "Delete the channel from the given guild in the cache."
168-
@spec channel_delete(Guild.id(), Channel.id()) :: Channel.t() | :noop
169162
def channel_delete(guild_id, channel_id) do
170163
old_channel =
171164
update_guild!(guild_id, fn guild ->
@@ -178,7 +171,6 @@ defmodule OctoconDiscord.GuildCache do
178171

179172
@doc "Update the channel on the given guild in the cache."
180173
@impl GuildCache
181-
@spec channel_update(Guild.id(), map()) :: {Channel.t() | nil, Channel.t()}
182174
def channel_update(guild_id, channel) do
183175
update_guild!(guild_id, fn guild ->
184176
{old, new, new_channels} =
@@ -190,23 +182,20 @@ defmodule OctoconDiscord.GuildCache do
190182

191183
@impl GuildCache
192184
@doc "Update the emoji list for the given guild in the cache."
193-
@spec emoji_update(Guild.id(), [map()]) :: {[Emoji.t()], [Emoji.t()]}
194185
def emoji_update(_guild_id, payload) do
195186
casted = Util.cast(payload, {:list, {:struct, Emoji}})
196187
{[], casted}
197188
end
198189

199190
@impl GuildCache
200191
@doc "Update the sticker list for the given guild in the cache."
201-
@spec stickers_update(Guild.id(), [map()]) :: {[Sticker.t()], [Sticker.t()]}
202192
def stickers_update(_guild_id, stickers) do
203193
casted = Util.cast(stickers, {:list, {:struct, Sticker}})
204194
{[], casted}
205195
end
206196

207197
@impl GuildCache
208198
@doc "Create the given role in the given guild in the cache."
209-
@spec role_create(Guild.id(), map()) :: {Guild.id(), Role.t()}
210199
def role_create(guild_id, payload) do
211200
update_guild!(guild_id, fn guild ->
212201
permissions = payload.permissions |> String.to_integer()
@@ -218,7 +207,6 @@ defmodule OctoconDiscord.GuildCache do
218207

219208
@doc "Delete the given role from the given guild in the cache."
220209
@impl GuildCache
221-
@spec role_delete(Guild.id(), Role.id()) :: {Guild.id(), Role.t()} | :noop
222210
def role_delete(guild_id, role_id) do
223211
update_guild!(guild_id, fn guild ->
224212
{popped, new_roles} = Map.pop(guild.roles, role_id)
@@ -229,7 +217,6 @@ defmodule OctoconDiscord.GuildCache do
229217

230218
@impl GuildCache
231219
@doc "Update the given role in the given guild in the cache."
232-
@spec role_update(Guild.id(), map()) :: {Guild.id(), Role.t() | nil, Role.t()}
233220
def role_update(guild_id, role) do
234221
update_guild!(guild_id, fn guild ->
235222
permissions = role.permissions |> String.to_integer()
@@ -242,15 +229,12 @@ defmodule OctoconDiscord.GuildCache do
242229

243230
@impl GuildCache
244231
@doc "Update guild voice states with the given voice state in the cache."
245-
@spec voice_state_update(Guild.id(), map()) :: {Guild.id(), [map()]}
246232
def voice_state_update(guild_id, _payload) do
247233
{guild_id, []}
248234
end
249235

250236
@doc "Increment the guild member count by one."
251-
@doc since: "0.7.0"
252237
@impl GuildCache
253-
@spec member_count_up(Guild.id()) :: true
254238
def member_count_up(guild_id) do
255239
# May not be `update_guild!` for the case where guild intent is off.
256240
update_guild(guild_id, fn guild ->
@@ -261,9 +245,7 @@ defmodule OctoconDiscord.GuildCache do
261245
end
262246

263247
@doc "Decrement the guild member count by one."
264-
@doc since: "0.7.0"
265248
@impl GuildCache
266-
@spec member_count_down(Guild.id()) :: true
267249
def member_count_down(guild_id) do
268250
# May not be `update_guild!` for the case where guild intent is off.
269251
update_guild(guild_id, fn guild ->
@@ -312,25 +294,31 @@ defmodule OctoconDiscord.GuildCache do
312294
channels: channels
313295
}) do
314296
channels =
315-
channels
316-
|> Enum.map(fn {id, channel} ->
317-
{id, if(channel == nil, do: nil, else: Map.take(channel, [:id, :type, :parent_id]))}
318-
end)
319-
|> Map.new()
297+
if channels == nil do
298+
nil
299+
else
300+
channels
301+
|> Enum.map(fn {id, channel} -> {id, Map.take(channel, [:id, :type, :parent_id])} end)
302+
|> Map.new()
303+
end
320304

321305
threads =
322-
threads
323-
|> Enum.map(fn {id, thread} ->
324-
{id, if(thread == nil, do: nil, else: Map.take(thread, [:id, :type, :parent_id]))}
325-
end)
326-
|> Map.new()
306+
if threads == nil do
307+
nil
308+
else
309+
threads
310+
|> Enum.map(fn {id, thread} -> {id, Map.take(thread, [:id, :type, :parent_id])} end)
311+
|> Map.new()
312+
end
327313

328314
roles =
329-
roles
330-
|> Enum.map(fn {id, role} ->
331-
{id, if(role == nil, do: nil, else: Map.take(role, [:id, :permissions]))}
332-
end)
333-
|> Map.new()
315+
if roles == nil do
316+
nil
317+
else
318+
roles
319+
|> Enum.map(fn {id, role} -> {id, Map.take(role, [:id, :permissions])} end)
320+
|> Map.new()
321+
end
334322

335323
%{
336324
id: id,

‎lib/octocon_discord/proxy.ex‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,11 @@ defmodule OctoconDiscord.Proxy do
290290
}
291291

292292
true ->
293-
nil
293+
%{
294+
filename: filename,
295+
content_type: attachment.content_type,
296+
title: attachment.title
297+
}
294298
end
295299

296300
{:ok, {file_data, attachment_data}}

‎lib/octocon_web/controllers/system/alter_controller.ex‎

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,34 +123,42 @@ defmodule OctoconWeb.System.AlterController do
123123
|> put_status(:bad_request)
124124
|> json(%{error: "No valid alter attributes provided.", code: "no_alter_attributes"})
125125
else
126-
# if Map.has_key?(attrs, :alias) do
127-
# if Alters.alias_taken?({:system, system_id}, attrs.alias) do
128-
# conn
129-
# |> put_status(:bad_request)
130-
# |> json(%{error: "That alias is already taken.", code: "alias_taken"})
131-
# else
132-
# end
133-
# end
134-
135-
case Alters.update_alter({:system, system_id}, {:id, id}, attrs) do
136-
:ok ->
137-
send_resp(conn, :no_content, "")
126+
if Map.has_key?(attrs, :alias) and attrs.alias != nil and
127+
Alters.alias_taken?({:system, system_id}, attrs.alias) do
128+
{:ok, alter} = Alters.get_alter_by_id({:system, system_id}, {:id, id})
138129

139-
{:error, :changeset} ->
130+
if alter != nil and alter.alias != attrs.alias do
140131
conn
141132
|> put_status(:bad_request)
142-
|> json(%{error: "Invalid alter attributes.", code: "invalid_alter_attributes"})
133+
|> json(%{error: "That alias is already taken.", code: "alias_taken"})
134+
else
135+
update_alter_internal(conn, system_id, id, attrs)
136+
end
137+
else
138+
update_alter_internal(conn, system_id, id, attrs)
139+
end
140+
end
141+
end
143142

144-
{:error, :no_alter_id} ->
145-
conn
146-
|> put_status(:not_found)
147-
|> json(%{error: "Alter not found.", code: "alter_not_found"})
143+
defp update_alter_internal(conn, system_id, id, attrs) do
144+
case Alters.update_alter({:system, system_id}, {:id, id}, attrs) do
145+
:ok ->
146+
send_resp(conn, :no_content, "")
148147

149-
_ ->
150-
conn
151-
|> put_status(:internal_server_error)
152-
|> json(%{error: "An unknown error occurred.", code: "unknown_error"})
153-
end
148+
{:error, :changeset} ->
149+
conn
150+
|> put_status(:bad_request)
151+
|> json(%{error: "Invalid alter attributes.", code: "invalid_alter_attributes"})
152+
153+
{:error, :no_alter_id} ->
154+
conn
155+
|> put_status(:not_found)
156+
|> json(%{error: "Alter not found.", code: "alter_not_found"})
157+
158+
_ ->
159+
conn
160+
|> put_status(:internal_server_error)
161+
|> json(%{error: "An unknown error occurred.", code: "unknown_error"})
154162
end
155163
end
156164

0 commit comments

Comments
 (0)