debianize-mobilizon/lib/mobilizon/actors/bot.ex

42 lines
843 B
Elixir
Raw Normal View History

defmodule Mobilizon.Actors.Bot do
@moduledoc """
2019-09-09 00:52:49 +02:00
Represents a local bot.
"""
2019-09-09 00:52:49 +02:00
use Ecto.Schema
2019-09-09 00:52:49 +02:00
import Ecto.Changeset
2019-09-09 00:52:49 +02:00
alias Mobilizon.Actors.Actor
alias Mobilizon.Users.User
2019-09-09 00:52:49 +02:00
@type t :: %__MODULE__{
source: String.t(),
type: String.t(),
actor: Actor.t(),
user: User.t()
}
@required_attrs [:source]
@optional_attrs [:type, :actor_id, :user_id]
@attrs @required_attrs ++ @optional_attrs
schema "bots" do
field(:source, :string)
field(:type, :string, default: "ics")
2019-09-09 00:52:49 +02:00
belongs_to(:actor, Actor)
belongs_to(:user, User)
timestamps()
end
@doc false
@spec changeset(t | Ecto.Schema.t(), map) :: Ecto.Changeset.t()
2019-09-13 01:55:45 +02:00
def changeset(%__MODULE__{} = bot, attrs) do
bot
2019-09-09 00:52:49 +02:00
|> cast(attrs, @attrs)
|> validate_required(@required_attrs)
end
end