Current section

Files

Jump to
teac lib teac api moderation automod settings.ex
Raw

lib/teac/api/moderation/automod/settings.ex

defmodule Teac.Api.Moderation.Automod.Settings do
alias Teac.Api
@get_schema NimbleOptions.new!(
broadcaster_id: [type: :string, required: true],
moderator_id: [type: :string, required: true]
)
@put_schema NimbleOptions.new!(
broadcaster_id: [type: :string, required: true],
moderator_id: [type: :string, required: true],
aggression: [type: :integer],
bullying: [type: :integer],
disability: [type: :integer],
misogyny: [type: :integer],
racism: [type: :integer],
sexism: [type: :integer],
homophobia: [type: :integer],
profanity: [type: :integer],
sexuality: [type: :integer],
violence: [type: :integer]
)
@doc """
Gets the broadcaster's AutoMod settings.
## Authorization
Requires a user access token with the `moderator:read:automod_settings` scope.
## Options
* `:broadcaster_id` - required. The ID of the broadcaster whose AutoMod settings to get.
* `:moderator_id` - required. The ID of the moderator or broadcaster making the request.
"""
@spec get(Teac.Client.t(), keyword()) :: {:ok, list(map())} | {:error, Teac.Error.t()}
def get(%Teac.Client{} = client, opts \\ []) do
case NimbleOptions.validate(opts, @get_schema) do
{:ok, opts} ->
[
base_url: Api.uri("moderation/automod/settings"),
params: [broadcaster_id: opts[:broadcaster_id], moderator_id: opts[:moderator_id]],
headers: Api.headers(client)
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.get!()
|> Api.handle_response()
{:error, %NimbleOptions.ValidationError{} = err} ->
{:error, err.message}
end
end
@doc """
Updates the broadcaster's AutoMod settings.
## Authorization
Requires a user access token with the `moderator:manage:automod_settings` scope.
## Options
* `:broadcaster_id` - required. The ID of the broadcaster whose AutoMod settings to update.
* `:moderator_id` - required. The ID of the moderator or broadcaster making the request.
* All category levels (`:aggression`, `:bullying`, `:disability`, `:misogyny`, `:racism`, `:sexism`, `:homophobia`, `:profanity`, `:sexuality`, `:violence`) - optional. Severity level 0–4. Setting any individual level clears the overall level.
"""
@spec put(Teac.Client.t(), keyword()) :: {:ok, list(map())} | {:error, Teac.Error.t()}
def put(%Teac.Client{} = client, opts \\ []) do
case NimbleOptions.validate(opts, @put_schema) do
{:ok, opts} ->
body =
opts
|> Keyword.drop([:broadcaster_id, :moderator_id])
|> Enum.reject(fn {_, v} -> is_nil(v) end)
|> Map.new()
[
base_url: Api.uri("moderation/automod/settings"),
params: [broadcaster_id: opts[:broadcaster_id], moderator_id: opts[:moderator_id]],
headers: Api.headers(client),
json: body
]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.put!()
|> Api.handle_response()
{:error, %NimbleOptions.ValidationError{} = err} ->
{:error, err.message}
end
end
end