Skip to content

Commit 646e3e8

Browse files
committed
fix: add credo and satisfy it
1 parent 041af43 commit 646e3e8

File tree

6 files changed

+34
-21
lines changed

6 files changed

+34
-21
lines changed

.credo.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
{Credo.Check.Readability.Semicolons},
3838
{Credo.Check.Readability.SinglePipe},
3939
{Credo.Check.Readability.SpaceAfterCommas},
40-
{Credo.Check.Readability.Specs},
40+
{Credo.Check.Readability.Specs, false},
4141
{Credo.Check.Readability.StringSigils},
4242
{Credo.Check.Readability.TrailingBlankLine},
4343
{Credo.Check.Readability.TrailingWhiteSpace},

lib/gateway/command.ex

+25-17
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,9 @@ defmodule Crux.Gateway.Command do
6868
%{shard_id: shard_id, shard_count: shard_count, token: token, intents: intents} = args
6969
) do
7070
presence =
71-
case args do
72-
%{presence: fun} when is_function(fun, 2) ->
73-
fun.(shard_id, shard_count)
74-
75-
%{presence: presence} when is_map(presence) ->
76-
presence
77-
78-
%{presence: nil} ->
79-
%{}
80-
81-
args when not is_map_key(args, :presence) ->
82-
%{}
83-
end
84-
85-
presence = _update_status(presence)
71+
args
72+
|> _get_presence()
73+
|> _update_status()
8674

8775
{os, name} = OS.type()
8876

@@ -102,6 +90,25 @@ defmodule Crux.Gateway.Command do
10290
|> finalize(2)
10391
end
10492

93+
defp _get_presence(%{presence: fun, shard_id: shard_id, shard_count: shard_count})
94+
when is_function(fun, 2) do
95+
fun.(shard_id, shard_count)
96+
end
97+
98+
defp _get_presence(%{presence: presence})
99+
when is_map(presence) do
100+
presence
101+
end
102+
103+
defp _get_presence(%{presence: nil}) do
104+
%{}
105+
end
106+
107+
defp _get_presence(args)
108+
when not is_map_key(args, :presence) do
109+
%{}
110+
end
111+
105112
@doc """
106113
Builds a [Update Voice State](https://discord.com/developers/docs/topics/gateway#update-voice-state) command.
107114
@@ -151,8 +158,9 @@ defmodule Crux.Gateway.Command do
151158
presence
152159
|> Map.new(fn
153160
{k, v} when is_list(v) ->
154-
activites =
155-
Enum.map(v, fn activity -> Map.new(activity, fn {k, v} -> {to_string(k), v} end) end)
161+
stringify_key = fn {k, v} -> {to_string(k), v} end
162+
163+
activites = Enum.map(v, &Map.new(&1, stringify_key))
156164

157165
{to_string(k), activites}
158166

lib/gateway/connection.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ defmodule Crux.Gateway.Connection do
362362
end
363363

364364
def terminate(:fatal_close_code, _state, data) do
365-
Crux.Gateway.stop_shard(data.name, {data.shard_id, data.shard_count})
365+
Gateway.stop_shard(data.name, {data.shard_id, data.shard_count})
366366
end
367367

368368
def terminate(reason, state, data) do

lib/gateway/connection/gun.ex

+2-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ defmodule Crux.Gateway.Connection.Gun do
262262
new_buffer =
263263
if suffix == <<0x00, 0x00, 0xFF, 0xFF>> do
264264
packet =
265-
Zlib.inflate(data.zlib, buffer)
265+
data.zlib
266+
|> Zlib.inflate(buffer)
266267
|> Erlang.iolist_to_binary()
267268
|> Erlang.binary_to_term()
268269
|> Util.atomify()

mix.exs

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ defmodule Crux.Gateway.MixProject do
4242
{:gen_stage, "~> 1.0"},
4343
{:gun, "~> 1.3"},
4444
{:jason, "~> 1.2", only: [:dev, :test], runtime: false},
45-
{:ex_doc, "~> 0.23", only: [:dev], runtime: false}
45+
{:ex_doc, "~> 0.23", only: [:dev], runtime: false},
46+
{:credo, "~> 1.5", only: [:dev, :test], runtime: false}
4647
]
4748
end
4849

mix.lock

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
%{
2+
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
23
"cowlib": {:hex, :cowlib, "2.7.3", "a7ffcd0917e6d50b4d5fb28e9e2085a0ceb3c97dea310505f7460ff5ed764ce9", [:rebar3], [], "hexpm", "1e1a3d176d52daebbecbbcdfd27c27726076567905c2a9d7398c54da9d225761"},
4+
"credo": {:hex, :credo, "1.5.4", "9914180105b438e378e94a844ec3a5088ae5875626fc945b7c1462b41afc3198", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "cf51af45eadc0a3f39ba13b56fdac415c91b34f7b7533a13dc13550277141bc4"},
35
"earmark_parser": {:hex, :earmark_parser, "1.4.12", "b245e875ec0a311a342320da0551da407d9d2b65d98f7a9597ae078615af3449", [:mix], [], "hexpm", "711e2cc4d64abb7d566d43f54b78f7dc129308a63bc103fbd88550d2174b3160"},
46
"ex_doc": {:hex, :ex_doc, "0.23.0", "a069bc9b0bf8efe323ecde8c0d62afc13d308b1fa3d228b65bca5cf8703a529d", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f5e2c4702468b2fd11b10d39416ddadd2fcdd173ba2a0285ebd92c39827a5a16"},
7+
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
58
"gen_stage": {:hex, :gen_stage, "1.0.0", "51c8ae56ff54f9a2a604ca583798c210ad245f415115453b773b621c49776df5", [:mix], [], "hexpm", "1d9fc978db5305ac54e6f5fec7adf80cd893b1000cf78271564c516aa2af7706"},
69
"gun": {:hex, :gun, "1.3.3", "cf8b51beb36c22b9c8df1921e3f2bc4d2b1f68b49ad4fbc64e91875aa14e16b4", [:rebar3], [{:cowlib, "~> 2.7.0", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "3106ce167f9c9723f849e4fb54ea4a4d814e3996ae243a1c828b256e749041e0"},
710
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},

0 commit comments

Comments
 (0)