Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ProducerMatt committed Mar 23, 2024
1 parent 2518ab5 commit 2cbb7cd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
10 changes: 5 additions & 5 deletions lib/service/discord.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule Service.Discord do
alias Stampede, as: S
alias S.{Msg}
alias Nostrum.Api
require Msg
use TypeCheck
use Supervisor, restart: :permanent
Expand Down Expand Up @@ -40,7 +41,7 @@ defmodule Service.Discord do

@impl Service
def at_bot?(_cfg, msg) do
Nostrum.Api.get_channel_message(msg.channel_id, msg.referenced_msg_id)
Api.get_channel_message(msg.channel_id, msg.referenced_msg_id)
|> case do
{:ok, service_msg} ->
bot_id?(service_msg.author.id)
Expand Down Expand Up @@ -88,7 +89,7 @@ defmodule Service.Discord do
end

def do_send_msg(channel_id, msg, try \\ 0) do
case Nostrum.Api.create_message(
case Api.create_message(
channel_id,
content: msg
) do
Expand Down Expand Up @@ -135,7 +136,7 @@ defmodule Service.Discord do

[
"Message from ",
msg.author_id |> Nostrum.Api.get_user!() |> Nostrum.Struct.User.full_name() |> inspect(),
msg.author_id |> Api.get_user!() |> Nostrum.Struct.User.full_name() |> inspect(),
" lead to ",
error_type,
" in plugin ",
Expand Down Expand Up @@ -223,7 +224,7 @@ defmodule Service.Discord do

@spec! get_msg({discord_channel_id(), discord_msg_id()}) :: {:ok, Msg.t()} | {:error, any()}
def get_msg({channel_id, msg_id}) do
case Nostrum.Api.get_channel_message(channel_id, msg_id) do
case Api.get_channel_message(channel_id, msg_id) do
{:ok, discord_msg} ->
{:ok, into_msg(discord_msg)}

Expand Down Expand Up @@ -259,7 +260,6 @@ defmodule Service.Discord.Handler do
alias Stampede, as: S
alias S.{Response, Msg}
require Msg
alias Nostrum.Api
alias Service.Discord

@typep! vips :: S.CfgTable.vips()
Expand Down
1 change: 0 additions & 1 deletion test/stampede_stateless_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ defmodule StampedeStatelessTest do
import ExUnit.CaptureLog
alias Stampede, as: S
require S.Msg
alias Service.Dummy, as: D
doctest Stampede

@dummy_cfg """
Expand Down
16 changes: 7 additions & 9 deletions test/stampede_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ defmodule StampedeTest do
server_id: :testing,
error_channel_id: :error,
prefix: "!",
plugs: MapSet.new([Plugin.Test, Plugin.Sentience, Plugin.Why])
plugs: MapSet.new([Plugin.Test, Plugin.Sentience, Plugin.Why]),
dm_handler: false,
filename: :"test SiteConfig load_all",
vip_ids: MapSet.new([:server])
}
setup_all do
%{
Expand Down Expand Up @@ -199,20 +202,15 @@ defmodule StampedeTest do
test "load_all", s do
ids = Atom.to_string(s.id)

this_cfg =
@dummy_cfg
|> String.replace("server_id: testing", "server_id: foobar")

Path.join([s.tmp_dir, ids <> ".yml"])
|> File.write!(this_cfg)
|> File.write!(@dummy_cfg)

newtable =
SiteConfig.load_all(s.tmp_dir)
|> Map.fetch!(Service.Dummy)
|> Map.fetch!(:foobar)
|> Map.fetch!(:testing)

assert "!" == newtable.prefix
assert :foobar == newtable.server_id
assert newtable == @dummy_cfg_verified
end
end

Expand Down

0 comments on commit 2cbb7cd

Please sign in to comment.