Gateway helpers

This commit is contained in:
TriForMine
2021-10-21 17:41:47 +02:00
parent 9eed90f8ed
commit 17115e7681
50 changed files with 121 additions and 110 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ import type { Channel } from "../../types/channels/channel.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
export async function handleChannelCreate(bot: Bot, payload: SnakeCasedPropertiesDeep<DiscordGatewayPayload>) { export async function handleChannelCreate(bot: Bot, payload: SnakeCasedPropertiesDeep<DiscordGatewayPayload>) {
const channel = bot.transformers.channel(bot, { channel: payload.d as SnakeCasedPropertiesDeep<Channel> }); const channel = bot.transformers.channel(bot, { channel: payload.d as SnakeCasedPropertiesDeep<Channel> });
+1 -1
View File
@@ -1,6 +1,6 @@
import type { Channel } from "../../types/channels/channel.ts"; import type { Channel } from "../../types/channels/channel.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
+1 -1
View File
@@ -1,4 +1,4 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import type { ChannelPinsUpdate } from "../../types/channels/channel_pins_update.ts"; import type { ChannelPinsUpdate } from "../../types/channels/channel_pins_update.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
+1 -1
View File
@@ -1,4 +1,4 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import type { Channel } from "../../types/channels/channel.ts"; import type { Channel } from "../../types/channels/channel.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
@@ -1,4 +1,4 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import type { StageInstance } from "../../types/channels/stage_instance.ts"; import type { StageInstance } from "../../types/channels/stage_instance.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
@@ -1,4 +1,4 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import type { StageInstance } from "../../types/channels/stage_instance.ts"; import type { StageInstance } from "../../types/channels/stage_instance.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
@@ -1,4 +1,4 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import type { StageInstance } from "../../types/channels/stage_instance.ts"; import type { StageInstance } from "../../types/channels/stage_instance.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
+1 -1
View File
@@ -1,4 +1,4 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import type { GuildEmojisUpdate } from "../../types/emojis/guild_emojis_update.ts"; import type { GuildEmojisUpdate } from "../../types/emojis/guild_emojis_update.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
+1 -1
View File
@@ -1,4 +1,4 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts"; import type { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
+1 -1
View File
@@ -1,4 +1,4 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts"; import type { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
+1 -1
View File
@@ -1,4 +1,4 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { Guild } from "../../types/guilds/guild.ts"; import type { Guild } from "../../types/guilds/guild.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
+1 -1
View File
@@ -1,4 +1,4 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { UnavailableGuild } from "../../types/guilds/unavailable_guild.ts"; import type { UnavailableGuild } from "../../types/guilds/unavailable_guild.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
@@ -1,4 +1,4 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { GuildIntegrationsUpdate } from "../../types/integrations/guild_integrations_update.ts"; import type { GuildIntegrationsUpdate } from "../../types/integrations/guild_integrations_update.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
+1 -1
View File
@@ -1,4 +1,4 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { Guild } from "../../types/guilds/guild.ts"; import type { Guild } from "../../types/guilds/guild.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
+1 -1
View File
@@ -1,4 +1,4 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { Guild } from "../../types/guilds/guild.ts"; import type { Guild } from "../../types/guilds/guild.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
@@ -1,5 +1,5 @@
import type { AddGuildDiscoverySubcategory } from "../../types/discovery/add_guild_discovery_subcategory.ts"; import type { AddGuildDiscoverySubcategory } from "../../types/discovery/add_guild_discovery_subcategory.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
/** Add a discovery subcategory to the guild. Requires the `MANAGE_GUILD` permission. */ /** Add a discovery subcategory to the guild. Requires the `MANAGE_GUILD` permission. */
+1 -1
View File
@@ -1,7 +1,7 @@
import type { DiscoveryMetadata } from "../../types/discovery/discovery_metadata.ts"; import type { DiscoveryMetadata } from "../../types/discovery/discovery_metadata.ts";
import type { ModifyGuildDiscoveryMetadata } from "../../types/discovery/modify_guild_discovery_metadata.ts"; import type { ModifyGuildDiscoveryMetadata } from "../../types/discovery/modify_guild_discovery_metadata.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
/** Modify the discovery metadata for the guild. Requires the MANAGE_GUILD permission. Returns the updated discovery metadata object on success. */ /** Modify the discovery metadata for the guild. Requires the MANAGE_GUILD permission. Returns the updated discovery metadata object on success. */
export async function editDiscovery(bot: Bot, guildId: bigint, data: ModifyGuildDiscoveryMetadata) { export async function editDiscovery(bot: Bot, guildId: bigint, data: ModifyGuildDiscoveryMetadata) {
+1 -1
View File
@@ -1,6 +1,6 @@
import type { DiscoveryMetadata } from "../../types/discovery/discovery_metadata.ts"; import type { DiscoveryMetadata } from "../../types/discovery/discovery_metadata.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
/** Returns the discovery metadata object for the guild. Requires the `MANAGE_GUILD` permission. */ /** Returns the discovery metadata object for the guild. Requires the `MANAGE_GUILD` permission. */
export async function getDiscovery(bot: Bot, guildId: bigint) { export async function getDiscovery(bot: Bot, guildId: bigint) {
@@ -1,6 +1,6 @@
import type { DiscoveryCategory } from "../../types/discovery/discovery_category.ts"; import type { DiscoveryCategory } from "../../types/discovery/discovery_category.ts";
import { Collection } from "../../util/collection.ts"; import { Collection } from "../../util/collection.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
/** Returns a Collection (mapped by Id of the discovery category object) of discovery category objects that can be used when editing guilds */ /** Returns a Collection (mapped by Id of the discovery category object) of discovery category objects that can be used when editing guilds */
@@ -1,4 +1,4 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
/** Removes a discovery subcategory from the guild. Requires the MANAGE_GUILD permission. Returns a 204 No Content on success. */ /** Removes a discovery subcategory from the guild. Requires the MANAGE_GUILD permission. Returns a 204 No Content on success. */
export async function removeDiscoverySubcategory(bot: Bot, guildId: bigint, categoryId: number) { export async function removeDiscoverySubcategory(bot: Bot, guildId: bigint, categoryId: number) {
@@ -1,5 +1,5 @@
import type { ValidateDiscoverySearchTerm } from "../../types/discovery/validate_discovery_search_term.ts"; import type { ValidateDiscoverySearchTerm } from "../../types/discovery/validate_discovery_search_term.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
export async function validDiscoveryTerm(bot: Bot, term: string) { export async function validDiscoveryTerm(bot: Bot, term: string) {
+1 -1
View File
@@ -1,6 +1,6 @@
import type { Emoji } from "../../types/emojis/emoji.ts"; import type { Emoji } from "../../types/emojis/emoji.ts";
import { Errors } from "../../types/discordeno/errors.ts"; import { Errors } from "../../types/discordeno/errors.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
/** /**
* Returns an emoji for the given guild and emoji Id. * Returns an emoji for the given guild and emoji Id.
+1 -1
View File
@@ -1,4 +1,4 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import type { Emoji } from "../../types/emojis/emoji.ts"; import type { Emoji } from "../../types/emojis/emoji.ts";
import { Errors } from "../../types/discordeno/errors.ts"; import { Errors } from "../../types/discordeno/errors.ts";
import { Collection } from "../../util/collection.ts"; import { Collection } from "../../util/collection.ts";
@@ -1,4 +1,4 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
/** Delete the attached integration object for the guild with this id. Requires MANAGE_GUILD permission. */ /** Delete the attached integration object for the guild with this id. Requires MANAGE_GUILD permission. */
export async function deleteIntegration(bot: Bot, guildId: bigint, id: bigint) { export async function deleteIntegration(bot: Bot, guildId: bigint, id: bigint) {
+1 -1
View File
@@ -1,7 +1,7 @@
import type { CreateChannelInvite } from "../../types/invites/create_channel_invite.ts"; import type { CreateChannelInvite } from "../../types/invites/create_channel_invite.ts";
import type { InviteMetadata } from "../../types/invites/invite_metadata.ts"; import type { InviteMetadata } from "../../types/invites/invite_metadata.ts";
import { Errors } from "../../types/discordeno/errors.ts"; import { Errors } from "../../types/discordeno/errors.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
/** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */ /** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */
+1 -1
View File
@@ -1,5 +1,5 @@
import type { InviteMetadata } from "../../types/invites/invite_metadata.ts"; import type { InviteMetadata } from "../../types/invites/invite_metadata.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
/** Deletes an invite for the given code. Requires `MANAGE_CHANNELS` or `MANAGE_GUILD` permission */ /** Deletes an invite for the given code. Requires `MANAGE_CHANNELS` or `MANAGE_GUILD` permission */
+1 -1
View File
@@ -1,6 +1,6 @@
import type { InviteMetadata } from "../../types/invites/invite_metadata.ts"; import type { InviteMetadata } from "../../types/invites/invite_metadata.ts";
import { Collection } from "../../util/collection.ts"; import { Collection } from "../../util/collection.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
/** Gets the invites for this channel. Requires MANAGE_CHANNEL */ /** Gets the invites for this channel. Requires MANAGE_CHANNEL */
+1 -1
View File
@@ -1,7 +1,7 @@
import { GetInvite } from "../../types/invites/get_invite.ts"; import { GetInvite } from "../../types/invites/get_invite.ts";
import type { InviteMetadata } from "../../types/invites/invite_metadata.ts"; import type { InviteMetadata } from "../../types/invites/invite_metadata.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
/** Returns an invite for the given code or throws an error if the invite doesn't exists. */ /** Returns an invite for the given code or throws an error if the invite doesn't exists. */
export async function getInvite(bot: Bot, inviteCode: string, options?: GetInvite) { export async function getInvite(bot: Bot, inviteCode: string, options?: GetInvite) {
+1 -1
View File
@@ -1,7 +1,7 @@
import type { InviteMetadata } from "../../types/invites/invite_metadata.ts"; import type { InviteMetadata } from "../../types/invites/invite_metadata.ts";
import { Collection } from "../../util/collection.ts"; import { Collection } from "../../util/collection.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
/** Get all the invites for this guild. Requires MANAGE_GUILD permission */ /** Get all the invites for this guild. Requires MANAGE_GUILD permission */
export async function getInvites(bot: Bot, guildId: bigint) { export async function getInvites(bot: Bot, guildId: bigint) {
+1 -1
View File
@@ -15,5 +15,5 @@ export async function getMessage(bot: Bot, channelId: bigint, id: bigint) {
bot.constants.endpoints.CHANNEL_MESSAGE(channelId, id) bot.constants.endpoints.CHANNEL_MESSAGE(channelId, id)
); );
return await bot.transformers.message(bot, result); return bot.transformers.message(bot, result);
} }
+1 -1
View File
@@ -10,5 +10,5 @@ export async function publishMessage(bot: Bot, channelId: bigint, messageId: big
bot.constants.endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId) bot.constants.endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId)
); );
return await bot.transformers.message(bot, data); return bot.transformers.message(bot, data);
} }
+1 -1
View File
@@ -16,5 +16,5 @@ export async function suppressEmbeds(bot: Bot, channelId: bigint, messageId: big
{ flags: 4 } { flags: 4 }
); );
return await bot.transformers.message(bot, result); return bot.transformers.message(bot, result);
} }
+1 -1
View File
@@ -1,6 +1,6 @@
import { Errors } from "../../types/discordeno/errors.ts"; import { Errors } from "../../types/discordeno/errors.ts";
import type { User } from "../../types/users/user.ts"; import type { User } from "../../types/users/user.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
/** Modifies the bot's username or avatar. /** Modifies the bot's username or avatar.
+1 -1
View File
@@ -1,4 +1,4 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import { DiscordGatewayOpcodes } from "../../types/codes/gateway_opcodes.ts"; import { DiscordGatewayOpcodes } from "../../types/codes/gateway_opcodes.ts";
import type { StatusUpdate } from "../../types/gateway/status_update.ts"; import type { StatusUpdate } from "../../types/gateway/status_update.ts";
+1 -1
View File
@@ -1,5 +1,5 @@
import type { GetGatewayBot } from "../../types/gateway/get_gateway_bot.ts"; import type { GetGatewayBot } from "../../types/gateway/get_gateway_bot.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
/** Get the bots Gateway metadata that can help during the operation of large or sharded bots. */ /** Get the bots Gateway metadata that can help during the operation of large or sharded bots. */
+1 -1
View File
@@ -1,5 +1,5 @@
import type { User } from "../../types/users/user.ts"; import type { User } from "../../types/users/user.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
/** This function will return the raw user payload in the rare cases you need to fetch a user directly from the API. */ /** This function will return the raw user payload in the rare cases you need to fetch a user directly from the API. */
+1 -1
View File
@@ -1,5 +1,5 @@
import { Application } from "../../types/applications/application.ts"; import { Application } from "../../types/applications/application.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
/** Get the applications info */ /** Get the applications info */
@@ -1,6 +1,6 @@
import type { UpdateVoiceState } from "../../types/voice/update_voice_state.ts"; import type { UpdateVoiceState } from "../../types/voice/update_voice_state.ts";
import type { AtLeastOne } from "../../types/util.ts"; import type { AtLeastOne } from "../../types/util.ts";
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
/** Connect or join a voice channel inside a guild. By default, the "selfDeaf" option is true. Requires `CONNECT` and `VIEW_CHANNEL` permissions. */ /** Connect or join a voice channel inside a guild. By default, the "selfDeaf" option is true. Requires `CONNECT` and `VIEW_CHANNEL` permissions. */
export async function connectToVoiceChannel( export async function connectToVoiceChannel(
+3 -2
View File
@@ -1,6 +1,7 @@
import { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
import type { CreateWebhook } from "../../types/webhooks/create_webhook.ts"; import type { CreateWebhook } from "../../types/webhooks/create_webhook.ts";
import type { Webhook } from "../../types/webhooks/webhook.ts"; import type { Webhook } from "../../types/webhooks/webhook.ts";
import type {SnakeCasedPropertiesDeep} from "../../types/util.ts";
/** /**
* Create a new webhook. Requires the MANAGE_WEBHOOKS permission. Returns a webhook object on success. Webhook names follow our naming restrictions that can be found in our Usernames and Nicknames documentation, with the following additional stipulations: * Create a new webhook. Requires the MANAGE_WEBHOOKS permission. Returns a webhook object on success. Webhook names follow our naming restrictions that can be found in our Usernames and Nicknames documentation, with the following additional stipulations:
@@ -18,7 +19,7 @@ export async function createWebhook(bot: Bot, channelId: bigint, options: Create
throw new Error(bot.constants.Errors.INVALID_WEBHOOK_NAME); throw new Error(bot.constants.Errors.INVALID_WEBHOOK_NAME);
} }
return await bot.rest.runMethod<Webhook>(bot.rest, "post", bot.constants.endpoints.CHANNEL_WEBHOOKS(channelId), { return await bot.rest.runMethod<SnakeCasedPropertiesDeep<Webhook>>(bot.rest, "post", bot.constants.endpoints.CHANNEL_WEBHOOKS(channelId), {
...options, ...options,
avatar: options.avatar ? await bot.utils.urlToBase64(options.avatar) : undefined, avatar: options.avatar ? await bot.utils.urlToBase64(options.avatar) : undefined,
}); });
+4 -6
View File
@@ -1,10 +1,8 @@
import { rest } from "../../rest/rest.ts"; import type {Bot} from "../../bot.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
/** Delete a webhook permanently. Requires the `MANAGE_WEBHOOKS` permission. Returns a undefined on success */ /** Delete a webhook permanently. Requires the `MANAGE_WEBHOOKS` permission. Returns a undefined on success */
export async function deleteWebhook(channelId: bigint, webhookId: bigint) { export async function deleteWebhook(bot: Bot, channelId: bigint, webhookId: bigint) {
await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]); await bot.utils.requireBotChannelPermissions(bot, channelId, ["MANAGE_WEBHOOKS"]);
return await rest.runMethod<undefined>("delete", endpoints.WEBHOOK_ID(webhookId)); return await bot.rest.runMethod<undefined>(bot.rset,"delete", bot.constants.endpoints.WEBHOOK_ID(webhookId));
} }
@@ -1,6 +1,5 @@
import { rest } from "../../rest/rest.ts"; import type {Bot} from "../../bot.ts";
import { endpoints } from "../../util/constants.ts";
export async function deleteWebhookMessage(webhookId: bigint, webhookToken: string, messageId: bigint) { export async function deleteWebhookMessage(bot: Bot, webhookId: bigint, webhookToken: string, messageId: bigint) {
return await rest.runMethod<undefined>("delete", endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId)); return await bot.rest.runMethod<undefined>(bot.rest,"delete", bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId));
} }
@@ -1,7 +1,6 @@
import { rest } from "../../rest/rest.ts"; import type {Bot} from "../../bot.ts";
import { endpoints } from "../../util/constants.ts";
/** Delete a webhook permanently. Returns a undefined on success */ /** Delete a webhook permanently. Returns a undefined on success */
export async function deleteWebhookWithToken(webhookId: bigint, webhookToken: string) { export async function deleteWebhookWithToken(bot: Bot, webhookId: bigint, webhookToken: string) {
return await rest.runMethod<undefined>("delete", endpoints.WEBHOOK(webhookId, webhookToken)); return await bot.rest.runMethod<undefined>(bot.rest,"delete", bot.constants.endpoints.WEBHOOK(webhookId, webhookToken));
} }
+5 -6
View File
@@ -1,14 +1,13 @@
import { rest } from "../../rest/rest.ts";
import type { ModifyWebhook } from "../../types/webhooks/modify_webhook.ts"; import type { ModifyWebhook } from "../../types/webhooks/modify_webhook.ts";
import type { Webhook } from "../../types/webhooks/webhook.ts"; import type { Webhook } from "../../types/webhooks/webhook.ts";
import { endpoints } from "../../util/constants.ts"; import type {Bot} from "../../bot.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts"; import type {SnakeCasedPropertiesDeep} from "../../types/util.ts";
/** Edit a webhook. Requires the `MANAGE_WEBHOOKS` permission. Returns the updated webhook object on success. */ /** Edit a webhook. Requires the `MANAGE_WEBHOOKS` permission. Returns the updated webhook object on success. */
export async function editWebhook(channelId: bigint, webhookId: bigint, options: ModifyWebhook) { export async function editWebhook(bot: Bot, channelId: bigint, webhookId: bigint, options: ModifyWebhook) {
await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]); await bot.utils.requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]);
return await rest.runMethod<Webhook>("patch", endpoints.WEBHOOK_ID(webhookId), { return await bot.rest.runMethod<SnakeCasedPropertiesDeep<Webhook>>(bot.rest,"patch", bot.constants.endpoints.WEBHOOK_ID(webhookId), {
...options, ...options,
channel_id: options.channelId, channel_id: options.channelId,
}); });
+20 -13
View File
@@ -1,19 +1,17 @@
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { Errors } from "../../types/discordeno/errors.ts";
import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts";
import type { Message } from "../../types/messages/message.ts"; import type { Message } from "../../types/messages/message.ts";
import type { EditWebhookMessage } from "../../types/webhooks/edit_webhook_message.ts"; import type { EditWebhookMessage } from "../../types/webhooks/edit_webhook_message.ts";
import { endpoints } from "../../util/constants.ts"; import type {Bot} from "../../bot.ts";
import { snakelize, validateComponents } from "../../util/utils.ts"; import {DiscordAllowedMentionsTypes} from "../../types/messages/allowed_mentions_types.ts";
import {SnakeCasedPropertiesDeep} from "../../types/util.ts";
export async function editWebhookMessage( export async function editWebhookMessage(
bot: Bot,
webhookId: bigint, webhookId: bigint,
webhookToken: string, webhookToken: string,
options: EditWebhookMessage & { messageId?: bigint } options: EditWebhookMessage & { messageId?: bigint }
) { ) {
if (options.content && options.content.length > 2000) { if (options.content && options.content.length > 2000) {
throw Error(Errors.MESSAGE_MAX_LENGTH); throw Error(bot.constants.Errors.MESSAGE_MAX_LENGTH);
} }
if (options.embeds && options.embeds.length > 10) { if (options.embeds && options.embeds.length > 10) {
@@ -43,16 +41,25 @@ export async function editWebhookMessage(
} }
if (options.components?.length) { if (options.components?.length) {
validateComponents(options.components); bot.utils.validateComponents(options.components);
} }
const result = await rest.runMethod<Message>( const result = await bot.rest.runMethod<SnakeCasedPropertiesDeep<Message>>(
bot.rest,
"patch", "patch",
options.messageId options.messageId
? endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, options.messageId) ? bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, options.messageId)
: endpoints.WEBHOOK_MESSAGE_ORIGINAL(webhookId, webhookToken), : bot.constants.endpoints.WEBHOOK_MESSAGE_ORIGINAL(webhookId, webhookToken),
snakelize(options) {
content: options.content,
embeds: options.embeds,
file: options.file,
allowedMentions: options.allowed_mentions,
attachments: options.attachments,
components: options.components,
message_id: options.messageId
}
); );
return await structures.createDiscordenoMessage(result); return bot.transformers.message(result);
} }
@@ -1,14 +1,17 @@
import { rest } from "../../rest/rest.ts";
import type { ModifyWebhook } from "../../types/webhooks/modify_webhook.ts"; import type { ModifyWebhook } from "../../types/webhooks/modify_webhook.ts";
import type { Webhook } from "../../types/webhooks/webhook.ts"; import type { Webhook } from "../../types/webhooks/webhook.ts";
import { endpoints } from "../../util/constants.ts"; import type {Bot} from "../../bot.ts";
import { snakelize } from "../../util/utils.ts"; import {SnakeCasedPropertiesDeep} from "../../types/util.ts";
/** Edit a webhook. Returns the updated webhook object on success. */ /** Edit a webhook. Returns the updated webhook object on success. */
export async function editWebhookWithToken( export async function editWebhookWithToken(
bot: Bot,
webhookId: bigint, webhookId: bigint,
webhookToken: string, webhookToken: string,
options: Omit<ModifyWebhook, "channelId"> options: Omit<ModifyWebhook, "channelId">
) { ) {
return await rest.runMethod<Webhook>("patch", endpoints.WEBHOOK(webhookId, webhookToken), snakelize(options)); return await bot.rest.runMethod<SnakeCasedPropertiesDeep<Webhook>>(bot.rest,"patch", bot.constants.endpoints.WEBHOOK(webhookId, webhookToken), {
name: options.name,
avatar: options.avatar
});
} }
+4 -4
View File
@@ -1,8 +1,8 @@
import { rest } from "../../rest/rest.ts";
import type { Webhook } from "../../types/webhooks/webhook.ts"; import type { Webhook } from "../../types/webhooks/webhook.ts";
import { endpoints } from "../../util/constants.ts"; import type {Bot} from "../../bot.ts";
import {SnakeCasedPropertiesDeep} from "../../types/util.ts";
/** Returns the new webhook object for the given id. */ /** Returns the new webhook object for the given id. */
export async function getWebhook(webhookId: bigint) { export async function getWebhook(bot: Bot, webhookId: bigint) {
return await rest.runMethod<Webhook>("get", endpoints.WEBHOOK_ID(webhookId)); return await bot.rest.runMethod<SnakeCasedPropertiesDeep<Webhook>>(bot.rest, "get", bot.constants.endpoints.WEBHOOK_ID(webhookId));
} }
+6 -7
View File
@@ -1,11 +1,10 @@
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import type { Message } from "../../types/messages/message.ts"; import type { Message } from "../../types/messages/message.ts";
import { endpoints } from "../../util/constants.ts"; import {SnakeCasedPropertiesDeep} from "../../types/util.ts";
import type {Bot} from "../../bot.ts";
/** Returns a previousy-sent webhook message from the same token. Returns a message object on success. */ /** Returns a previously-sent webhook message from the same token. Returns a message object on success. */
export async function getWebhookMessage(webhookId: bigint, webhookToken: string, messageId: bigint) { export async function getWebhookMessage(bot: Bot, webhookId: bigint, webhookToken: string, messageId: bigint) {
const result = await rest.runMethod<Message>("get", endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId)); const result = await bot.rest.runMethod<SnakeCasedPropertiesDeep<Message>>(bot.rest,"get", bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId));
return await structures.createDiscordenoMessage(result); return bot.transformers.message(result);
} }
@@ -1,8 +1,7 @@
import { rest } from "../../rest/rest.ts";
import type { Webhook } from "../../types/webhooks/webhook.ts"; import type { Webhook } from "../../types/webhooks/webhook.ts";
import { endpoints } from "../../util/constants.ts"; import type {Bot} from "../../bot.ts";
/** Returns the new webhook object for the given id, this call does not require authentication and returns no user in the webhook object. */ /** Returns the new webhook object for the given id, this call does not require authentication and returns no user in the webhook object. */
export async function getWebhookWithToken(webhookId: bigint, token: string) { export async function getWebhookWithToken(bot: Bot, webhookId: bigint, token: string) {
return await rest.runMethod<Webhook>("get", endpoints.WEBHOOK(webhookId, token)); return await bot.rest.runMethod<Webhook>(bot.rest,"get", bot.constants.endpoints.WEBHOOK(webhookId, token));
} }
+5 -6
View File
@@ -1,14 +1,13 @@
import { rest } from "../../rest/rest.ts"; import type {Bot} from "../../bot.ts";
import type { Webhook } from "../../types/webhooks/webhook.ts"; import type { Webhook } from "../../types/webhooks/webhook.ts";
import { Collection } from "../../util/collection.ts"; import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts"; import {SnakeCasedPropertiesDeep} from "../../types/util.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Returns a list of guild webhooks objects. Requires the MANAGE_WEBHOOKs permission. */ /** Returns a list of guild webhooks objects. Requires the MANAGE_WEBHOOKs permission. */
export async function getWebhooks(guildId: bigint) { export async function getWebhooks(bot: Bot, guildId: bigint) {
await requireBotGuildPermissions(guildId, ["MANAGE_WEBHOOKS"]); await bot.utils.requireBotGuildPermissions(guildId, ["MANAGE_WEBHOOKS"]);
const result = await rest.runMethod<Webhook[]>("get", endpoints.GUILD_WEBHOOKS(guildId)); const result = await bot.rest.runMethod<SnakeCasedPropertiesDeep<Webhook>[]>(bot.rest,"get", bot.constants.endpoints.GUILD_WEBHOOKS(guildId));
return new Collection(result.map((webhook) => [webhook.id, webhook])); return new Collection(result.map((webhook) => [webhook.id, webhook]));
} }
+20 -12
View File
@@ -1,20 +1,17 @@
import { rest } from "../../rest/rest.ts"; import type {Bot} from "../../bot.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts"; import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts";
import type { Message } from "../../types/messages/message.ts"; import type { Message } from "../../types/messages/message.ts";
import { Errors } from "../../types/discordeno/errors.ts";
import type { ExecuteWebhook } from "../../types/webhooks/execute_webhook.ts"; import type { ExecuteWebhook } from "../../types/webhooks/execute_webhook.ts";
import { endpoints } from "../../util/constants.ts"; import {SnakeCasedPropertiesDeep} from "../../types/util.ts";
import { snakelize } from "../../util/utils.ts";
/** Send a webhook with webhook Id and webhook token */ /** Send a webhook with webhook Id and webhook token */
export async function sendWebhook(webhookId: bigint, webhookToken: string, options: ExecuteWebhook) { export async function sendWebhook(bot: Bot, webhookId: bigint, webhookToken: string, options: ExecuteWebhook) {
if (!options.content && !options.file && !options.embeds) { if (!options.content && !options.file && !options.embeds) {
throw new Error(Errors.INVALID_WEBHOOK_OPTIONS); throw new Error(bot.constants.Errors.INVALID_WEBHOOK_OPTIONS);
} }
if (options.content && options.content.length > 2000) { if (options.content && options.content.length > 2000) {
throw Error(Errors.MESSAGE_MAX_LENGTH); throw Error(bot.constants.Errors.MESSAGE_MAX_LENGTH);
} }
options.embeds?.splice(10); options.embeds?.splice(10);
@@ -41,14 +38,25 @@ export async function sendWebhook(webhookId: bigint, webhookToken: string, optio
} }
} }
const result = await rest.runMethod<Message>( const result = await bot.rest.runMethod<SnakeCasedPropertiesDeep<Message>>(
bot.rest,
"post", "post",
`${endpoints.WEBHOOK(webhookId, webhookToken)}?wait=${options.wait ?? false}${ `${bot.constants.endpoints.WEBHOOK(webhookId, webhookToken)}?wait=${options.wait ?? false}${
options.threadId ? `&thread_id=${options.threadId}` : "" options.threadId ? `&thread_id=${options.threadId}` : ""
}`, }`,
snakelize(options) {
wait: options.wait,
thread_id: options.threadId,
content: options.content,
username: options.username,
avatar_url: options.avatarUrl,
tts: options.tts,
file: options.file,
embeds: options.embeds,
allowed_mentions: options.allowedMentions,
}
); );
if (!options.wait) return; if (!options.wait) return;
return structures.createDiscordenoMessage(result); return bot.transformers.message(result);
} }