@@ -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 ,
0 commit comments