defmodule Thulani.Command.Util do alias Nostrum.Struct.Message alias Nostrum.Struct.User alias Nostrum.Struct.Emoji alias Nostrum.Struct.Channel alias Nostrum.Api @spec reply(Message.t(), Api.options() | String.t()) :: Api.create_message(Channel.id(), Message.t()) def reply( %Message{ channel_id: channel_id }, msg ) when is_bitstring(msg) do Api.create_message(channel_id, content: msg) end def reply( %Message{ channel_id: channel_id }, opts ) do Api.create_message(channel_id, opts) end @spec reply!(Message.t(), Api.options() | String.t()) :: nil def reply!(msg, opts), do: {:ok} = reply(msg, opts) @spec react(Message.t(), Api.emoji()) :: Api.create_reaction(Channel.id(), Message.id(), Emoji.t()) def react( %Message{ id: id, channel_id: channel_id }, reaction ) do Api.create_reaction(channel_id, id, reaction) end @spec react!(Message.t(), Api.emoji()) :: Api.create_reaction(Channel.id(), Message.id(), Emoji.t()) def react!(msg, opts), do: {:ok} = react(msg, opts) @spec metadata(Message.t()) :: Map.t() def metadata(%Message{ author: %User{ id: user_id }, timestamp: timestamp }) do %{ created_by: user_id, created: timestamp } end end