-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #562 from geekingfrog/autohost-to-generic-bots
Autohost to generic bots
- Loading branch information
Showing
48 changed files
with
637 additions
and
464 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
defmodule Teiserver.Bot do | ||
alias Teiserver.Bot.Bot | ||
alias Teiserver.BotQueries | ||
alias Teiserver.Repo | ||
|
||
@type id :: Teiserver.Bot.Bot.id() | ||
|
||
def create_bot(attrs \\ %{}) do | ||
%Bot{} | ||
|> Bot.changeset(attrs) | ||
|> Repo.insert() | ||
end | ||
|
||
def change_bot(%Bot{} = bot, attrs \\ %{}) do | ||
Bot.changeset(bot, attrs) | ||
end | ||
|
||
def update_bot(%Bot{} = bot, attrs) do | ||
bot |> change_bot(attrs) |> Repo.update() | ||
end | ||
|
||
@spec delete(Bot.t()) :: :ok | {:error, term()} | ||
def delete(%Bot{} = bot) do | ||
case Repo.delete(bot) do | ||
{:ok, _} -> :ok | ||
{:error, err} -> {:error, err} | ||
end | ||
end | ||
|
||
defdelegate get_by_id(id), to: BotQueries | ||
end |
2 changes: 1 addition & 1 deletion
2
lib/teiserver/autohost/libs/autohost_lib.ex → lib/teiserver/bot/libs/bot_lib.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 9 additions & 9 deletions
18
...server/autohost/queries/autohost_query.ex → lib/teiserver/bot/queries/bot_queries.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
defmodule Teiserver.AutohostQueries do | ||
defmodule Teiserver.BotQueries do | ||
use TeiserverWeb, :queries | ||
alias Teiserver.Autohost.Autohost | ||
alias Teiserver.Bot.Bot | ||
|
||
@doc """ | ||
Returns all autohosts. | ||
Returns all bots. | ||
That list may get big, so think about streaming and/or paginating | ||
but for now this will do. | ||
""" | ||
@spec list_autohosts() :: [Autohost.t()] | ||
def list_autohosts() do | ||
@spec list_bots() :: [Bot.t()] | ||
def list_bots() do | ||
base_query() |> Repo.all() | ||
end | ||
|
||
@spec get_by_id(Autohost.id()) :: Autohost.t() | nil | ||
@spec get_by_id(Bot.id()) :: Bot.t() | nil | ||
def get_by_id(nil), do: nil | ||
|
||
def get_by_id(id) do | ||
base_query() |> where_id(id) |> Repo.one() | ||
end | ||
|
||
def base_query() do | ||
from autohost in Autohost, as: :autohost | ||
from bot in Bot, as: :bot | ||
end | ||
|
||
def where_id(query, id) do | ||
from autohost in query, | ||
where: autohost.id == ^id | ||
from bot in query, | ||
where: bot.id == ^id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.