aboutsummaryrefslogtreecommitdiff
path: root/lib/command/util.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/command/util.ex')
-rw-r--r--lib/command/util.ex64
1 files changed, 53 insertions, 11 deletions
diff --git a/lib/command/util.ex b/lib/command/util.ex
index 8f2018f..d47dd59 100644
--- a/lib/command/util.ex
+++ b/lib/command/util.ex
@@ -1,18 +1,60 @@
defmodule Thulani.Command.Util do
- alias Nostrum.Snowflake
- @type qualified_channel :: {Snowflake.t(), Snowflake.t()}
+ alias Nostrum.Struct.Message
+ alias Nostrum.Struct.User
+ alias Nostrum.Struct.Emoji
+ alias Nostrum.Struct.Channel
+ alias Nostrum.Api
- defmacro __using__(_opts) do
- mod = __MODULE__
+ @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
- quote do
- alias unquote(mod)
- end
+ def reply(
+ %Message{
+ channel_id: channel_id
+ },
+ opts
+ ) do
+ Api.create_message(channel_id, opts)
end
- defmacro command(word, rest, msg) do
- quote do
- {:cmd, " #{unquote(word)}" <> unquote(rest), unquote(msg)}
- 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