Current section

Files

Jump to
discord_gleam src discord_gleam@bot.erl
Raw

src/discord_gleam@bot.erl

-module(discord_gleam@bot).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/discord_gleam/bot.gleam").
-export([new/2, with_intents/2, with_message_cache_limit/2, send_packet/2]).
-export_type([bot/0, bot_message/0, cache/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type bot() :: {bot,
binary(),
discord_gleam@discord@snowflake:snowflake(discord_gleam@discord@snowflake:application()),
discord_gleam@discord@intents:intents(),
cache(),
integer(),
gleam@erlang@process:subject(bot_message())}.
-type bot_message() :: {send_packet, binary()}.
-type cache() :: {cache,
booklet:booklet(gleam@dict:dict(discord_gleam@discord@snowflake:snowflake(discord_gleam@discord@snowflake:message()), discord_gleam@ws@packets@message:message_packet_data()))}.
-file("src/discord_gleam/bot.gleam", 44).
?DOC(
" Create a new bot instance.\n"
"\n"
" Example:\n"
" ```gleam\n"
" import discord_gleam/bot\n"
"\n"
" fn main() {\n"
" let bot = bot.new(\"TOKEN\", \"CLIENT_ID\")\n"
" }\n"
" ```\n"
).
-spec new(binary(), binary()) -> bot().
new(Token, Client_id) ->
{bot,
Token,
discord_gleam@discord@snowflake:from_string(Client_id),
discord_gleam@discord@intents:default(),
{cache, booklet_ffi:make(maps:new())},
1000,
gleam@erlang@process:new_subject()}.
-file("src/discord_gleam/bot.gleam", 69).
?DOC(
" Sets the intents for the bot. \\\n"
" This can only be used before the bot is started, and is meant to use while building the bot\n"
"\n"
" Example:\n"
" ```gleam\n"
" import discord_gleam/bot\n"
" import discord_gleam/discord/intents\n"
"\n"
" fn main() {\n"
" let bot =\n"
" bot.new(token, client_id)\n"
" |> bot.with_intents(intents.all())\n"
" }\n"
" ```\n"
).
-spec with_intents(bot(), discord_gleam@discord@intents:intents()) -> bot().
with_intents(Bot, Intents) ->
{bot,
erlang:element(2, Bot),
erlang:element(3, Bot),
Intents,
erlang:element(5, Bot),
erlang:element(6, Bot),
erlang:element(7, Bot)}.
-file("src/discord_gleam/bot.gleam", 74).
?DOC(" Sets the message cache size limit for the bot, default is 1000 messages.\n").
-spec with_message_cache_limit(bot(), integer()) -> bot().
with_message_cache_limit(Bot, Limit) ->
{bot,
erlang:element(2, Bot),
erlang:element(3, Bot),
erlang:element(4, Bot),
erlang:element(5, Bot),
Limit,
erlang:element(7, Bot)}.
-file("src/discord_gleam/bot.gleam", 80).
?DOC(
" Used to send a packet on the websocket to discord \\\n"
" Primarily made to be used internally\n"
).
-spec send_packet(bot(), binary()) -> nil.
send_packet(Bot, Packet) ->
gleam@erlang@process:send(erlang:element(7, Bot), {send_packet, Packet}).