mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
change: prettier code
This commit is contained in:
committed by
GitHub Action
parent
72ffbdc4db
commit
1c1c93ed7f
+2
-2
@@ -125,11 +125,11 @@ import {
|
|||||||
handleIntegrationCreate,
|
handleIntegrationCreate,
|
||||||
handleIntegrationUpdate,
|
handleIntegrationUpdate,
|
||||||
handleIntegrationDelete,
|
handleIntegrationDelete,
|
||||||
handleGuildLoaded
|
handleGuildLoaded,
|
||||||
} from "./handlers/mod.ts";
|
} from "./handlers/mod.ts";
|
||||||
import { DiscordenoInteraction, transformInteraction } from "./transformers/interaction.ts";
|
import { DiscordenoInteraction, transformInteraction } from "./transformers/interaction.ts";
|
||||||
import { DiscordenoIntegration, transformIntegration } from "./transformers/integration.ts";
|
import { DiscordenoIntegration, transformIntegration } from "./transformers/integration.ts";
|
||||||
import {Emoji} from "./types/emojis/emoji.ts";
|
import { Emoji } from "./types/emojis/emoji.ts";
|
||||||
import { transformApplication } from "./transformers/application.ts";
|
import { transformApplication } from "./transformers/application.ts";
|
||||||
import { transformTeam } from "./transformers/team.ts";
|
import { transformTeam } from "./transformers/team.ts";
|
||||||
import { DiscordenoInvite, transformInvite } from "./transformers/invite.ts";
|
import { DiscordenoInvite, transformInvite } from "./transformers/invite.ts";
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
|||||||
export async function handleGuildBanAdd(bot: Bot, data: SnakeCasedPropertiesDeep<DiscordGatewayPayload>) {
|
export async function handleGuildBanAdd(bot: Bot, data: SnakeCasedPropertiesDeep<DiscordGatewayPayload>) {
|
||||||
const payload = data.d as SnakeCasedPropertiesDeep<GuildBanAddRemove>;
|
const payload = data.d as SnakeCasedPropertiesDeep<GuildBanAddRemove>;
|
||||||
// FIRST COMPLETE THE END USERS EVENT
|
// FIRST COMPLETE THE END USERS EVENT
|
||||||
await bot.events.guildBanAdd(bot, bot.transformers.user(bot, payload.user), bot.transformers.snowflake(payload.guild_id));
|
await bot.events.guildBanAdd(
|
||||||
|
bot,
|
||||||
|
bot.transformers.user(bot, payload.user),
|
||||||
|
bot.transformers.snowflake(payload.guild_id)
|
||||||
|
);
|
||||||
// THEN DELETE THE MEMBER
|
// THEN DELETE THE MEMBER
|
||||||
await bot.cache.members.delete(bot.transformers.snowflake(payload.user.id));
|
await bot.cache.members.delete(bot.transformers.snowflake(payload.user.id));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ export async function handleGuildDelete(bot: Bot, data: DiscordGatewayPayload, s
|
|||||||
|
|
||||||
await bot.cache.guilds.delete(id);
|
await bot.cache.guilds.delete(id);
|
||||||
|
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
bot.cache.forEach("DELETE_MESSAGES_FROM_GUILD", { guildId: guild.id }),
|
bot.cache.forEach("DELETE_MESSAGES_FROM_GUILD", { guildId: guild.id }),
|
||||||
bot.cache.forEach("DELETE_CHANNELS_FROM_GUILD", { guildId: guild.id }),
|
bot.cache.forEach("DELETE_CHANNELS_FROM_GUILD", { guildId: guild.id }),
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {Bot} from "../../bot.ts";
|
import { Bot } from "../../bot.ts";
|
||||||
|
|
||||||
/** Gets an array of all the channels ids that are the children of this category.
|
/** Gets an array of all the channels ids that are the children of this category.
|
||||||
* ⚠️ This does not work for custom cache users!
|
* ⚠️ This does not work for custom cache users!
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ export async function createChannel(bot: Bot, guildId: bigint, options?: CreateG
|
|||||||
bot.rest,
|
bot.rest,
|
||||||
"post",
|
"post",
|
||||||
bot.constants.endpoints.GUILD_CHANNELS(guildId),
|
bot.constants.endpoints.GUILD_CHANNELS(guildId),
|
||||||
options ? {
|
options
|
||||||
|
? {
|
||||||
name: options.name,
|
name: options.name,
|
||||||
topic: options.topic,
|
topic: options.topic,
|
||||||
bitrate: options.bitrate,
|
bitrate: options.bitrate,
|
||||||
@@ -32,7 +33,8 @@ export async function createChannel(bot: Bot, guildId: bigint, options?: CreateG
|
|||||||
})),
|
})),
|
||||||
type: options?.type || DiscordChannelTypes.GuildText,
|
type: options?.type || DiscordChannelTypes.GuildText,
|
||||||
reason,
|
reason,
|
||||||
} : {}
|
}
|
||||||
|
: {}
|
||||||
);
|
);
|
||||||
|
|
||||||
const discordenoChannel = bot.transformers.channel(result);
|
const discordenoChannel = bot.transformers.channel(result);
|
||||||
|
|||||||
@@ -19,14 +19,9 @@ export async function createStageInstance(bot: Bot, channelId: bigint, topic: st
|
|||||||
throw new Error(bot.constants.Errors.INVALID_TOPIC_LENGTH);
|
throw new Error(bot.constants.Errors.INVALID_TOPIC_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await bot.rest.runMethod<StageInstance>(
|
return await bot.rest.runMethod<StageInstance>(bot.rest, "post", bot.constants.endpoints.STAGE_INSTANCES, {
|
||||||
bot.rest,
|
|
||||||
"post",
|
|
||||||
bot.constants.endpoints.STAGE_INSTANCES,
|
|
||||||
{
|
|
||||||
channel_id: channelId,
|
channel_id: channelId,
|
||||||
topic,
|
topic,
|
||||||
privacy_level: privacyLevel,
|
privacy_level: privacyLevel,
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,5 +19,7 @@ export async function deleteChannel(bot: Bot, channelId: bigint, reason?: string
|
|||||||
await bot.utils.requireBotGuildPermissions(bot, guild, ["MANAGE_CHANNELS"]);
|
await bot.utils.requireBotGuildPermissions(bot, guild, ["MANAGE_CHANNELS"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await bot.rest.runMethod<undefined>(bot.rest, "delete", bot.constants.endpoints.CHANNEL_BASE(channelId), { reason });
|
return await bot.rest.runMethod<undefined>(bot.rest, "delete", bot.constants.endpoints.CHANNEL_BASE(channelId), {
|
||||||
|
reason,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,5 +9,9 @@ export async function deleteChannelOverwrite(
|
|||||||
): Promise<undefined> {
|
): Promise<undefined> {
|
||||||
await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]);
|
await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]);
|
||||||
|
|
||||||
return await bot.rest.runMethod<undefined>(bot.rest,"delete", bot.constants.endpoints.CHANNEL_OVERWRITE(channelId, overwriteId));
|
return await bot.rest.runMethod<undefined>(
|
||||||
|
bot.rest,
|
||||||
|
"delete",
|
||||||
|
bot.constants.endpoints.CHANNEL_OVERWRITE(channelId, overwriteId)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { DiscordenoChannel } from "../../structures/channel.ts";
|
|||||||
import type { Channel } from "../../types/channels/channel.ts";
|
import type { Channel } from "../../types/channels/channel.ts";
|
||||||
import type { ModifyChannel } from "../../types/channels/modify_channel.ts";
|
import type { ModifyChannel } from "../../types/channels/modify_channel.ts";
|
||||||
import type { Bot } from "../../bot.ts";
|
import type { Bot } from "../../bot.ts";
|
||||||
import {SnakeCasedPropertiesDeep} from "../../types/util.ts";
|
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||||
|
|
||||||
/** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */
|
/** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */
|
||||||
export async function editChannel(bot: Bot, channelId: bigint, options: ModifyChannel, reason?: string) {
|
export async function editChannel(bot: Bot, channelId: bigint, options: ModifyChannel, reason?: string) {
|
||||||
@@ -103,13 +103,15 @@ function processEditChannelQueue(bot: Bot) {
|
|||||||
|
|
||||||
if (!details) return;
|
if (!details) return;
|
||||||
|
|
||||||
await bot.helpers.editChannel(bot, details.channelId, details.options)
|
await bot.helpers
|
||||||
|
.editChannel(bot, details.channelId, details.options)
|
||||||
.then((result) => details.resolve(result))
|
.then((result) => details.resolve(result))
|
||||||
.catch(details.reject);
|
.catch(details.reject);
|
||||||
const secondDetails = request.items.shift();
|
const secondDetails = request.items.shift();
|
||||||
if (!secondDetails) return;
|
if (!secondDetails) return;
|
||||||
|
|
||||||
await bot.helpers.editChannel(bot, secondDetails.channelId, secondDetails.options)
|
await bot.helpers
|
||||||
|
.editChannel(bot, secondDetails.channelId, secondDetails.options)
|
||||||
.then((result) => secondDetails.resolve(result))
|
.then((result) => secondDetails.resolve(result))
|
||||||
.catch(secondDetails.reject);
|
.catch(secondDetails.reject);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -11,9 +11,14 @@ export async function editChannelOverwrite(
|
|||||||
): Promise<undefined> {
|
): Promise<undefined> {
|
||||||
await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]);
|
await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]);
|
||||||
|
|
||||||
return await bot.rest.runMethod<undefined>(bot.rest,"put", bot.constants.endpoints.CHANNEL_OVERWRITE(channelId, overwriteId), {
|
return await bot.rest.runMethod<undefined>(
|
||||||
|
bot.rest,
|
||||||
|
"put",
|
||||||
|
bot.constants.endpoints.CHANNEL_OVERWRITE(channelId, overwriteId),
|
||||||
|
{
|
||||||
allow: bot.utils.calculateBits(options.allow),
|
allow: bot.utils.calculateBits(options.allow),
|
||||||
deny: bot.utils.calculateBits(options.deny),
|
deny: bot.utils.calculateBits(options.deny),
|
||||||
type: options.type,
|
type: options.type,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,14 @@ import type { Bot } from "../../bot.ts";
|
|||||||
export async function followChannel(bot: Bot, sourceChannelId: bigint, targetChannelId: bigint) {
|
export async function followChannel(bot: Bot, sourceChannelId: bigint, targetChannelId: bigint) {
|
||||||
await bot.utils.requireBotChannelPermissions(bot, targetChannelId, ["MANAGE_WEBHOOKS"]);
|
await bot.utils.requireBotChannelPermissions(bot, targetChannelId, ["MANAGE_WEBHOOKS"]);
|
||||||
|
|
||||||
const data = await bot.rest.runMethod<FollowedChannel>(bot.rest,"post", bot.constants.endpoints.CHANNEL_FOLLOW(sourceChannelId), {
|
const data = await bot.rest.runMethod<FollowedChannel>(
|
||||||
|
bot.rest,
|
||||||
|
"post",
|
||||||
|
bot.constants.endpoints.CHANNEL_FOLLOW(sourceChannelId),
|
||||||
|
{
|
||||||
webhook_channel_id: targetChannelId,
|
webhook_channel_id: targetChannelId,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return data.webhookId;
|
return data.webhookId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,14 +6,12 @@ import type { Channel } from "../../types/channels/channel.ts";
|
|||||||
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
|
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
|
||||||
*/
|
*/
|
||||||
export async function getChannel(bot: Bot, channelId: bigint, addToCache = true) {
|
export async function getChannel(bot: Bot, channelId: bigint, addToCache = true) {
|
||||||
const result = await bot.rest.runMethod<Channel>(bot.rest,"get", bot.constants.endpoints.CHANNEL_BASE(channelId));
|
const result = await bot.rest.runMethod<Channel>(bot.rest, "get", bot.constants.endpoints.CHANNEL_BASE(channelId));
|
||||||
|
|
||||||
const discordenoChannel = bot.transformers.channel(
|
const discordenoChannel = bot.transformers.channel({
|
||||||
{
|
|
||||||
channel: result,
|
channel: result,
|
||||||
guildId: result.guildId ? bot.transformers.snowflake(result.guildId) : undefined
|
guildId: result.guildId ? bot.transformers.snowflake(result.guildId) : undefined,
|
||||||
}
|
});
|
||||||
);
|
|
||||||
if (addToCache) {
|
if (addToCache) {
|
||||||
await bot.cache.channels.set(discordenoChannel.id, discordenoChannel);
|
await bot.cache.channels.set(discordenoChannel.id, discordenoChannel);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ import type { Bot } from "../../bot.ts";
|
|||||||
export async function getChannelWebhooks(bot: Bot, channelId: bigint) {
|
export async function getChannelWebhooks(bot: Bot, channelId: bigint) {
|
||||||
await bot.utils.requireBotChannelPermissions(bot, channelId, ["MANAGE_WEBHOOKS"]);
|
await bot.utils.requireBotChannelPermissions(bot, channelId, ["MANAGE_WEBHOOKS"]);
|
||||||
|
|
||||||
const result = await bot.rest.runMethod<Webhook[]>(bot.rest,"get", bot.constants.endpoints.CHANNEL_WEBHOOKS(channelId));
|
const result = await bot.rest.runMethod<Webhook[]>(
|
||||||
|
bot.rest,
|
||||||
|
"get",
|
||||||
|
bot.constants.endpoints.CHANNEL_WEBHOOKS(channelId)
|
||||||
|
);
|
||||||
|
|
||||||
return new Collection(result.map((webhook) => [webhook.id, webhook]));
|
return new Collection(result.map((webhook) => [webhook.id, webhook]));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ import type { Bot } from "../../bot.ts";
|
|||||||
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
|
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
|
||||||
*/
|
*/
|
||||||
export async function getChannels(bot: Bot, guildId: bigint, addToCache = true) {
|
export async function getChannels(bot: Bot, guildId: bigint, addToCache = true) {
|
||||||
const result = await bot.rest.runMethod<Channel[]>(bot.rest,"get", bot.constants.endpoints.GUILD_CHANNELS(guildId));
|
const result = await bot.rest.runMethod<Channel[]>(bot.rest, "get", bot.constants.endpoints.GUILD_CHANNELS(guildId));
|
||||||
|
|
||||||
return new Collection(
|
return new Collection(
|
||||||
(
|
(
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
result.map(async (res) => {
|
result.map(async (res) => {
|
||||||
const discordenoChannel = await bot.transformers.channel({channel: res, guildId});
|
const discordenoChannel = await bot.transformers.channel({ channel: res, guildId });
|
||||||
if (addToCache) {
|
if (addToCache) {
|
||||||
await bot.cache.channels.set(discordenoChannel.id, discordenoChannel);
|
await bot.cache.channels.set(discordenoChannel.id, discordenoChannel);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import type { Bot } from "../../bot.ts";
|
|||||||
|
|
||||||
/** Get pinned messages in this channel. */
|
/** Get pinned messages in this channel. */
|
||||||
export async function getPins(bot: Bot, channelId: bigint) {
|
export async function getPins(bot: Bot, channelId: bigint) {
|
||||||
const result = await bot.rest.runMethod<Message[]>(bot.rest,"get", bot.constants.endpoints.CHANNEL_PINS(channelId));
|
const result = await bot.rest.runMethod<Message[]>(bot.rest, "get", bot.constants.endpoints.CHANNEL_PINS(channelId));
|
||||||
|
|
||||||
return result.map(bot.transformers.message);
|
return result.map(bot.transformers.message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,5 +12,5 @@ export async function getStageInstance(bot: Bot, channelId: bigint) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return await bot.rest.runMethod<StageInstance>(bot.rest,"get", bot.constants.endpoints.STAGE_INSTANCE(channelId));
|
return await bot.rest.runMethod<StageInstance>(bot.rest, "get", bot.constants.endpoints.STAGE_INSTANCE(channelId));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,5 +29,5 @@ export async function startTyping(bot: Bot, channelId: bigint) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return await bot.rest.runMethod<undefined>(bot.rest,"post", bot.constants.endpoints.CHANNEL_TYPING(channelId));
|
return await bot.rest.runMethod<undefined>(bot.rest, "post", bot.constants.endpoints.CHANNEL_TYPING(channelId));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,17 @@ export async function swapChannels(bot: Bot, guildId: bigint, channelPositions:
|
|||||||
throw "You must provide at least two channels to be swapped.";
|
throw "You must provide at least two channels to be swapped.";
|
||||||
}
|
}
|
||||||
|
|
||||||
return await bot.rest.runMethod<undefined>(bot.rest,"patch", bot.constants.endpoints.GUILD_CHANNELS(guildId), channelPositions.map((channelPosition) => {
|
return await bot.rest.runMethod<undefined>(
|
||||||
|
bot.rest,
|
||||||
|
"patch",
|
||||||
|
bot.constants.endpoints.GUILD_CHANNELS(guildId),
|
||||||
|
channelPositions.map((channelPosition) => {
|
||||||
return {
|
return {
|
||||||
id: channelPosition.id,
|
id: channelPosition.id,
|
||||||
position: channelPosition.position,
|
position: channelPosition.position,
|
||||||
lock_positions: channelPosition.lockPositions,
|
lock_positions: channelPosition.lockPositions,
|
||||||
parent_id: channelPosition.parentId
|
parent_id: channelPosition.parentId,
|
||||||
}
|
};
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ export async function updateStageInstance(
|
|||||||
throw new Error(bot.constants.Errors.INVALID_TOPIC_LENGTH);
|
throw new Error(bot.constants.Errors.INVALID_TOPIC_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await bot.rest.runMethod<StageInstance>(bot.rest,"patch", bot.constants.endpoints.STAGE_INSTANCE(channelId), {
|
return await bot.rest.runMethod<StageInstance>(bot.rest, "patch", bot.constants.endpoints.STAGE_INSTANCE(channelId), {
|
||||||
topic: data.topic,
|
topic: data.topic,
|
||||||
privacy_level: data.privacyLevel
|
privacy_level: data.privacyLevel,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,12 +20,15 @@ export async function updateBotVoiceState(
|
|||||||
return await bot.rest.runMethod(
|
return await bot.rest.runMethod(
|
||||||
bot.rest,
|
bot.rest,
|
||||||
"patch",
|
"patch",
|
||||||
bot.constants.endpoints.UPDATE_VOICE_STATE(guildId, bot.utils.hasOwnProperty(options, "userId") ? options.userId : undefined),
|
bot.constants.endpoints.UPDATE_VOICE_STATE(
|
||||||
|
guildId,
|
||||||
|
bot.utils.hasOwnProperty(options, "userId") ? options.userId : undefined
|
||||||
|
),
|
||||||
{
|
{
|
||||||
channel_id: options.channelId,
|
channel_id: options.channelId,
|
||||||
suppress: options.suppress,
|
suppress: options.suppress,
|
||||||
request_to_speak_timestamp: options.requestToSpeakTimestamp,
|
request_to_speak_timestamp: options.requestToSpeakTimestamp,
|
||||||
user_id: options.userId
|
user_id: options.userId,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,13 @@ import { Collection } from "../../util/collection.ts";
|
|||||||
import type { Bot } from "../../bot.ts";
|
import type { Bot } from "../../bot.ts";
|
||||||
|
|
||||||
/** Get a list of users that reacted with this emoji. */
|
/** Get a list of users that reacted with this emoji. */
|
||||||
export async function getReactions(bot: Bot, channelId: bigint, messageId: bigint, reaction: string, options?: GetReactions) {
|
export async function getReactions(
|
||||||
|
bot: Bot,
|
||||||
|
channelId: bigint,
|
||||||
|
messageId: bigint,
|
||||||
|
reaction: string,
|
||||||
|
options?: GetReactions
|
||||||
|
) {
|
||||||
const users = await bot.rest.runMethod<User[]>(
|
const users = await bot.rest.runMethod<User[]>(
|
||||||
bot.rest,
|
bot.rest,
|
||||||
"get",
|
"get",
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ import type { Bot } from "../../bot.ts";
|
|||||||
export async function pin(bot: Bot, channelId: bigint, messageId: bigint) {
|
export async function pin(bot: Bot, channelId: bigint, messageId: bigint) {
|
||||||
await bot.utils.requireBotChannelPermissions(bot, channelId, ["MANAGE_MESSAGES"]);
|
await bot.utils.requireBotChannelPermissions(bot, channelId, ["MANAGE_MESSAGES"]);
|
||||||
|
|
||||||
return await bot.rest.runMethod<undefined>(bot.rest,"put", bot.constants.endpoints.CHANNEL_PIN(channelId, messageId));
|
return await bot.rest.runMethod<undefined>(
|
||||||
|
bot.rest,
|
||||||
|
"put",
|
||||||
|
bot.constants.endpoints.CHANNEL_PIN(channelId, messageId)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// aliases
|
// aliases
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { 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";
|
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:
|
||||||
@@ -19,8 +19,13 @@ 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<SnakeCasedPropertiesDeep<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,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type {Bot} from "../../bot.ts";
|
import type { Bot } from "../../bot.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(bot: Bot, channelId: bigint, webhookId: bigint) {
|
export async function deleteWebhook(bot: Bot, channelId: bigint, webhookId: bigint) {
|
||||||
await bot.utils.requireBotChannelPermissions(bot, channelId, ["MANAGE_WEBHOOKS"]);
|
await bot.utils.requireBotChannelPermissions(bot, channelId, ["MANAGE_WEBHOOKS"]);
|
||||||
|
|
||||||
return await bot.rest.runMethod<undefined>(bot.rset,"delete", bot.constants.endpoints.WEBHOOK_ID(webhookId));
|
return await bot.rest.runMethod<undefined>(bot.rset, "delete", bot.constants.endpoints.WEBHOOK_ID(webhookId));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import type {Bot} from "../../bot.ts";
|
import type { Bot } from "../../bot.ts";
|
||||||
|
|
||||||
export async function deleteWebhookMessage(bot: Bot, webhookId: bigint, webhookToken: string, messageId: bigint) {
|
export async function deleteWebhookMessage(bot: Bot, webhookId: bigint, webhookToken: string, messageId: bigint) {
|
||||||
return await bot.rest.runMethod<undefined>(bot.rest,"delete", bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId));
|
return await bot.rest.runMethod<undefined>(
|
||||||
|
bot.rest,
|
||||||
|
"delete",
|
||||||
|
bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import type {Bot} from "../../bot.ts";
|
import type { Bot } from "../../bot.ts";
|
||||||
|
|
||||||
/** Delete a webhook permanently. Returns a undefined on success */
|
/** Delete a webhook permanently. Returns a undefined on success */
|
||||||
export async function deleteWebhookWithToken(bot: Bot, webhookId: bigint, webhookToken: string) {
|
export async function deleteWebhookWithToken(bot: Bot, webhookId: bigint, webhookToken: string) {
|
||||||
return await bot.rest.runMethod<undefined>(bot.rest,"delete", bot.constants.endpoints.WEBHOOK(webhookId, webhookToken));
|
return await bot.rest.runMethod<undefined>(
|
||||||
|
bot.rest,
|
||||||
|
"delete",
|
||||||
|
bot.constants.endpoints.WEBHOOK(webhookId, webhookToken)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
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 type {Bot} from "../../bot.ts";
|
import type { Bot } from "../../bot.ts";
|
||||||
import type {SnakeCasedPropertiesDeep} from "../../types/util.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(bot: Bot, channelId: bigint, webhookId: bigint, options: ModifyWebhook) {
|
export async function editWebhook(bot: Bot, channelId: bigint, webhookId: bigint, options: ModifyWebhook) {
|
||||||
await bot.utils.requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]);
|
await bot.utils.requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]);
|
||||||
|
|
||||||
return await bot.rest.runMethod<SnakeCasedPropertiesDeep<Webhook>>(bot.rest,"patch", bot.constants.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,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { Webhook } from "../../types/webhooks/webhook.ts";
|
import type { Webhook } from "../../types/webhooks/webhook.ts";
|
||||||
import type {Bot} from "../../bot.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(bot: Bot, webhookId: bigint, token: string) {
|
export async function getWebhookWithToken(bot: Bot, webhookId: bigint, token: string) {
|
||||||
return await bot.rest.runMethod<Webhook>(bot.rest,"get", bot.constants.endpoints.WEBHOOK(webhookId, token));
|
return await bot.rest.runMethod<Webhook>(bot.rest, "get", bot.constants.endpoints.WEBHOOK(webhookId, token));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user