mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
refactor: rename *ID to *Id (#710)
* refactor: rename *ID to *Id * Update src/helpers/commands/delete_slash_command.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/commands/delete_slash_command.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/commands/delete_slash_response.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/commands/edit_slash_response.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/util/utils.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/util/utils.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/util/utils.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/util/utils.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/util/utils.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/commands/get_slash_command.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/commands/send_interaction_response.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/commands/upsert_slash_command.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/guilds/edit_widget.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/guilds/get_widget.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/guilds/get_widget.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/guilds/get_widget_image_url.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/guilds/get_widget_image_url.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/guilds/get_widget_settings.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update .gitignore Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update LICENSE Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/members/edit_bot_profile.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/members/edit_bot_profile.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/webhooks/create_webhook.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/webhooks/delete_webhook.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/util/constants.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/webhooks/edit_webhook.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/webhooks/execute_webhook.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/webhooks/get_webhook.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/rest/cache.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/rest/request.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/util/constants.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/helpers/commands/delete_slash_response.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/util/constants.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/util/constants.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/util/constants.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/util/constants.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/util/utils.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Update src/util/utils.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * Revert docs file Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>
This commit is contained in:
+18
-18
@@ -9,14 +9,14 @@ import { spawnShards } from "./ws/shard_manager.ts";
|
|||||||
|
|
||||||
export let authorization = "";
|
export let authorization = "";
|
||||||
export let restAuthorization = "";
|
export let restAuthorization = "";
|
||||||
export let botID = "";
|
export let botId = "";
|
||||||
export let applicationID = "";
|
export let applicationId = "";
|
||||||
|
|
||||||
export let eventHandlers: EventHandlers = {};
|
export let eventHandlers: EventHandlers = {};
|
||||||
|
|
||||||
export let botGatewayData: DiscordGetGatewayBot;
|
export let botGatewayData: DiscordGetGatewayBot;
|
||||||
export let proxyWSURL = `wss://gateway.discord.gg`;
|
export let proxyWSURL = `wss://gateway.discord.gg`;
|
||||||
export let lastShardID = 0;
|
export let lastShardId = 0;
|
||||||
|
|
||||||
export const identifyPayload: DiscordIdentify = {
|
export const identifyPayload: DiscordIdentify = {
|
||||||
token: "",
|
token: "",
|
||||||
@@ -51,10 +51,10 @@ export async function startBot(config: BotConfig) {
|
|||||||
: next),
|
: next),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
lastShardID = botGatewayData.shards;
|
lastShardId = botGatewayData.shards;
|
||||||
identifyPayload.shard = [0, lastShardID];
|
identifyPayload.shard = [0, lastShardId];
|
||||||
|
|
||||||
await spawnShards(botGatewayData, identifyPayload, 0, lastShardID);
|
await spawnShards(botGatewayData, identifyPayload, 0, lastShardId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Allows you to dynamically update the event handlers by passing in new eventHandlers */
|
/** Allows you to dynamically update the event handlers by passing in new eventHandlers */
|
||||||
@@ -65,14 +65,14 @@ export function updateEventHandlers(newEventHandlers: EventHandlers) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** INTERNAL LIB function used to set the bot ID once the READY event is sent by Discord. */
|
/** INTERNAL LIB function used to set the bot Id once the READY event is sent by Discord. */
|
||||||
export function setBotID(id: string) {
|
export function setBotId(id: string) {
|
||||||
if (botID !== id) botID = id;
|
if (botId !== id) botId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** INTERNAL LIB function used to set the application ID once the READY event is sent by Discord. */
|
/** INTERNAL LIB function used to set the application Id once the READY event is sent by Discord. */
|
||||||
export function setApplicationID(id: string) {
|
export function setApplicationId(id: string) {
|
||||||
if (applicationID !== id) applicationID = id;
|
if (applicationId !== id) applicationId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// BIG BRAIN BOT STUFF ONLY BELOW THIS
|
// BIG BRAIN BOT STUFF ONLY BELOW THIS
|
||||||
@@ -113,10 +113,10 @@ export async function startBigBrainBot(data: BigBrainBotConfig) {
|
|||||||
await spawnShards(
|
await spawnShards(
|
||||||
botGatewayData,
|
botGatewayData,
|
||||||
identifyPayload,
|
identifyPayload,
|
||||||
data.firstShardID,
|
data.firstShardId,
|
||||||
data.lastShardID ||
|
data.lastShardId ||
|
||||||
(botGatewayData.shards >= 25
|
(botGatewayData.shards >= 25
|
||||||
? (data.firstShardID + 25)
|
? (data.firstShardId + 25)
|
||||||
: botGatewayData.shards),
|
: botGatewayData.shards),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -130,9 +130,9 @@ export interface BotConfig {
|
|||||||
|
|
||||||
export interface BigBrainBotConfig extends BotConfig {
|
export interface BigBrainBotConfig extends BotConfig {
|
||||||
/** The first shard to start at for this worker. Use this to control which shards to run in each worker. */
|
/** The first shard to start at for this worker. Use this to control which shards to run in each worker. */
|
||||||
firstShardID: number;
|
firstShardId: number;
|
||||||
/** The last shard to start for this worker. By default it will be 25 + the firstShardID. */
|
/** The last shard to start for this worker. By default it will be 25 + the firstShardId. */
|
||||||
lastShardID?: number;
|
lastShardId?: number;
|
||||||
/** This can be used to forward the ws handling to a proxy. */
|
/** This can be used to forward the ws handling to a proxy. */
|
||||||
wsURL?: string;
|
wsURL?: string;
|
||||||
/** This can be used to forward the REST handling to a proxy. */
|
/** This can be used to forward the REST handling to a proxy. */
|
||||||
|
|||||||
+6
-6
@@ -5,17 +5,17 @@ import { Collection } from "./util/collection.ts";
|
|||||||
|
|
||||||
export const cache: CacheData = {
|
export const cache: CacheData = {
|
||||||
isReady: false,
|
isReady: false,
|
||||||
/** All of the guild objects the bot has access to, mapped by their IDs */
|
/** All of the guild objects the bot has access to, mapped by their Ids */
|
||||||
guilds: new Collection(),
|
guilds: new Collection(),
|
||||||
/** All of the channel objects the bot has access to, mapped by their IDs */
|
/** All of the channel objects the bot has access to, mapped by their Ids */
|
||||||
channels: new Collection(),
|
channels: new Collection(),
|
||||||
/** All of the message objects the bot has cached since the bot acquired `READY` state, mapped by their IDs */
|
/** All of the message objects the bot has cached since the bot acquired `READY` state, mapped by their Ids */
|
||||||
messages: new Collection(),
|
messages: new Collection(),
|
||||||
/** All of the member objects that have been cached since the bot acquired `READY` state, mapped by their IDs */
|
/** All of the member objects that have been cached since the bot acquired `READY` state, mapped by their Ids */
|
||||||
members: new Collection(),
|
members: new Collection(),
|
||||||
/** All of the unavailable guilds, mapped by their IDs (id, shardID) */
|
/** All of the unavailable guilds, mapped by their Ids (id, shardId) */
|
||||||
unavailableGuilds: new Collection(),
|
unavailableGuilds: new Collection(),
|
||||||
/** All of the presence update objects received in PRESENCE_UPDATE gateway event, mapped by their user ID */
|
/** All of the presence update objects received in PRESENCE_UPDATE gateway event, mapped by their user Id */
|
||||||
presences: new Collection(),
|
presences: new Collection(),
|
||||||
fetchAllMembersProcessingRequests: new Collection(),
|
fetchAllMembersProcessingRequests: new Collection(),
|
||||||
executedSlashCommands: new Collection(),
|
executedSlashCommands: new Collection(),
|
||||||
|
|||||||
@@ -13,22 +13,22 @@ export async function handleChannelDelete(data: DiscordGatewayPayload) {
|
|||||||
|
|
||||||
if (guild) {
|
if (guild) {
|
||||||
return Promise.all(guild.voiceStates.map(async (vs, key) => {
|
return Promise.all(guild.voiceStates.map(async (vs, key) => {
|
||||||
if (vs.channelID !== payload.id) return;
|
if (vs.channelId !== payload.id) return;
|
||||||
|
|
||||||
// Since this channel was deleted all voice states for this channel should be deleted
|
// Since this channel was deleted all voice states for this channel should be deleted
|
||||||
guild.voiceStates.delete(key);
|
guild.voiceStates.delete(key);
|
||||||
|
|
||||||
const member = await cacheHandlers.get("members", vs.userID);
|
const member = await cacheHandlers.get("members", vs.userId);
|
||||||
if (!member) return;
|
if (!member) return;
|
||||||
|
|
||||||
eventHandlers.voiceChannelLeave?.(member, vs.channelID);
|
eventHandlers.voiceChannelLeave?.(member, vs.channelId);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await cacheHandlers.delete("channels", payload.id);
|
await cacheHandlers.delete("channels", payload.id);
|
||||||
cacheHandlers.forEach("messages", (message) => {
|
cacheHandlers.forEach("messages", (message) => {
|
||||||
if (message.channelID === payload.id) {
|
if (message.channelId === payload.id) {
|
||||||
cacheHandlers.delete("messages", message.id);
|
cacheHandlers.delete("messages", message.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { basicShards } from "../../ws/shard.ts";
|
|||||||
|
|
||||||
export async function handleGuildCreate(
|
export async function handleGuildCreate(
|
||||||
data: DiscordGatewayPayload,
|
data: DiscordGatewayPayload,
|
||||||
shardID: number,
|
shardId: number,
|
||||||
) {
|
) {
|
||||||
const payload = data.d as DiscordGuild;
|
const payload = data.d as DiscordGuild;
|
||||||
// When shards resume they emit GUILD_CREATE again.
|
// When shards resume they emit GUILD_CREATE again.
|
||||||
@@ -14,16 +14,16 @@ export async function handleGuildCreate(
|
|||||||
|
|
||||||
const guildStruct = await structures.createGuildStruct(
|
const guildStruct = await structures.createGuildStruct(
|
||||||
data.d,
|
data.d,
|
||||||
shardID,
|
shardId,
|
||||||
);
|
);
|
||||||
await cacheHandlers.set("guilds", guildStruct.id, guildStruct);
|
await cacheHandlers.set("guilds", guildStruct.id, guildStruct);
|
||||||
|
|
||||||
const shard = basicShards.get(shardID);
|
const shard = basicShards.get(shardId);
|
||||||
|
|
||||||
if (shard?.unavailableGuildIDs.has(payload.id)) {
|
if (shard?.unavailableGuildIds.has(payload.id)) {
|
||||||
await cacheHandlers.delete("unavailableGuilds", payload.id);
|
await cacheHandlers.delete("unavailableGuilds", payload.id);
|
||||||
|
|
||||||
shard.unavailableGuildIDs.delete(payload.id);
|
shard.unavailableGuildIds.delete(payload.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cache.isReady) return eventHandlers.guildLoaded?.(guildStruct);
|
if (!cache.isReady) return eventHandlers.guildLoaded?.(guildStruct);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { basicShards } from "../../ws/shard.ts";
|
|||||||
|
|
||||||
export async function handleGuildDelete(
|
export async function handleGuildDelete(
|
||||||
data: DiscordGatewayPayload,
|
data: DiscordGatewayPayload,
|
||||||
shardID: number,
|
shardId: number,
|
||||||
) {
|
) {
|
||||||
const payload = data.d as DiscordUnavailableGuild;
|
const payload = data.d as DiscordUnavailableGuild;
|
||||||
|
|
||||||
@@ -15,8 +15,8 @@ export async function handleGuildDelete(
|
|||||||
await cacheHandlers.delete("guilds", payload.id);
|
await cacheHandlers.delete("guilds", payload.id);
|
||||||
|
|
||||||
if (payload.unavailable) {
|
if (payload.unavailable) {
|
||||||
const shard = basicShards.get(shardID);
|
const shard = basicShards.get(shardId);
|
||||||
if (shard) shard.unavailableGuildIDs.add(payload.id);
|
if (shard) shard.unavailableGuildIds.add(payload.id);
|
||||||
|
|
||||||
await cacheHandlers.set("unavailableGuilds", payload.id, Date.now());
|
await cacheHandlers.set("unavailableGuilds", payload.id, Date.now());
|
||||||
}
|
}
|
||||||
@@ -24,13 +24,13 @@ export async function handleGuildDelete(
|
|||||||
eventHandlers.guildDelete?.(guild);
|
eventHandlers.guildDelete?.(guild);
|
||||||
|
|
||||||
cacheHandlers.forEach("messages", (message) => {
|
cacheHandlers.forEach("messages", (message) => {
|
||||||
if (message.guildID === payload.id) {
|
if (message.guildId === payload.id) {
|
||||||
cacheHandlers.delete("messages", message.id);
|
cacheHandlers.delete("messages", message.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
cacheHandlers.forEach("channels", (channel) => {
|
cacheHandlers.forEach("channels", (channel) => {
|
||||||
if (channel.guildID === payload.id) {
|
if (channel.guildId === payload.id) {
|
||||||
cacheHandlers.delete("channels", channel.id);
|
cacheHandlers.delete("channels", channel.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ import {
|
|||||||
|
|
||||||
export function handleInviteDelete(payload: DiscordGatewayPayload) {
|
export function handleInviteDelete(payload: DiscordGatewayPayload) {
|
||||||
const {
|
const {
|
||||||
channel_id: channelID,
|
channel_id: channelId,
|
||||||
guild_id: guildID,
|
guild_id: guildId,
|
||||||
...rest
|
...rest
|
||||||
} = payload.d as DiscordInviteDelete;
|
} = payload.d as DiscordInviteDelete;
|
||||||
|
|
||||||
eventHandlers.inviteDelete?.({
|
eventHandlers.inviteDelete?.({
|
||||||
...rest,
|
...rest,
|
||||||
channelID,
|
channelId,
|
||||||
guildID,
|
guildId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,16 +44,16 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
|
|||||||
eventHandlers.membershipScreeningPassed?.(guild, memberStruct);
|
eventHandlers.membershipScreeningPassed?.(guild, memberStruct);
|
||||||
}
|
}
|
||||||
|
|
||||||
const roleIDs = guildMember?.roles || [];
|
const roleIds = guildMember?.roles || [];
|
||||||
|
|
||||||
roleIDs.forEach((id) => {
|
roleIds.forEach((id) => {
|
||||||
if (!payload.roles.includes(id)) {
|
if (!payload.roles.includes(id)) {
|
||||||
eventHandlers.roleLost?.(guild, memberStruct, id);
|
eventHandlers.roleLost?.(guild, memberStruct, id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
payload.roles.forEach((id) => {
|
payload.roles.forEach((id) => {
|
||||||
if (!roleIDs.includes(id)) {
|
if (!roleIds.includes(id)) {
|
||||||
eventHandlers.roleGained?.(guild, memberStruct, id);
|
eventHandlers.roleGained?.(guild, memberStruct, id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { DiscordGatewayPayload } from "../../types/gateway.ts";
|
|||||||
export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as DiscordMessage;
|
const payload = data.d as DiscordMessage;
|
||||||
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
||||||
if (channel) channel.lastMessageID = payload.id;
|
if (channel) channel.lastMessageId = payload.id;
|
||||||
|
|
||||||
const guild = payload.guild_id
|
const guild = payload.guild_id
|
||||||
? await cacheHandlers.get("guilds", payload.guild_id)
|
? await cacheHandlers.get("guilds", payload.guild_id)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { botID, eventHandlers } from "../../bot.ts";
|
import { botId, eventHandlers } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import {
|
import {
|
||||||
@@ -21,7 +21,7 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
|
|||||||
else {
|
else {
|
||||||
const newReaction = {
|
const newReaction = {
|
||||||
count: 1,
|
count: 1,
|
||||||
me: payload.user_id === botID,
|
me: payload.user_id === botId,
|
||||||
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
|
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
|
||||||
};
|
};
|
||||||
message.reactions = message.reactions
|
message.reactions = message.reactions
|
||||||
@@ -46,8 +46,8 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
|
|||||||
const uncachedOptions = {
|
const uncachedOptions = {
|
||||||
...payload,
|
...payload,
|
||||||
id: payload.message_id,
|
id: payload.message_id,
|
||||||
channelID: payload.channel_id,
|
channelId: payload.channel_id,
|
||||||
guildID: payload.guild_id || "",
|
guildId: payload.guild_id || "",
|
||||||
};
|
};
|
||||||
|
|
||||||
eventHandlers.reactionAdd?.(
|
eventHandlers.reactionAdd?.(
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { botID, eventHandlers } from "../../bot.ts";
|
import { botId, eventHandlers } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import {
|
import {
|
||||||
@@ -23,7 +23,7 @@ export async function handleMessageReactionRemove(
|
|||||||
else {
|
else {
|
||||||
const newReaction = {
|
const newReaction = {
|
||||||
count: 1,
|
count: 1,
|
||||||
me: payload.user_id === botID,
|
me: payload.user_id === botId,
|
||||||
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
|
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
|
||||||
};
|
};
|
||||||
message.reactions = message.reactions
|
message.reactions = message.reactions
|
||||||
@@ -48,8 +48,8 @@ export async function handleMessageReactionRemove(
|
|||||||
const uncachedOptions = {
|
const uncachedOptions = {
|
||||||
...payload,
|
...payload,
|
||||||
id: payload.message_id,
|
id: payload.message_id,
|
||||||
channelID: payload.channel_id,
|
channelId: payload.channel_id,
|
||||||
guildID: payload.guild_id,
|
guildId: payload.guild_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
eventHandlers.reactionRemove?.(
|
eventHandlers.reactionRemove?.(
|
||||||
|
|||||||
+23
-23
@@ -1,8 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
eventHandlers,
|
eventHandlers,
|
||||||
lastShardID,
|
lastShardId,
|
||||||
setApplicationID,
|
setApplicationId,
|
||||||
setBotID,
|
setBotId,
|
||||||
} from "../../bot.ts";
|
} from "../../bot.ts";
|
||||||
import { cache, cacheHandlers } from "../../cache.ts";
|
import { cache, cacheHandlers } from "../../cache.ts";
|
||||||
import { initialMemberLoadQueue } from "../../structures/guild.ts";
|
import { initialMemberLoadQueue } from "../../structures/guild.ts";
|
||||||
@@ -13,30 +13,30 @@ import { allowNextShard, basicShards } from "../../ws/mod.ts";
|
|||||||
|
|
||||||
export async function handleReady(
|
export async function handleReady(
|
||||||
data: DiscordGatewayPayload,
|
data: DiscordGatewayPayload,
|
||||||
shardID: number,
|
shardId: number,
|
||||||
) {
|
) {
|
||||||
// The bot has already started, the last shard is resumed, however.
|
// The bot has already started, the last shard is resumed, however.
|
||||||
if (cache.isReady) return;
|
if (cache.isReady) return;
|
||||||
|
|
||||||
const payload = data.d as DiscordReady;
|
const payload = data.d as DiscordReady;
|
||||||
setBotID(payload.user.id);
|
setBotId(payload.user.id);
|
||||||
setApplicationID(payload.application.id);
|
setApplicationId(payload.application.id);
|
||||||
|
|
||||||
// Triggered on each shard
|
// Triggered on each shard
|
||||||
eventHandlers.shardReady?.(shardID);
|
eventHandlers.shardReady?.(shardId);
|
||||||
// Save when the READY event was received to prevent infinite load loops
|
// Save when the READY event was received to prevent infinite load loops
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
const shard = basicShards.get(shardID);
|
const shard = basicShards.get(shardId);
|
||||||
if (!shard) return;
|
if (!shard) return;
|
||||||
|
|
||||||
// Set ready to false just to go sure
|
// Set ready to false just to go sure
|
||||||
shard.ready = false;
|
shard.ready = false;
|
||||||
// All guilds are unavailable at first
|
// All guilds are unavailable at first
|
||||||
shard.unavailableGuildIDs = new Set(payload.guilds.map((g) => g.id));
|
shard.unavailableGuildIds = new Set(payload.guilds.map((g) => g.id));
|
||||||
|
|
||||||
// Start ready check in 2 seconds
|
// Start ready check in 2 seconds
|
||||||
setTimeout(() => checkReady(payload, shardID, now), 2000);
|
setTimeout(() => checkReady(payload, shardId, now), 2000);
|
||||||
|
|
||||||
// Wait 5 seconds to spawn next shard
|
// Wait 5 seconds to spawn next shard
|
||||||
await delay(5000);
|
await delay(5000);
|
||||||
@@ -45,48 +45,48 @@ export async function handleReady(
|
|||||||
|
|
||||||
// Don't pass the shard itself because unavailableGuilds won't be updated by the GUILD_CREATE event
|
// Don't pass the shard itself because unavailableGuilds won't be updated by the GUILD_CREATE event
|
||||||
/** This function checks if the shard is fully loaded */
|
/** This function checks if the shard is fully loaded */
|
||||||
function checkReady(payload: DiscordReady, shardID: number, now: number) {
|
function checkReady(payload: DiscordReady, shardId: number, now: number) {
|
||||||
const shard = basicShards.get(shardID);
|
const shard = basicShards.get(shardId);
|
||||||
if (!shard) return;
|
if (!shard) return;
|
||||||
|
|
||||||
// Check if all guilds were loaded
|
// Check if all guilds were loaded
|
||||||
if (shard.unavailableGuildIDs.size) {
|
if (shard.unavailableGuildIds.size) {
|
||||||
if (Date.now() - now > 10000) {
|
if (Date.now() - now > 10000) {
|
||||||
eventHandlers.shardFailedToLoad?.(shardID, shard.unavailableGuildIDs);
|
eventHandlers.shardFailedToLoad?.(shardId, shard.unavailableGuildIds);
|
||||||
// Force execute the loaded function to prevent infinite loop
|
// Force execute the loaded function to prevent infinite loop
|
||||||
loaded(shardID);
|
loaded(shardId);
|
||||||
} else {
|
} else {
|
||||||
// Not all guilds were loaded but 10 seconds haven't passed so check again
|
// Not all guilds were loaded but 10 seconds haven't passed so check again
|
||||||
setTimeout(() => checkReady(payload, shardID, now), 2000);
|
setTimeout(() => checkReady(payload, shardId, now), 2000);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// All guilds were loaded
|
// All guilds were loaded
|
||||||
loaded(shardID);
|
loaded(shardId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loaded(shardID: number) {
|
async function loaded(shardId: number) {
|
||||||
const shard = basicShards.get(shardID);
|
const shard = basicShards.get(shardId);
|
||||||
if (!shard) return;
|
if (!shard) return;
|
||||||
|
|
||||||
shard.ready = true;
|
shard.ready = true;
|
||||||
|
|
||||||
// If it is the last shard we can go full ready
|
// If it is the last shard we can go full ready
|
||||||
if (shardID === lastShardID - 1) {
|
if (shardId === lastShardId - 1) {
|
||||||
// Still some shards are loading so wait another 2 seconds for them
|
// Still some shards are loading so wait another 2 seconds for them
|
||||||
if (basicShards.some((shard) => !shard.ready)) {
|
if (basicShards.some((shard) => !shard.ready)) {
|
||||||
setTimeout(() => loaded(shardID), 2000);
|
setTimeout(() => loaded(shardId), 2000);
|
||||||
} else {
|
} else {
|
||||||
cache.isReady = true;
|
cache.isReady = true;
|
||||||
eventHandlers.ready?.();
|
eventHandlers.ready?.();
|
||||||
|
|
||||||
// All the members that came in on guild creates should now be processed 1 by 1
|
// All the members that came in on guild creates should now be processed 1 by 1
|
||||||
for (const [guildID, members] of initialMemberLoadQueue.entries()) {
|
for (const [guildId, members] of initialMemberLoadQueue.entries()) {
|
||||||
await Promise.allSettled(
|
await Promise.allSettled(
|
||||||
members.map(async (member) => {
|
members.map(async (member) => {
|
||||||
const memberStruct = await structures.createMemberStruct(
|
const memberStruct = await structures.createMemberStruct(
|
||||||
member,
|
member,
|
||||||
guildID,
|
guildId,
|
||||||
);
|
);
|
||||||
|
|
||||||
return cacheHandlers.set(
|
return cacheHandlers.set(
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
|
|||||||
|
|
||||||
guild.voiceStates.set(payload.user_id, {
|
guild.voiceStates.set(payload.user_id, {
|
||||||
...payload,
|
...payload,
|
||||||
guildID: payload.guild_id,
|
guildId: payload.guild_id,
|
||||||
channelID: payload.channel_id || "",
|
channelId: payload.channel_id || "",
|
||||||
userID: payload.user_id,
|
userId: payload.user_id,
|
||||||
sessionID: payload.session_id,
|
sessionId: payload.session_id,
|
||||||
selfDeaf: payload.self_deaf,
|
selfDeaf: payload.self_deaf,
|
||||||
selfMute: payload.self_mute,
|
selfMute: payload.self_mute,
|
||||||
selfStream: payload.self_stream || false,
|
selfStream: payload.self_stream || false,
|
||||||
@@ -31,22 +31,22 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
|
|||||||
|
|
||||||
await cacheHandlers.set("guilds", payload.guild_id, guild);
|
await cacheHandlers.set("guilds", payload.guild_id, guild);
|
||||||
|
|
||||||
if (cachedState?.channelID !== payload.channel_id) {
|
if (cachedState?.channelId !== payload.channel_id) {
|
||||||
// Either joined or moved channels
|
// Either joined or moved channels
|
||||||
if (payload.channel_id) {
|
if (payload.channel_id) {
|
||||||
if (cachedState?.channelID) { // Was in a channel before
|
if (cachedState?.channelId) { // Was in a channel before
|
||||||
eventHandlers.voiceChannelSwitch?.(
|
eventHandlers.voiceChannelSwitch?.(
|
||||||
member,
|
member,
|
||||||
payload.channel_id,
|
payload.channel_id,
|
||||||
cachedState.channelID,
|
cachedState.channelId,
|
||||||
);
|
);
|
||||||
} else { // Was not in a channel before so user just joined
|
} else { // Was not in a channel before so user just joined
|
||||||
eventHandlers.voiceChannelJoin?.(member, payload.channel_id);
|
eventHandlers.voiceChannelJoin?.(member, payload.channel_id);
|
||||||
}
|
}
|
||||||
} // Left the channel
|
} // Left the channel
|
||||||
else if (cachedState?.channelID) {
|
else if (cachedState?.channelId) {
|
||||||
guild.voiceStates.delete(payload.user_id);
|
guild.voiceStates.delete(payload.user_id);
|
||||||
eventHandlers.voiceChannelLeave?.(member, cachedState.channelID);
|
eventHandlers.voiceChannelLeave?.(member, cachedState.channelId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.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. */
|
||||||
export function categoryChildrenIDs(guildID: string, id: string) {
|
export function categoryChildrenIds(guildId: string, id: string) {
|
||||||
return cacheHandlers.filter(
|
return cacheHandlers.filter(
|
||||||
"channels",
|
"channels",
|
||||||
(channel) => channel.parentID === id && channel.guildID === guildID,
|
(channel) => channel.parentId === id && channel.guildId === guildId,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
/** Checks if a channel overwrite for a user id or a role id has permission in this channel */
|
/** Checks if a channel overwrite for a user id or a role id has permission in this channel */
|
||||||
export function channelOverwriteHasPermission(
|
export function channelOverwriteHasPermission(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
id: string,
|
id: string,
|
||||||
overwrites: RawOverwrite[],
|
overwrites: RawOverwrite[],
|
||||||
permissions: Permission[],
|
permissions: Permission[],
|
||||||
) {
|
) {
|
||||||
const overwrite = overwrites.find((perm) => perm.id === id) ||
|
const overwrite = overwrites.find((perm) => perm.id === id) ||
|
||||||
overwrites.find((perm) => perm.id === guildID);
|
overwrites.find((perm) => perm.id === guildId);
|
||||||
|
|
||||||
return permissions.every((perm) => {
|
return permissions.every((perm) => {
|
||||||
if (overwrite) {
|
if (overwrite) {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
|
|
||||||
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
||||||
export async function createChannel(
|
export async function createChannel(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
name: string,
|
name: string,
|
||||||
options?: ChannelCreateOptions,
|
options?: ChannelCreateOptions,
|
||||||
) {
|
) {
|
||||||
@@ -20,10 +20,10 @@ export async function createChannel(
|
|||||||
overwrite.deny.forEach(requiredPerms.add, requiredPerms);
|
overwrite.deny.forEach(requiredPerms.add, requiredPerms);
|
||||||
});
|
});
|
||||||
|
|
||||||
await requireBotGuildPermissions(guildID, [...requiredPerms]);
|
await requireBotGuildPermissions(guildId, [...requiredPerms]);
|
||||||
|
|
||||||
const result = (await RequestManager.post(
|
const result = (await RequestManager.post(
|
||||||
endpoints.GUILD_CHANNELS(guildID),
|
endpoints.GUILD_CHANNELS(guildId),
|
||||||
{
|
{
|
||||||
...options,
|
...options,
|
||||||
name,
|
name,
|
||||||
|
|||||||
@@ -5,25 +5,25 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
|
|
||||||
/** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
/** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
||||||
export async function deleteChannel(
|
export async function deleteChannel(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
channelID: string,
|
channelId: string,
|
||||||
reason?: string,
|
reason?: string,
|
||||||
) {
|
) {
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_CHANNELS"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_CHANNELS"]);
|
||||||
|
|
||||||
const guild = await cacheHandlers.get("guilds", guildID);
|
const guild = await cacheHandlers.get("guilds", guildId);
|
||||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||||
|
|
||||||
if (guild?.rulesChannelID === channelID) {
|
if (guild?.rulesChannelId === channelId) {
|
||||||
throw new Error(Errors.RULES_CHANNEL_CANNOT_BE_DELETED);
|
throw new Error(Errors.RULES_CHANNEL_CANNOT_BE_DELETED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (guild?.publicUpdatesChannelID === channelID) {
|
if (guild?.publicUpdatesChannelId === channelId) {
|
||||||
throw new Error(Errors.UPDATES_CHANNEL_CANNOT_BE_DELETED);
|
throw new Error(Errors.UPDATES_CHANNEL_CANNOT_BE_DELETED);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await RequestManager.delete(
|
const result = await RequestManager.delete(
|
||||||
endpoints.CHANNEL_BASE(channelID),
|
endpoints.CHANNEL_BASE(channelId),
|
||||||
{ reason },
|
{ reason },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
|
|
||||||
/** Delete the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */
|
/** Delete the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */
|
||||||
export async function deleteChannelOverwrite(
|
export async function deleteChannelOverwrite(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
channelID: string,
|
channelId: string,
|
||||||
overwriteID: string,
|
overwriteId: string,
|
||||||
) {
|
) {
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_ROLES"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||||
|
|
||||||
const result = await RequestManager.delete(
|
const result = await RequestManager.delete(
|
||||||
endpoints.CHANNEL_OVERWRITE(channelID, overwriteID),
|
endpoints.CHANNEL_OVERWRITE(channelId, overwriteId),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -7,18 +7,18 @@ import {
|
|||||||
|
|
||||||
/** 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(
|
export async function editChannel(
|
||||||
channelID: string,
|
channelId: string,
|
||||||
options: ChannelEditOptions,
|
options: ChannelEditOptions,
|
||||||
reason?: string,
|
reason?: string,
|
||||||
) {
|
) {
|
||||||
await requireBotChannelPermissions(channelID, ["MANAGE_CHANNELS"]);
|
await requireBotChannelPermissions(channelId, ["MANAGE_CHANNELS"]);
|
||||||
|
|
||||||
if (options.name || options.topic) {
|
if (options.name || options.topic) {
|
||||||
const request = editChannelNameTopicQueue.get(channelID);
|
const request = editChannelNameTopicQueue.get(channelId);
|
||||||
if (!request) {
|
if (!request) {
|
||||||
// If this hasnt been done before simply add 1 for it
|
// If this hasnt been done before simply add 1 for it
|
||||||
editChannelNameTopicQueue.set(channelID, {
|
editChannelNameTopicQueue.set(channelId, {
|
||||||
channelID: channelID,
|
channelId: channelId,
|
||||||
amount: 1,
|
amount: 1,
|
||||||
// 10 minutes from now
|
// 10 minutes from now
|
||||||
timestamp: Date.now() + 600000,
|
timestamp: Date.now() + 600000,
|
||||||
@@ -30,7 +30,7 @@ export async function editChannel(
|
|||||||
request.timestamp = Date.now() + 600000;
|
request.timestamp = Date.now() + 600000;
|
||||||
} else {
|
} else {
|
||||||
// 2 have already been used add to queue
|
// 2 have already been used add to queue
|
||||||
request.items.push({ channelID, options });
|
request.items.push({ channelId, options });
|
||||||
if (editChannelProcessing) return;
|
if (editChannelProcessing) return;
|
||||||
editChannelProcessing = true;
|
editChannelProcessing = true;
|
||||||
processEditChannelQueue();
|
processEditChannelQueue();
|
||||||
@@ -43,7 +43,7 @@ export async function editChannel(
|
|||||||
// deno-lint-ignore camelcase
|
// deno-lint-ignore camelcase
|
||||||
rate_limit_per_user: options.rateLimitPerUser,
|
rate_limit_per_user: options.rateLimitPerUser,
|
||||||
// deno-lint-ignore camelcase
|
// deno-lint-ignore camelcase
|
||||||
parent_id: options.parentID,
|
parent_id: options.parentId,
|
||||||
// deno-lint-ignore camelcase
|
// deno-lint-ignore camelcase
|
||||||
user_limit: options.userLimit,
|
user_limit: options.userLimit,
|
||||||
// deno-lint-ignore camelcase
|
// deno-lint-ignore camelcase
|
||||||
@@ -56,7 +56,7 @@ export async function editChannel(
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await RequestManager.patch(endpoints.CHANNEL_BASE(channelID), {
|
const result = await RequestManager.patch(endpoints.CHANNEL_BASE(channelId), {
|
||||||
...payload,
|
...payload,
|
||||||
reason,
|
reason,
|
||||||
});
|
});
|
||||||
@@ -75,7 +75,7 @@ function processEditChannelQueue() {
|
|||||||
if (now > request.timestamp) return;
|
if (now > request.timestamp) return;
|
||||||
// 10 minutes have passed so we can reset this channel again
|
// 10 minutes have passed so we can reset this channel again
|
||||||
if (!request.items.length) {
|
if (!request.items.length) {
|
||||||
return editChannelNameTopicQueue.delete(request.channelID);
|
return editChannelNameTopicQueue.delete(request.channelId);
|
||||||
}
|
}
|
||||||
request.amount = 0;
|
request.amount = 0;
|
||||||
// There are items to process for this request
|
// There are items to process for this request
|
||||||
@@ -83,11 +83,11 @@ function processEditChannelQueue() {
|
|||||||
|
|
||||||
if (!details) return;
|
if (!details) return;
|
||||||
|
|
||||||
editChannel(details.channelID, details.options);
|
editChannel(details.channelId, details.options);
|
||||||
const secondDetails = request.items.shift();
|
const secondDetails = request.items.shift();
|
||||||
if (!secondDetails) return;
|
if (!secondDetails) return;
|
||||||
|
|
||||||
return editChannel(secondDetails.channelID, secondDetails.options);
|
return editChannel(secondDetails.channelId, secondDetails.options);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (editChannelNameTopicQueue.size) {
|
if (editChannelNameTopicQueue.size) {
|
||||||
|
|||||||
@@ -7,15 +7,15 @@ import {
|
|||||||
|
|
||||||
/** Edit the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */
|
/** Edit the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */
|
||||||
export async function editChannelOverwrite(
|
export async function editChannelOverwrite(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
channelID: string,
|
channelId: string,
|
||||||
overwriteID: string,
|
overwriteId: string,
|
||||||
options: Omit<Overwrite, "id">,
|
options: Omit<Overwrite, "id">,
|
||||||
) {
|
) {
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_ROLES"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||||
|
|
||||||
const result = await RequestManager.put(
|
const result = await RequestManager.put(
|
||||||
endpoints.CHANNEL_OVERWRITE(channelID, overwriteID),
|
endpoints.CHANNEL_OVERWRITE(channelId, overwriteId),
|
||||||
{
|
{
|
||||||
allow: calculateBits(options.allow),
|
allow: calculateBits(options.allow),
|
||||||
deny: calculateBits(options.deny),
|
deny: calculateBits(options.deny),
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
|||||||
|
|
||||||
/** Follow a News Channel to send messages to a target channel. Requires the `MANAGE_WEBHOOKS` permission in the target channel. Returns the webhook id. */
|
/** Follow a News Channel to send messages to a target channel. Requires the `MANAGE_WEBHOOKS` permission in the target channel. Returns the webhook id. */
|
||||||
export async function followChannel(
|
export async function followChannel(
|
||||||
sourceChannelID: string,
|
sourceChannelId: string,
|
||||||
targetChannelID: string,
|
targetChannelId: string,
|
||||||
) {
|
) {
|
||||||
await requireBotChannelPermissions(targetChannelID, ["MANAGE_WEBHOOKS"]);
|
await requireBotChannelPermissions(targetChannelId, ["MANAGE_WEBHOOKS"]);
|
||||||
|
|
||||||
const data = (await RequestManager.post(
|
const data = (await RequestManager.post(
|
||||||
endpoints.CHANNEL_FOLLOW(sourceChannelID),
|
endpoints.CHANNEL_FOLLOW(sourceChannelId),
|
||||||
{
|
{
|
||||||
webhook_channel_id: targetChannelID,
|
webhook_channel_id: targetChannelId,
|
||||||
},
|
},
|
||||||
)) as FollowedChannelPayload;
|
)) as FollowedChannelPayload;
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import { endpoints } from "../../util/constants.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(channelID: string, addToCache = true) {
|
export async function getChannel(channelId: string, addToCache = true) {
|
||||||
const result = (await RequestManager.get(
|
const result = (await RequestManager.get(
|
||||||
endpoints.CHANNEL_BASE(channelID),
|
endpoints.CHANNEL_BASE(channelId),
|
||||||
)) as ChannelCreatePayload;
|
)) as ChannelCreatePayload;
|
||||||
|
|
||||||
const channelStruct = await structures.createChannelStruct(
|
const channelStruct = await structures.createChannelStruct(
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Gets the webhooks for this channel. Requires MANAGE_WEBHOOKS */
|
/** Gets the webhooks for this channel. Requires MANAGE_WEBHOOKS */
|
||||||
export async function getChannelWebhooks(channelID: string) {
|
export async function getChannelWebhooks(channelId: string) {
|
||||||
await requireBotChannelPermissions(channelID, ["MANAGE_WEBHOOKS"]);
|
await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]);
|
||||||
|
|
||||||
const result = await RequestManager.get(
|
const result = await RequestManager.get(
|
||||||
endpoints.CHANNEL_WEBHOOKS(channelID),
|
endpoints.CHANNEL_WEBHOOKS(channelId),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result as WebhookPayload[];
|
return result as WebhookPayload[];
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ import { endpoints } from "../../util/constants.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(guildID: string, addToCache = true) {
|
export async function getChannels(guildId: string, addToCache = true) {
|
||||||
const result = (await RequestManager.get(
|
const result = (await RequestManager.get(
|
||||||
endpoints.GUILD_CHANNELS(guildID),
|
endpoints.GUILD_CHANNELS(guildId),
|
||||||
) as ChannelCreatePayload[]);
|
) as ChannelCreatePayload[]);
|
||||||
|
|
||||||
return Promise.all(result.map(async (res) => {
|
return Promise.all(result.map(async (res) => {
|
||||||
const channelStruct = await structures.createChannelStruct(res, guildID);
|
const channelStruct = await structures.createChannelStruct(res, guildId);
|
||||||
if (addToCache) {
|
if (addToCache) {
|
||||||
await cacheHandlers.set("channels", channelStruct.id, channelStruct);
|
await cacheHandlers.set("channels", channelStruct.id, channelStruct);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import { structures } from "../../structures/mod.ts";
|
|||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** Get pinned messages in this channel. */
|
/** Get pinned messages in this channel. */
|
||||||
export async function getPins(channelID: string) {
|
export async function getPins(channelId: string) {
|
||||||
const result = (await RequestManager.get(
|
const result = (await RequestManager.get(
|
||||||
endpoints.CHANNEL_PINS(channelID),
|
endpoints.CHANNEL_PINS(channelId),
|
||||||
)) as MessageCreateOptions[];
|
)) as MessageCreateOptions[];
|
||||||
|
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
|
||||||
/** Checks whether a channel is synchronized with its parent/category channel or not. */
|
/** Checks whether a channel is synchronized with its parent/category channel or not. */
|
||||||
export async function isChannelSynced(channelID: string) {
|
export async function isChannelSynced(channelId: string) {
|
||||||
const channel = await cacheHandlers.get("channels", channelID);
|
const channel = await cacheHandlers.get("channels", channelId);
|
||||||
if (!channel?.parentID) return false;
|
if (!channel?.parentId) return false;
|
||||||
|
|
||||||
const parentChannel = await cacheHandlers.get("channels", channel.parentID);
|
const parentChannel = await cacheHandlers.get("channels", channel.parentId);
|
||||||
if (!parentChannel) return false;
|
if (!parentChannel) return false;
|
||||||
|
|
||||||
return channel.permissionOverwrites?.every((overwrite) => {
|
return channel.permissionOverwrites?.every((overwrite) => {
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import { botHasChannelPermissions } from "../../util/permissions.ts";
|
|||||||
* However, if a bot is responding to a command and expects the computation to take a few seconds,
|
* However, if a bot is responding to a command and expects the computation to take a few seconds,
|
||||||
* this endpoint may be called to let the user know that the bot is processing their message.
|
* this endpoint may be called to let the user know that the bot is processing their message.
|
||||||
*/
|
*/
|
||||||
export async function startTyping(channelID: string) {
|
export async function startTyping(channelId: string) {
|
||||||
const channel = await cacheHandlers.get("channels", channelID);
|
const channel = await cacheHandlers.get("channels", channelId);
|
||||||
// If the channel is cached, we can do extra checks/safety
|
// If the channel is cached, we can do extra checks/safety
|
||||||
if (channel) {
|
if (channel) {
|
||||||
if (
|
if (
|
||||||
@@ -23,7 +23,7 @@ export async function startTyping(channelID: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const hasSendMessagesPerm = await botHasChannelPermissions(
|
const hasSendMessagesPerm = await botHasChannelPermissions(
|
||||||
channelID,
|
channelId,
|
||||||
["SEND_MESSAGES"],
|
["SEND_MESSAGES"],
|
||||||
);
|
);
|
||||||
if (
|
if (
|
||||||
@@ -33,7 +33,7 @@ export async function startTyping(channelID: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await RequestManager.post(endpoints.CHANNEL_TYPING(channelID));
|
const result = await RequestManager.post(endpoints.CHANNEL_TYPING(channelId));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
|
|
||||||
/** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */
|
/** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */
|
||||||
export async function swapChannels(
|
export async function swapChannels(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
channelPositions: PositionSwap[],
|
channelPositions: PositionSwap[],
|
||||||
) {
|
) {
|
||||||
if (channelPositions.length < 2) {
|
if (channelPositions.length < 2) {
|
||||||
@@ -11,7 +11,7 @@ export async function swapChannels(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = await RequestManager.patch(
|
const result = await RequestManager.patch(
|
||||||
endpoints.GUILD_CHANNELS(guildID),
|
endpoints.GUILD_CHANNELS(guildId),
|
||||||
channelPositions,
|
channelPositions,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { applicationID } from "../../bot.ts";
|
import { applicationId } from "../../bot.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { validateSlashCommands } from "../../util/utils.ts";
|
import { validateSlashCommands } from "../../util/utils.ts";
|
||||||
@@ -18,9 +18,9 @@ export async function createSlashCommand(options: CreateSlashCommandOptions) {
|
|||||||
validateSlashCommands([options], true);
|
validateSlashCommands([options], true);
|
||||||
|
|
||||||
const result = await RequestManager.post(
|
const result = await RequestManager.post(
|
||||||
options.guildID
|
options.guildId
|
||||||
? endpoints.COMMANDS_GUILD(applicationID, options.guildID)
|
? endpoints.COMMANDS_GUILD(applicationId, options.guildId)
|
||||||
: endpoints.COMMANDS(applicationID),
|
: endpoints.COMMANDS(applicationId),
|
||||||
{
|
{
|
||||||
...options,
|
...options,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { applicationID } from "../../bot.ts";
|
import { applicationId } from "../../bot.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** Deletes a slash command. */
|
/** Deletes a slash command. */
|
||||||
export function deleteSlashCommand(id: string, guildID?: string) {
|
export function deleteSlashCommand(id: string, guildId?: string) {
|
||||||
if (!guildID) {
|
if (!guildId) {
|
||||||
return RequestManager.delete(endpoints.COMMANDS_ID(applicationID, id));
|
return RequestManager.delete(endpoints.COMMANDS_ID(applicationId, id));
|
||||||
}
|
}
|
||||||
return RequestManager.delete(
|
return RequestManager.delete(
|
||||||
endpoints.COMMANDS_GUILD_ID(applicationID, guildID, id),
|
endpoints.COMMANDS_GUILD_ID(applicationId, guildId, id),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
import { applicationID } from "../../bot.ts";
|
import { applicationId } from "../../bot.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** To delete your response to a slash command. If a message id is not provided, it will default to deleting the original response. */
|
/** To delete your response to a slash command. If a message id is not provided, it will default to deleting the original response. */
|
||||||
export async function deleteSlashResponse(token: string, messageID?: string) {
|
export async function deleteSlashResponse(token: string, messageId?: string) {
|
||||||
const result = await RequestManager.delete(
|
const result = await RequestManager.delete(
|
||||||
messageID
|
messageId
|
||||||
? endpoints.INTERACTION_ID_TOKEN_MESSAGEID(
|
? endpoints.INTERACTION_ID_TOKEN_MESSAGE_ID(
|
||||||
applicationID,
|
applicationId,
|
||||||
token,
|
token,
|
||||||
messageID,
|
messageId,
|
||||||
)
|
)
|
||||||
: endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationID, token),
|
: endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { applicationID } from "../../bot.ts";
|
import { applicationId } from "../../bot.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** To edit your response to a slash command. If a messageID is not provided it will default to editing the original response. */
|
/** To edit your response to a slash command. If a messageId is not provided it will default to editing the original response. */
|
||||||
export async function editSlashResponse(
|
export async function editSlashResponse(
|
||||||
token: string,
|
token: string,
|
||||||
options: EditSlashResponseOptions,
|
options: EditSlashResponseOptions,
|
||||||
@@ -49,14 +49,14 @@ export async function editSlashResponse(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = await RequestManager.patch(
|
const result = await RequestManager.patch(
|
||||||
options.messageID
|
options.messageId
|
||||||
? endpoints.WEBHOOK_MESSAGE(applicationID, token, options.messageID)
|
? endpoints.WEBHOOK_MESSAGE(applicationId, token, options.messageId)
|
||||||
: endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationID, token),
|
: endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token),
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
|
||||||
// If the original message was edited, this will not return a message
|
// If the original message was edited, this will not return a message
|
||||||
if (!options.messageID) return result;
|
if (!options.messageId) return result;
|
||||||
|
|
||||||
const message = await structures.createMessageStruct(
|
const message = await structures.createMessageStruct(
|
||||||
result as MessageCreateOptions,
|
result as MessageCreateOptions,
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { applicationID } from "../../bot.ts";
|
import { applicationId } from "../../bot.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** Fetchs the global command for the given ID. If a guildID is provided, the guild command will be fetched. */
|
/** Fetchs the global command for the given Id. If a guildId is provided, the guild command will be fetched. */
|
||||||
export async function getSlashCommand(commandID: string, guildID?: string) {
|
export async function getSlashCommand(commandId: string, guildId?: string) {
|
||||||
const result = await RequestManager.get(
|
const result = await RequestManager.get(
|
||||||
guildID
|
guildId
|
||||||
? endpoints.COMMANDS_GUILD_ID(applicationID, guildID, commandID)
|
? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, commandId)
|
||||||
: endpoints.COMMANDS_ID(applicationID, commandID),
|
: endpoints.COMMANDS_ID(applicationId, commandId),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result as SlashCommand;
|
return result as SlashCommand;
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import { applicationID } from "../../bot.ts";
|
import { applicationId } from "../../bot.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../../util/collection.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** Fetch all of the global commands for your application. */
|
/** Fetch all of the global commands for your application. */
|
||||||
export async function getSlashCommands(guildID?: string) {
|
export async function getSlashCommands(guildId?: string) {
|
||||||
const result = (await RequestManager.get(
|
const result = (await RequestManager.get(
|
||||||
guildID
|
guildId
|
||||||
? endpoints.COMMANDS_GUILD(applicationID, guildID)
|
? endpoints.COMMANDS_GUILD(applicationId, guildId)
|
||||||
: endpoints.COMMANDS(applicationID),
|
: endpoints.COMMANDS(applicationId),
|
||||||
)) as SlashCommand[];
|
)) as SlashCommand[];
|
||||||
|
|
||||||
return new Collection(result.map((command) => [command.name, command]));
|
return new Collection(result.map((command) => [command.name, command]));
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { applicationID } from "../../bot.ts";
|
import { applicationId } from "../../bot.ts";
|
||||||
import { cache } from "../../cache.ts";
|
import { cache } from "../../cache.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
@@ -16,7 +16,7 @@ export async function sendInteractionResponse(
|
|||||||
) {
|
) {
|
||||||
// If its already been executed, we need to send a followup response
|
// If its already been executed, we need to send a followup response
|
||||||
if (cache.executedSlashCommands.has(token)) {
|
if (cache.executedSlashCommands.has(token)) {
|
||||||
return RequestManager.post(endpoints.WEBHOOK(applicationID, token), {
|
return RequestManager.post(endpoints.WEBHOOK(applicationId, token), {
|
||||||
...options,
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { applicationID } from "../../bot.ts";
|
import { applicationId } from "../../bot.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { validateSlashCommands } from "../../util/utils.ts";
|
import { validateSlashCommands } from "../../util/utils.ts";
|
||||||
@@ -7,16 +7,16 @@ import { validateSlashCommands } from "../../util/utils.ts";
|
|||||||
* Edit an existing slash command. If this command did not exist, it will create it.
|
* Edit an existing slash command. If this command did not exist, it will create it.
|
||||||
*/
|
*/
|
||||||
export async function upsertSlashCommand(
|
export async function upsertSlashCommand(
|
||||||
commandID: string,
|
commandId: string,
|
||||||
options: UpsertSlashCommandOptions,
|
options: UpsertSlashCommandOptions,
|
||||||
guildID?: string,
|
guildId?: string,
|
||||||
) {
|
) {
|
||||||
validateSlashCommands([options]);
|
validateSlashCommands([options]);
|
||||||
|
|
||||||
const result = await RequestManager.patch(
|
const result = await RequestManager.patch(
|
||||||
guildID
|
guildId
|
||||||
? endpoints.COMMANDS_GUILD_ID(applicationID, guildID, commandID)
|
? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, commandId)
|
||||||
: endpoints.COMMANDS_ID(applicationID, commandID),
|
: endpoints.COMMANDS_ID(applicationId, commandId),
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { applicationID } from "../../bot.ts";
|
import { applicationId } from "../../bot.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { validateSlashCommands } from "../../util/utils.ts";
|
import { validateSlashCommands } from "../../util/utils.ts";
|
||||||
@@ -6,18 +6,18 @@ import { validateSlashCommands } from "../../util/utils.ts";
|
|||||||
/**
|
/**
|
||||||
* Bulk edit existing slash commands. If a command does not exist, it will create it.
|
* Bulk edit existing slash commands. If a command does not exist, it will create it.
|
||||||
*
|
*
|
||||||
* **NOTE:** Any slash commands that are not specified in this function will be **deleted**. If you don't provide the commandID and rename your command, the command gets a new ID.
|
* **NOTE:** Any slash commands that are not specified in this function will be **deleted**. If you don't provide the commandId and rename your command, the command gets a new Id.
|
||||||
*/
|
*/
|
||||||
export async function upsertSlashCommands(
|
export async function upsertSlashCommands(
|
||||||
options: UpsertSlashCommandsOptions[],
|
options: UpsertSlashCommandsOptions[],
|
||||||
guildID?: string,
|
guildId?: string,
|
||||||
) {
|
) {
|
||||||
validateSlashCommands(options);
|
validateSlashCommands(options);
|
||||||
|
|
||||||
const result = await RequestManager.put(
|
const result = await RequestManager.put(
|
||||||
guildID
|
guildId
|
||||||
? endpoints.COMMANDS_GUILD(applicationID, guildID)
|
? endpoints.COMMANDS_GUILD(applicationId, guildId)
|
||||||
: endpoints.COMMANDS(applicationID),
|
: endpoints.COMMANDS(applicationId),
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -5,18 +5,18 @@ import { urlToBase64 } from "../../util/utils.ts";
|
|||||||
|
|
||||||
/** Create an emoji in the server. Emojis and animated emojis have a maximum file size of 256kb. Attempting to upload an emoji larger than this limit will fail and return 400 Bad Request and an error message, but not a JSON status code. If a URL is provided to the image parameter, Discordeno will automatically convert it to a base64 string internally. */
|
/** Create an emoji in the server. Emojis and animated emojis have a maximum file size of 256kb. Attempting to upload an emoji larger than this limit will fail and return 400 Bad Request and an error message, but not a JSON status code. If a URL is provided to the image parameter, Discordeno will automatically convert it to a base64 string internally. */
|
||||||
export async function createEmoji(
|
export async function createEmoji(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
name: string,
|
name: string,
|
||||||
image: string,
|
image: string,
|
||||||
options: CreateEmojisOptions,
|
options: CreateEmojisOptions,
|
||||||
) {
|
) {
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_EMOJIS"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
|
||||||
|
|
||||||
if (image && !image.startsWith("data:image/")) {
|
if (image && !image.startsWith("data:image/")) {
|
||||||
image = await urlToBase64(image);
|
image = await urlToBase64(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await RequestManager.post(endpoints.GUILD_EMOJIS(guildID), {
|
const result = await RequestManager.post(endpoints.GUILD_EMOJIS(guildId), {
|
||||||
...options,
|
...options,
|
||||||
name,
|
name,
|
||||||
image,
|
image,
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
|
|
||||||
/** Delete the given emoji. Requires the MANAGE_EMOJIS permission. Returns 204 No Content on success. */
|
/** Delete the given emoji. Requires the MANAGE_EMOJIS permission. Returns 204 No Content on success. */
|
||||||
export async function deleteEmoji(
|
export async function deleteEmoji(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
id: string,
|
id: string,
|
||||||
reason?: string,
|
reason?: string,
|
||||||
) {
|
) {
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_EMOJIS"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
|
||||||
|
|
||||||
const result = await RequestManager.delete(
|
const result = await RequestManager.delete(
|
||||||
endpoints.GUILD_EMOJI(guildID, id),
|
endpoints.GUILD_EMOJI(guildId, id),
|
||||||
{ reason },
|
{ reason },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
|
|
||||||
/** Modify the given emoji. Requires the MANAGE_EMOJIS permission. */
|
/** Modify the given emoji. Requires the MANAGE_EMOJIS permission. */
|
||||||
export async function editEmoji(
|
export async function editEmoji(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
id: string,
|
id: string,
|
||||||
options: EditEmojisOptions,
|
options: EditEmojisOptions,
|
||||||
) {
|
) {
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_EMOJIS"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
|
||||||
|
|
||||||
const result = await RequestManager.patch(
|
const result = await RequestManager.patch(
|
||||||
endpoints.GUILD_EMOJI(guildID, id),
|
endpoints.GUILD_EMOJI(guildId, id),
|
||||||
{
|
{
|
||||||
name: options.name,
|
name: options.name,
|
||||||
roles: options.roles,
|
roles: options.roles,
|
||||||
|
|||||||
@@ -3,26 +3,26 @@ import { RequestManager } from "../../rest/request_manager.ts";
|
|||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an emoji for the given guild and emoji ID.
|
* Returns an emoji for the given guild and emoji Id.
|
||||||
*
|
*
|
||||||
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis
|
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis
|
||||||
*/
|
*/
|
||||||
export async function getEmoji(
|
export async function getEmoji(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
emojiID: string,
|
emojiId: string,
|
||||||
addToCache = true,
|
addToCache = true,
|
||||||
) {
|
) {
|
||||||
const result = (await RequestManager.get(
|
const result = (await RequestManager.get(
|
||||||
endpoints.GUILD_EMOJI(guildID, emojiID),
|
endpoints.GUILD_EMOJI(guildId, emojiId),
|
||||||
)) as Emoji;
|
)) as Emoji;
|
||||||
|
|
||||||
if (addToCache) {
|
if (addToCache) {
|
||||||
const guild = await cacheHandlers.get("guilds", guildID);
|
const guild = await cacheHandlers.get("guilds", guildId);
|
||||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||||
guild.emojis.set(result.id ?? result.name, result);
|
guild.emojis.set(result.id ?? result.name, result);
|
||||||
cacheHandlers.set(
|
cacheHandlers.set(
|
||||||
"guilds",
|
"guilds",
|
||||||
guildID,
|
guildId,
|
||||||
guild,
|
guild,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,18 +7,18 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
*
|
*
|
||||||
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis
|
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis
|
||||||
*/
|
*/
|
||||||
export async function getEmojis(guildID: string, addToCache = true) {
|
export async function getEmojis(guildId: string, addToCache = true) {
|
||||||
const result = (await RequestManager.get(
|
const result = (await RequestManager.get(
|
||||||
endpoints.GUILD_EMOJIS(guildID),
|
endpoints.GUILD_EMOJIS(guildId),
|
||||||
)) as Emoji[];
|
)) as Emoji[];
|
||||||
|
|
||||||
if (addToCache) {
|
if (addToCache) {
|
||||||
const guild = await cacheHandlers.get("guilds", guildID);
|
const guild = await cacheHandlers.get("guilds", guildId);
|
||||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||||
|
|
||||||
result.forEach((emoji) => guild.emojis.set(emoji.id ?? emoji.name, emoji));
|
result.forEach((emoji) => guild.emojis.set(emoji.id ?? emoji.name, emoji));
|
||||||
|
|
||||||
cacheHandlers.set("guilds", guildID, guild);
|
cacheHandlers.set("guilds", guildId, guild);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
|
|
||||||
/** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event.
|
/** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event.
|
||||||
*/
|
*/
|
||||||
export async function deleteServer(guildID: string) {
|
export async function deleteServer(guildId: string) {
|
||||||
const result = await RequestManager.delete(endpoints.GUILDS_BASE(guildID));
|
const result = await RequestManager.delete(endpoints.GUILDS_BASE(guildId));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
import { urlToBase64 } from "../../util/utils.ts";
|
import { urlToBase64 } from "../../util/utils.ts";
|
||||||
|
|
||||||
/** Modify a guilds settings. Requires the MANAGE_GUILD permission. */
|
/** Modify a guilds settings. Requires the MANAGE_GUILD permission. */
|
||||||
export async function editGuild(guildID: string, options: GuildEditOptions) {
|
export async function editGuild(guildId: string, options: GuildEditOptions) {
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||||
|
|
||||||
if (options.icon && !options.icon.startsWith("data:image/")) {
|
if (options.icon && !options.icon.startsWith("data:image/")) {
|
||||||
options.icon = await urlToBase64(options.icon);
|
options.icon = await urlToBase64(options.icon);
|
||||||
@@ -20,7 +20,7 @@ export async function editGuild(guildID: string, options: GuildEditOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = await RequestManager.patch(
|
const result = await RequestManager.patch(
|
||||||
endpoints.GUILDS_BASE(guildID),
|
endpoints.GUILDS_BASE(guildId),
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
|
|
||||||
/** Modify a guild widget object for the guild. Requires the MANAGE_GUILD permission. */
|
/** Modify a guild widget object for the guild. Requires the MANAGE_GUILD permission. */
|
||||||
export async function editWidget(
|
export async function editWidget(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
enabled: boolean,
|
enabled: boolean,
|
||||||
channelID?: string | null,
|
channelId?: string | null,
|
||||||
) {
|
) {
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||||
|
|
||||||
const result = await RequestManager.patch(endpoints.GUILD_WIDGET(guildID), {
|
const result = await RequestManager.patch(endpoints.GUILD_WIDGET(guildId), {
|
||||||
enabled,
|
enabled,
|
||||||
channel_id: channelID,
|
channel_id: channelId,
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
|
|
||||||
/** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */
|
/** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */
|
||||||
export async function getAuditLogs(
|
export async function getAuditLogs(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
options: GetAuditLogsOptions,
|
options: GetAuditLogsOptions,
|
||||||
) {
|
) {
|
||||||
await requireBotGuildPermissions(guildID, ["VIEW_AUDIT_LOG"]);
|
await requireBotGuildPermissions(guildId, ["VIEW_AUDIT_LOG"]);
|
||||||
|
|
||||||
const result = await RequestManager.get(endpoints.GUILD_AUDIT_LOGS(guildID), {
|
const result = await RequestManager.get(endpoints.GUILD_AUDIT_LOGS(guildId), {
|
||||||
...options,
|
...options,
|
||||||
action_type: options.action_type
|
action_type: options.action_type
|
||||||
? AuditLogs[options.action_type]
|
? AuditLogs[options.action_type]
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Returns a ban object for the given user or a 404 not found if the ban cannot be found. Requires the BAN_MEMBERS permission. */
|
/** Returns a ban object for the given user or a 404 not found if the ban cannot be found. Requires the BAN_MEMBERS permission. */
|
||||||
export async function getBan(guildID: string, memberID: string) {
|
export async function getBan(guildId: string, memberId: string) {
|
||||||
await requireBotGuildPermissions(guildID, ["BAN_MEMBERS"]);
|
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
|
||||||
|
|
||||||
const result = await RequestManager.get(
|
const result = await RequestManager.get(
|
||||||
endpoints.GUILD_BAN(guildID, memberID),
|
endpoints.GUILD_BAN(guildId, memberId),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result as BannedUser;
|
return result as BannedUser;
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Returns a list of ban objects for the users banned from this guild. Requires the BAN_MEMBERS permission. */
|
/** Returns a list of ban objects for the users banned from this guild. Requires the BAN_MEMBERS permission. */
|
||||||
export async function getBans(guildID: string) {
|
export async function getBans(guildId: string) {
|
||||||
await requireBotGuildPermissions(guildID, ["BAN_MEMBERS"]);
|
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
|
||||||
|
|
||||||
const results = (await RequestManager.get(
|
const results = (await RequestManager.get(
|
||||||
endpoints.GUILD_BANS(guildID),
|
endpoints.GUILD_BANS(guildId),
|
||||||
)) as BannedUser[];
|
)) as BannedUser[];
|
||||||
|
|
||||||
return new Collection<string, BannedUser>(
|
return new Collection<string, BannedUser>(
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
* This function fetches a guild's data. This is not the same data as a GUILD_CREATE.
|
* This function fetches a guild's data. This is not the same data as a GUILD_CREATE.
|
||||||
* So it does not cache the guild, you must do it manually.
|
* So it does not cache the guild, you must do it manually.
|
||||||
* */
|
* */
|
||||||
export async function getGuild(guildID: string, counts = true) {
|
export async function getGuild(guildId: string, counts = true) {
|
||||||
const result = await RequestManager.get(endpoints.GUILDS_BASE(guildID), {
|
const result = await RequestManager.get(endpoints.GUILDS_BASE(guildId), {
|
||||||
with_counts: counts,
|
with_counts: counts,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import { RequestManager } from "../../rest/request_manager.ts";
|
|||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** Returns the guild preview object for the given id. If the bot is not in the guild, then the guild must be Discoverable. */
|
/** Returns the guild preview object for the given id. If the bot is not in the guild, then the guild must be Discoverable. */
|
||||||
export async function getGuildPreview(guildID: string) {
|
export async function getGuildPreview(guildId: string) {
|
||||||
const result = await RequestManager.get(endpoints.GUILD_PREVIEW(guildID));
|
const result = await RequestManager.get(endpoints.GUILD_PREVIEW(guildId));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
import { camelKeysToSnakeCase, urlToBase64 } from "../../util/utils.ts";
|
import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
/** Check how many members would be removed from the server in a prune operation. Requires the KICK_MEMBERS permission */
|
/** Check how many members would be removed from the server in a prune operation. Requires the KICK_MEMBERS permission */
|
||||||
export async function getPruneCount(guildID: string, options?: PruneOptions) {
|
export async function getPruneCount(guildId: string, options?: PruneOptions) {
|
||||||
if (options?.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS);
|
if (options?.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS);
|
||||||
if (options?.days && options.days > 30) {
|
if (options?.days && options.days > 30) {
|
||||||
throw new Error(Errors.PRUNE_MAX_DAYS);
|
throw new Error(Errors.PRUNE_MAX_DAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
await requireBotGuildPermissions(guildID, ["KICK_MEMBERS"]);
|
await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]);
|
||||||
|
|
||||||
const result = await RequestManager.get(
|
const result = await RequestManager.get(
|
||||||
endpoints.GUILD_PRUNE(guildID),
|
endpoints.GUILD_PRUNE(guildId),
|
||||||
camelKeysToSnakeCase(options ?? {}),
|
camelKeysToSnakeCase(options ?? {}),
|
||||||
) as PrunePayload;
|
) as PrunePayload;
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import { RequestManager } from "../../rest/request_manager.ts";
|
|||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** Returns the code and uses of the vanity url for this server if it is enabled. Requires the MANAGE_GUILD permission. */
|
/** Returns the code and uses of the vanity url for this server if it is enabled. Requires the MANAGE_GUILD permission. */
|
||||||
export async function getVanityURL(guildID: string) {
|
export async function getVanityURL(guildId: string) {
|
||||||
const result = await RequestManager.get(endpoints.GUILD_VANITY_URL(guildID));
|
const result = await RequestManager.get(endpoints.GUILD_VANITY_URL(guildId));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import { RequestManager } from "../../rest/request_manager.ts";
|
|||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** Returns a list of voice region objects for the guild. Unlike the similar /voice route, this returns VIP servers when the guild is VIP-enabled. */
|
/** Returns a list of voice region objects for the guild. Unlike the similar /voice route, this returns VIP servers when the guild is VIP-enabled. */
|
||||||
export async function getVoiceRegions(guildID: string) {
|
export async function getVoiceRegions(guildId: string) {
|
||||||
const result = await RequestManager.get(endpoints.GUILD_REGIONS(guildID));
|
const result = await RequestManager.get(endpoints.GUILD_REGIONS(guildId));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ import { RequestManager } from "../../rest/request_manager.ts";
|
|||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** Returns the widget for the guild. */
|
/** Returns the widget for the guild. */
|
||||||
export async function getWidget(guildID: string, options?: { force: boolean }) {
|
export async function getWidget(guildId: string, options?: { force: boolean }) {
|
||||||
if (!options?.force) {
|
if (!options?.force) {
|
||||||
const guild = await cacheHandlers.get("guilds", guildID);
|
const guild = await cacheHandlers.get("guilds", guildId);
|
||||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||||
if (!guild?.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
|
if (!guild?.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
return RequestManager.get(`${endpoints.GUILD_WIDGET(guildID)}.json`);
|
return RequestManager.get(`${endpoints.GUILD_WIDGET(guildId)}.json`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,18 +3,18 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
|
|
||||||
/** Returns the widget image URL for the guild. */
|
/** Returns the widget image URL for the guild. */
|
||||||
export async function getWidgetImageURL(
|
export async function getWidgetImageURL(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
options?: {
|
options?: {
|
||||||
style?: "shield" | "banner1" | "banner2" | "banner3" | "banner4";
|
style?: "shield" | "banner1" | "banner2" | "banner3" | "banner4";
|
||||||
force?: boolean;
|
force?: boolean;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
if (!options?.force) {
|
if (!options?.force) {
|
||||||
const guild = await cacheHandlers.get("guilds", guildID);
|
const guild = await cacheHandlers.get("guilds", guildId);
|
||||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||||
if (!guild.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
|
if (!guild.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${endpoints.GUILD_WIDGET(guildID)}.png?style=${options?.style ??
|
return `${endpoints.GUILD_WIDGET(guildId)}.png?style=${options?.style ??
|
||||||
"shield"}`;
|
"shield"}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Returns the guild widget object. Requires the MANAGE_GUILD permission. */
|
/** Returns the guild widget object. Requires the MANAGE_GUILD permission. */
|
||||||
export async function getWidgetSettings(guildID: string) {
|
export async function getWidgetSettings(guildId: string) {
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||||
|
|
||||||
const result = await RequestManager.get(endpoints.GUILD_WIDGET(guildID));
|
const result = await RequestManager.get(endpoints.GUILD_WIDGET(guildId));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import { RequestManager } from "../../rest/request_manager.ts";
|
|||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** Leave a guild */
|
/** Leave a guild */
|
||||||
export async function leaveGuild(guildID: string) {
|
export async function leaveGuild(guildId: string) {
|
||||||
const result = await RequestManager.delete(endpoints.GUILD_LEAVE(guildID));
|
const result = await RequestManager.delete(endpoints.GUILD_LEAVE(guildId));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.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(guildID: string, id: string) {
|
export async function deleteIntegration(guildId: string, id: string) {
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||||
|
|
||||||
const result = await RequestManager.delete(
|
const result = await RequestManager.delete(
|
||||||
endpoints.GUILD_INTEGRATION(guildID, id),
|
endpoints.GUILD_INTEGRATION(guildId, id),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
|
|
||||||
/** Modify the behavior and settings of an integration object for the guild. Requires the MANAGE_GUILD permission. */
|
/** Modify the behavior and settings of an integration object for the guild. Requires the MANAGE_GUILD permission. */
|
||||||
export async function editIntegration(
|
export async function editIntegration(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
id: string,
|
id: string,
|
||||||
options: EditIntegrationOptions,
|
options: EditIntegrationOptions,
|
||||||
) {
|
) {
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||||
|
|
||||||
const result = await RequestManager.patch(
|
const result = await RequestManager.patch(
|
||||||
endpoints.GUILD_INTEGRATION(guildID, id),
|
endpoints.GUILD_INTEGRATION(guildId, id),
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Returns a list of integrations for the guild. Requires the MANAGE_GUILD permission. */
|
/** Returns a list of integrations for the guild. Requires the MANAGE_GUILD permission. */
|
||||||
export async function getIntegrations(guildID: string) {
|
export async function getIntegrations(guildId: string) {
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||||
|
|
||||||
const result = await RequestManager.get(
|
const result = await RequestManager.get(
|
||||||
endpoints.GUILD_INTEGRATIONS(guildID),
|
endpoints.GUILD_INTEGRATIONS(guildId),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Sync an integration. Requires the MANAGE_GUILD permission. */
|
/** Sync an integration. Requires the MANAGE_GUILD permission. */
|
||||||
export async function syncIntegration(guildID: string, id: string) {
|
export async function syncIntegration(guildId: string, id: string) {
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||||
|
|
||||||
const result = await RequestManager.post(
|
const result = await RequestManager.post(
|
||||||
endpoints.GUILD_INTEGRATION_SYNC(guildID, id),
|
endpoints.GUILD_INTEGRATION_SYNC(guildId, id),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -4,27 +4,27 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
|||||||
|
|
||||||
/** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */
|
/** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */
|
||||||
export async function createInvite(
|
export async function createInvite(
|
||||||
channelID: string,
|
channelId: string,
|
||||||
options: CreateInviteOptions,
|
options: CreateInviteOptions,
|
||||||
) {
|
) {
|
||||||
await requireBotChannelPermissions(channelID, ["CREATE_INSTANT_INVITE"]);
|
await requireBotChannelPermissions(channelId, ["CREATE_INSTANT_INVITE"]);
|
||||||
|
|
||||||
if (options.max_age && (options.max_age > 604800 || options.max_age < 0)) {
|
if (options.max_age && (options.max_age > 604800 || options.max_age < 0)) {
|
||||||
console.log(
|
console.log(
|
||||||
`The max age for invite created in ${channelID} was not between 0-604800. Using default values instead.`,
|
`The max age for invite created in ${channelId} was not between 0-604800. Using default values instead.`,
|
||||||
);
|
);
|
||||||
options.max_age = undefined;
|
options.max_age = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.max_uses && (options.max_uses > 100 || options.max_uses < 0)) {
|
if (options.max_uses && (options.max_uses > 100 || options.max_uses < 0)) {
|
||||||
console.log(
|
console.log(
|
||||||
`The max uses for invite created in ${channelID} was not between 0-100. Using default values instead.`,
|
`The max uses for invite created in ${channelId} was not between 0-100. Using default values instead.`,
|
||||||
);
|
);
|
||||||
options.max_uses = undefined;
|
options.max_uses = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await RequestManager.post(
|
const result = await RequestManager.post(
|
||||||
endpoints.CHANNEL_INVITES(channelID),
|
endpoints.CHANNEL_INVITES(channelId),
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import {
|
|||||||
} from "../../util/permissions.ts";
|
} from "../../util/permissions.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 */
|
||||||
export async function deleteInvite(channelID: string, inviteCode: string) {
|
export async function deleteInvite(channelId: string, inviteCode: string) {
|
||||||
const channel = await cacheHandlers.get("channels", channelID);
|
const channel = await cacheHandlers.get("channels", channelId);
|
||||||
|
|
||||||
if (!channel) throw new Error(Errors.CHANNEL_NOT_FOUND);
|
if (!channel) throw new Error(Errors.CHANNEL_NOT_FOUND);
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ export async function deleteInvite(channelID: string, inviteCode: string) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (!hasPerm) {
|
if (!hasPerm) {
|
||||||
await requireBotGuildPermissions(channel!.guildID, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(channel!.guildId, ["MANAGE_GUILD"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await RequestManager.delete(endpoints.INVITE(inviteCode));
|
const result = await RequestManager.delete(endpoints.INVITE(inviteCode));
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Gets the invites for this channel. Requires MANAGE_CHANNEL */
|
/** Gets the invites for this channel. Requires MANAGE_CHANNEL */
|
||||||
export async function getChannelInvites(channelID: string) {
|
export async function getChannelInvites(channelId: string) {
|
||||||
await requireBotChannelPermissions(channelID, ["MANAGE_CHANNELS"]);
|
await requireBotChannelPermissions(channelId, ["MANAGE_CHANNELS"]);
|
||||||
|
|
||||||
const result = await RequestManager.get(endpoints.CHANNEL_INVITES(channelID));
|
const result = await RequestManager.get(endpoints.CHANNEL_INVITES(channelId));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.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(guildID: string) {
|
export async function getInvites(guildId: string) {
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||||
|
|
||||||
const result = await RequestManager.get(endpoints.GUILD_INVITES(guildID));
|
const result = await RequestManager.get(endpoints.GUILD_INVITES(guildId));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Ban a user from the guild and optionally delete previous messages sent by the user. Requires the BAN_MEMBERS permission. */
|
/** Ban a user from the guild and optionally delete previous messages sent by the user. Requires the BAN_MEMBERS permission. */
|
||||||
export async function ban(guildID: string, id: string, options: BanOptions) {
|
export async function ban(guildId: string, id: string, options: BanOptions) {
|
||||||
await requireBotGuildPermissions(guildID, ["BAN_MEMBERS"]);
|
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
|
||||||
|
|
||||||
const result = await RequestManager.put(endpoints.GUILD_BAN(guildID, id), {
|
const result = await RequestManager.put(endpoints.GUILD_BAN(guildId, id), {
|
||||||
...options,
|
...options,
|
||||||
delete_message_days: options.days,
|
delete_message_days: options.days,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { editMember } from "./edit_member.ts";
|
import { editMember } from "./edit_member.ts";
|
||||||
|
|
||||||
/** Kicks a member from a voice channel */
|
/** Kicks a member from a voice channel */
|
||||||
export function disconnectMember(guildID: string, memberID: string) {
|
export function disconnectMember(guildId: string, memberId: string) {
|
||||||
return editMember(guildID, memberID, { channel_id: null });
|
return editMember(guildId, memberId, { channel_id: null });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
|
|
||||||
/** Edit the nickname of the bot in this guild */
|
/** Edit the nickname of the bot in this guild */
|
||||||
export async function editBotNickname(
|
export async function editBotNickname(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
nickname: string | null,
|
nickname: string | null,
|
||||||
) {
|
) {
|
||||||
await requireBotGuildPermissions(guildID, ["CHANGE_NICKNAME"]);
|
await requireBotGuildPermissions(guildId, ["CHANGE_NICKNAME"]);
|
||||||
|
|
||||||
const response = await RequestManager.patch(
|
const response = await RequestManager.patch(
|
||||||
endpoints.USER_NICK(guildID),
|
endpoints.USER_NICK(guildId),
|
||||||
{ nick: nickname },
|
{ nick: nickname },
|
||||||
) as { nick: string };
|
) as { nick: string };
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import {
|
|||||||
|
|
||||||
/** Edit the member */
|
/** Edit the member */
|
||||||
export async function editMember(
|
export async function editMember(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
memberID: string,
|
memberId: string,
|
||||||
options: EditMemberOptions,
|
options: EditMemberOptions,
|
||||||
) {
|
) {
|
||||||
const requiredPerms: Set<Permission> = new Set();
|
const requiredPerms: Set<Permission> = new Set();
|
||||||
@@ -29,10 +29,10 @@ export async function editMember(
|
|||||||
typeof options.deaf !== "undefined" ||
|
typeof options.deaf !== "undefined" ||
|
||||||
(typeof options.channel_id !== "undefined" || "null")
|
(typeof options.channel_id !== "undefined" || "null")
|
||||||
) {
|
) {
|
||||||
const memberVoiceState = (await cacheHandlers.get("guilds", guildID))
|
const memberVoiceState = (await cacheHandlers.get("guilds", guildId))
|
||||||
?.voiceStates.get(memberID);
|
?.voiceStates.get(memberId);
|
||||||
|
|
||||||
if (!memberVoiceState?.channelID) {
|
if (!memberVoiceState?.channelId) {
|
||||||
throw new Error(Errors.MEMBER_NOT_IN_VOICE_CHANNEL);
|
throw new Error(Errors.MEMBER_NOT_IN_VOICE_CHANNEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ export async function editMember(
|
|||||||
]);
|
]);
|
||||||
if (memberVoiceState) {
|
if (memberVoiceState) {
|
||||||
await requireBotChannelPermissions(
|
await requireBotChannelPermissions(
|
||||||
memberVoiceState?.channelID,
|
memberVoiceState?.channelId,
|
||||||
[...requiredVoicePerms],
|
[...requiredVoicePerms],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -62,13 +62,13 @@ export async function editMember(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await requireBotGuildPermissions(guildID, [...requiredPerms]);
|
await requireBotGuildPermissions(guildId, [...requiredPerms]);
|
||||||
|
|
||||||
const result = await RequestManager.patch(
|
const result = await RequestManager.patch(
|
||||||
endpoints.GUILD_MEMBER(guildID, memberID),
|
endpoints.GUILD_MEMBER(guildId, memberId),
|
||||||
options,
|
options,
|
||||||
) as MemberCreatePayload;
|
) as MemberCreatePayload;
|
||||||
const member = await structures.createMemberStruct(result, guildID);
|
const member = await structures.createMemberStruct(result, guildId);
|
||||||
|
|
||||||
return member;
|
return member;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import { requestAllMembers } from "../../ws/shard_manager.ts";
|
|||||||
* GW(this function): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is now 960/m.
|
* GW(this function): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is now 960/m.
|
||||||
*/
|
*/
|
||||||
export function fetchMembers(
|
export function fetchMembers(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
shardID: number,
|
shardId: number,
|
||||||
options?: FetchMembersOptions,
|
options?: FetchMembersOptions,
|
||||||
) {
|
) {
|
||||||
// You can request 1 member without the intent
|
// You can request 1 member without the intent
|
||||||
@@ -24,11 +24,11 @@ export function fetchMembers(
|
|||||||
throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS);
|
throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options?.userIDs?.length) {
|
if (options?.userIds?.length) {
|
||||||
options.limit = options.userIDs.length;
|
options.limit = options.userIds.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
return requestAllMembers(guildID, shardID, resolve, options);
|
return requestAllMembers(guildId, shardId, resolve, options);
|
||||||
}) as Promise<Collection<string, Member>>;
|
}) as Promise<Collection<string, Member>>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,18 +8,18 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
* ⚠️ **ADVANCED USE ONLY: Your members will be cached in your guild most likely. Only use this when you are absolutely sure the member is not cached.**
|
* ⚠️ **ADVANCED USE ONLY: Your members will be cached in your guild most likely. Only use this when you are absolutely sure the member is not cached.**
|
||||||
*/
|
*/
|
||||||
export async function getMember(
|
export async function getMember(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
id: string,
|
id: string,
|
||||||
options?: { force?: boolean },
|
options?: { force?: boolean },
|
||||||
) {
|
) {
|
||||||
const guild = await cacheHandlers.get("guilds", guildID);
|
const guild = await cacheHandlers.get("guilds", guildId);
|
||||||
if (!guild && !options?.force) return;
|
if (!guild && !options?.force) return;
|
||||||
|
|
||||||
const data = (await RequestManager.get(
|
const data = (await RequestManager.get(
|
||||||
endpoints.GUILD_MEMBER(guildID, id),
|
endpoints.GUILD_MEMBER(guildId, id),
|
||||||
)) as MemberCreatePayload;
|
)) as MemberCreatePayload;
|
||||||
|
|
||||||
const memberStruct = await structures.createMemberStruct(data, guildID);
|
const memberStruct = await structures.createMemberStruct(data, guildId);
|
||||||
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
||||||
|
|
||||||
return memberStruct;
|
return memberStruct;
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
* REST(this function): 50/s global(across all shards) rate limit with ALL requests this included
|
* REST(this function): 50/s global(across all shards) rate limit with ALL requests this included
|
||||||
* GW(fetchMembers): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is 960/m.
|
* GW(fetchMembers): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is 960/m.
|
||||||
*/
|
*/
|
||||||
export async function getMembers(guildID: string, options?: GetMemberOptions) {
|
export async function getMembers(guildId: string, options?: GetMemberOptions) {
|
||||||
if (!(identifyPayload.intents && Intents.GUILD_MEMBERS)) {
|
if (!(identifyPayload.intents && Intents.GUILD_MEMBERS)) {
|
||||||
throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS);
|
throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
const guild = await cacheHandlers.get("guilds", guildID);
|
const guild = await cacheHandlers.get("guilds", guildId);
|
||||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||||
|
|
||||||
const members = new Collection<string, Member>();
|
const members = new Collection<string, Member>();
|
||||||
@@ -40,7 +40,7 @@ export async function getMembers(guildID: string, options?: GetMemberOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = (await RequestManager.get(
|
const result = (await RequestManager.get(
|
||||||
`${endpoints.GUILD_MEMBERS(guildID)}?limit=${
|
`${endpoints.GUILD_MEMBERS(guildId)}?limit=${
|
||||||
membersLeft > 1000 ? 1000 : membersLeft
|
membersLeft > 1000 ? 1000 : membersLeft
|
||||||
}${options?.after ? `&after=${options.after}` : ""}`,
|
}${options?.after ? `&after=${options.after}` : ""}`,
|
||||||
)) as MemberCreatePayload[];
|
)) as MemberCreatePayload[];
|
||||||
@@ -49,7 +49,7 @@ export async function getMembers(guildID: string, options?: GetMemberOptions) {
|
|||||||
result.map(async (member) => {
|
result.map(async (member) => {
|
||||||
const memberStruct = await structures.createMemberStruct(
|
const memberStruct = await structures.createMemberStruct(
|
||||||
member,
|
member,
|
||||||
guildID,
|
guildId,
|
||||||
);
|
);
|
||||||
|
|
||||||
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
||||||
|
|||||||
@@ -8,15 +8,15 @@ import { requestAllMembers } from "../../ws/shard_manager.ts";
|
|||||||
* ⚠️ **ADVANCED USE ONLY: Your members will be cached in your guild most likely. Only use this when you are absolutely sure the member is not cached.**
|
* ⚠️ **ADVANCED USE ONLY: Your members will be cached in your guild most likely. Only use this when you are absolutely sure the member is not cached.**
|
||||||
*/
|
*/
|
||||||
export async function getMembersByQuery(
|
export async function getMembersByQuery(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
name: string,
|
name: string,
|
||||||
limit = 1,
|
limit = 1,
|
||||||
) {
|
) {
|
||||||
const guild = await cacheHandlers.get("guilds", guildID);
|
const guild = await cacheHandlers.get("guilds", guildId);
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
return requestAllMembers(guild.id, guild.shardID, resolve, {
|
return requestAllMembers(guild.id, guild.shardId, resolve, {
|
||||||
query: name,
|
query: name,
|
||||||
limit,
|
limit,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { botID } from "../../bot.ts";
|
import { botId } from "../../bot.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import {
|
import {
|
||||||
@@ -7,9 +7,9 @@ import {
|
|||||||
} from "../../util/permissions.ts";
|
} from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Kick a member from the server */
|
/** Kick a member from the server */
|
||||||
export async function kick(guildID: string, memberID: string, reason?: string) {
|
export async function kick(guildId: string, memberId: string, reason?: string) {
|
||||||
const botsHighestRole = await highestRole(guildID, botID);
|
const botsHighestRole = await highestRole(guildId, botId);
|
||||||
const membersHighestRole = await highestRole(guildID, memberID);
|
const membersHighestRole = await highestRole(guildId, memberId);
|
||||||
if (
|
if (
|
||||||
botsHighestRole && membersHighestRole &&
|
botsHighestRole && membersHighestRole &&
|
||||||
botsHighestRole.position <= membersHighestRole.position
|
botsHighestRole.position <= membersHighestRole.position
|
||||||
@@ -17,10 +17,10 @@ export async function kick(guildID: string, memberID: string, reason?: string) {
|
|||||||
throw new Error(Errors.BOTS_HIGHEST_ROLE_TOO_LOW);
|
throw new Error(Errors.BOTS_HIGHEST_ROLE_TOO_LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
await requireBotGuildPermissions(guildID, ["KICK_MEMBERS"]);
|
await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]);
|
||||||
|
|
||||||
const result = await RequestManager.delete(
|
const result = await RequestManager.delete(
|
||||||
endpoints.GUILD_MEMBER(guildID, memberID),
|
endpoints.GUILD_MEMBER(guildId, memberId),
|
||||||
{ reason },
|
{ reason },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ import { editMember } from "./edit_member.ts";
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Move a member from a voice channel to another.
|
* Move a member from a voice channel to another.
|
||||||
* @param guildID the id of the guild which the channel exists in
|
* @param guildId the id of the guild which the channel exists in
|
||||||
* @param memberID the id of the member to move.
|
* @param memberId the id of the member to move.
|
||||||
* @param channelID id of channel to move user to (if they are connected to voice)
|
* @param channelId id of channel to move user to (if they are connected to voice)
|
||||||
*/
|
*/
|
||||||
export function moveMember(
|
export function moveMember(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
memberID: string,
|
memberId: string,
|
||||||
channelID: string,
|
channelId: string,
|
||||||
) {
|
) {
|
||||||
return editMember(guildID, memberID, { channel_id: channelID });
|
return editMember(guildId, memberId, { channel_id: channelId });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,16 +9,16 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
|||||||
* By default, prune will not remove users with roles. You can optionally include specific roles in your prune by providing the roles (resolved to include_roles internally) parameter. Any inactive user that has a subset of the provided role(s) will be included in the prune and users with additional roles will not.
|
* By default, prune will not remove users with roles. You can optionally include specific roles in your prune by providing the roles (resolved to include_roles internally) parameter. Any inactive user that has a subset of the provided role(s) will be included in the prune and users with additional roles will not.
|
||||||
*/
|
*/
|
||||||
export async function pruneMembers(
|
export async function pruneMembers(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
options: PruneOptions,
|
options: PruneOptions,
|
||||||
) {
|
) {
|
||||||
if (options.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS);
|
if (options.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS);
|
||||||
if (options.days && options.days > 30) throw new Error(Errors.PRUNE_MAX_DAYS);
|
if (options.days && options.days > 30) throw new Error(Errors.PRUNE_MAX_DAYS);
|
||||||
|
|
||||||
await requireBotGuildPermissions(guildID, ["KICK_MEMBERS"]);
|
await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]);
|
||||||
|
|
||||||
const result = await RequestManager.post(
|
const result = await RequestManager.post(
|
||||||
endpoints.GUILD_PRUNE(guildID),
|
endpoints.GUILD_PRUNE(guildId),
|
||||||
camelKeysToSnakeCase(options),
|
camelKeysToSnakeCase(options),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ import { formatImageURL } from "../../util/utils.ts";
|
|||||||
|
|
||||||
/** The users custom avatar or the default avatar if you don't have a member object. */
|
/** The users custom avatar or the default avatar if you don't have a member object. */
|
||||||
export function rawAvatarURL(
|
export function rawAvatarURL(
|
||||||
userID: string,
|
userId: string,
|
||||||
discriminator: string,
|
discriminator: string,
|
||||||
avatar?: string | null,
|
avatar?: string | null,
|
||||||
size: ImageSize = 128,
|
size: ImageSize = 128,
|
||||||
format?: ImageFormats,
|
format?: ImageFormats,
|
||||||
) {
|
) {
|
||||||
return avatar
|
return avatar
|
||||||
? formatImageURL(endpoints.USER_AVATAR(userID, avatar), size, format)
|
? formatImageURL(endpoints.USER_AVATAR(userId, avatar), size, format)
|
||||||
: endpoints.USER_DEFAULT_AVATAR(Number(discriminator) % 5);
|
: endpoints.USER_DEFAULT_AVATAR(Number(discriminator) % 5);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,21 +6,21 @@ import { sendMessage } from "../messages/send_message.ts";
|
|||||||
|
|
||||||
/** Send a message to a users DM. Note: this takes 2 API calls. 1 is to fetch the users dm channel. 2 is to send a message to that channel. */
|
/** Send a message to a users DM. Note: this takes 2 API calls. 1 is to fetch the users dm channel. 2 is to send a message to that channel. */
|
||||||
export async function sendDirectMessage(
|
export async function sendDirectMessage(
|
||||||
memberID: string,
|
memberId: string,
|
||||||
content: string | MessageContent,
|
content: string | MessageContent,
|
||||||
) {
|
) {
|
||||||
let dmChannel = await cacheHandlers.get("channels", memberID);
|
let dmChannel = await cacheHandlers.get("channels", memberId);
|
||||||
if (!dmChannel) {
|
if (!dmChannel) {
|
||||||
// If not available in cache create a new one.
|
// If not available in cache create a new one.
|
||||||
const dmChannelData = await RequestManager.post(
|
const dmChannelData = await RequestManager.post(
|
||||||
endpoints.USER_DM,
|
endpoints.USER_DM,
|
||||||
{ recipient_id: memberID },
|
{ recipient_id: memberId },
|
||||||
) as DMChannelCreatePayload;
|
) as DMChannelCreatePayload;
|
||||||
const channelStruct = await structures.createChannelStruct(
|
const channelStruct = await structures.createChannelStruct(
|
||||||
dmChannelData as unknown as ChannelCreatePayload,
|
dmChannelData as unknown as ChannelCreatePayload,
|
||||||
);
|
);
|
||||||
// Recreate the channel and add it undert he users id
|
// Recreate the channel and add it undert he users id
|
||||||
await cacheHandlers.set("channels", memberID, channelStruct);
|
await cacheHandlers.set("channels", memberId, channelStruct);
|
||||||
dmChannel = channelStruct;
|
dmChannel = channelStruct;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Remove the ban for a user. Requires BAN_MEMBERS permission */
|
/** Remove the ban for a user. Requires BAN_MEMBERS permission */
|
||||||
export async function unban(guildID: string, id: string) {
|
export async function unban(guildId: string, id: string) {
|
||||||
await requireBotGuildPermissions(guildID, ["BAN_MEMBERS"]);
|
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
|
||||||
|
|
||||||
const result = await RequestManager.delete(endpoints.GUILD_BAN(guildID, id));
|
const result = await RequestManager.delete(endpoints.GUILD_BAN(guildId, id));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
|||||||
|
|
||||||
/** Create a reaction for the message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. Requires READ_MESSAGE_HISTORY and ADD_REACTIONS */
|
/** Create a reaction for the message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. Requires READ_MESSAGE_HISTORY and ADD_REACTIONS */
|
||||||
export async function addReaction(
|
export async function addReaction(
|
||||||
channelID: string,
|
channelId: string,
|
||||||
messageID: string,
|
messageId: string,
|
||||||
reaction: string,
|
reaction: string,
|
||||||
) {
|
) {
|
||||||
await requireBotChannelPermissions(channelID, [
|
await requireBotChannelPermissions(channelId, [
|
||||||
"ADD_REACTIONS",
|
"ADD_REACTIONS",
|
||||||
"READ_MESSAGE_HISTORY",
|
"READ_MESSAGE_HISTORY",
|
||||||
]);
|
]);
|
||||||
@@ -20,7 +20,7 @@ export async function addReaction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = await RequestManager.put(
|
const result = await RequestManager.put(
|
||||||
endpoints.CHANNEL_MESSAGE_REACTION_ME(channelID, messageID, reaction),
|
endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -2,18 +2,18 @@ import { addReaction } from "./add_reaction.ts";
|
|||||||
|
|
||||||
/** Adds multiple reactions to a message. If `ordered` is true(default is false), it will add the reactions one at a time in the order provided. Note: Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. Requires READ_MESSAGE_HISTORY and ADD_REACTIONS */
|
/** Adds multiple reactions to a message. If `ordered` is true(default is false), it will add the reactions one at a time in the order provided. Note: Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. Requires READ_MESSAGE_HISTORY and ADD_REACTIONS */
|
||||||
export async function addReactions(
|
export async function addReactions(
|
||||||
channelID: string,
|
channelId: string,
|
||||||
messageID: string,
|
messageId: string,
|
||||||
reactions: string[],
|
reactions: string[],
|
||||||
ordered = false,
|
ordered = false,
|
||||||
) {
|
) {
|
||||||
if (!ordered) {
|
if (!ordered) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
reactions.map((reaction) => addReaction(channelID, messageID, reaction)),
|
reactions.map((reaction) => addReaction(channelId, messageId, reaction)),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
for (const reaction of reactions) {
|
for (const reaction of reactions) {
|
||||||
await addReaction(channelID, messageID, reaction);
|
await addReaction(channelId, messageId, reaction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { botID } from "../../bot.ts";
|
import { botId } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
@@ -7,21 +7,21 @@ import { delay } from "../../util/utils.ts";
|
|||||||
|
|
||||||
/** Delete a message with the channel id and message id only. */
|
/** Delete a message with the channel id and message id only. */
|
||||||
export async function deleteMessage(
|
export async function deleteMessage(
|
||||||
channelID: string,
|
channelId: string,
|
||||||
messageID: string,
|
messageId: string,
|
||||||
reason?: string,
|
reason?: string,
|
||||||
delayMilliseconds = 0,
|
delayMilliseconds = 0,
|
||||||
) {
|
) {
|
||||||
const message = await cacheHandlers.get("messages", messageID);
|
const message = await cacheHandlers.get("messages", messageId);
|
||||||
|
|
||||||
if (message && message.author.id !== botID) {
|
if (message && message.author.id !== botId) {
|
||||||
await requireBotChannelPermissions(message.channelID, ["MANAGE_MESSAGES"]);
|
await requireBotChannelPermissions(message.channelId, ["MANAGE_MESSAGES"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delayMilliseconds) await delay(delayMilliseconds);
|
if (delayMilliseconds) await delay(delayMilliseconds);
|
||||||
|
|
||||||
const result = await RequestManager.delete(
|
const result = await RequestManager.delete(
|
||||||
endpoints.CHANNEL_MESSAGE(channelID, messageID),
|
endpoints.CHANNEL_MESSAGE(channelId, messageId),
|
||||||
{ reason },
|
{ reason },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
|||||||
|
|
||||||
/** Delete messages from the channel. 2-100. Requires the MANAGE_MESSAGES permission */
|
/** Delete messages from the channel. 2-100. Requires the MANAGE_MESSAGES permission */
|
||||||
export async function deleteMessages(
|
export async function deleteMessages(
|
||||||
channelID: string,
|
channelId: string,
|
||||||
ids: string[],
|
ids: string[],
|
||||||
reason?: string,
|
reason?: string,
|
||||||
) {
|
) {
|
||||||
await requireBotChannelPermissions(channelID, ["MANAGE_MESSAGES"]);
|
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
|
||||||
|
|
||||||
if (ids.length < 2) {
|
if (ids.length < 2) {
|
||||||
throw new Error(Errors.DELETE_MESSAGES_MIN);
|
throw new Error(Errors.DELETE_MESSAGES_MIN);
|
||||||
@@ -21,7 +21,7 @@ export async function deleteMessages(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = await RequestManager.post(
|
const result = await RequestManager.post(
|
||||||
endpoints.CHANNEL_BULK_DELETE(channelID),
|
endpoints.CHANNEL_BULK_DELETE(channelId),
|
||||||
{
|
{
|
||||||
messages: ids.splice(0, 100),
|
messages: ids.splice(0, 100),
|
||||||
reason,
|
reason,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { botID } from "../../bot.ts";
|
import { botId } from "../../bot.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { Message, structures } from "../../structures/mod.ts";
|
import { Message, structures } from "../../structures/mod.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
@@ -9,7 +9,7 @@ export async function editMessage(
|
|||||||
message: Message,
|
message: Message,
|
||||||
content: string | MessageContent,
|
content: string | MessageContent,
|
||||||
) {
|
) {
|
||||||
if (message.author.id !== botID) {
|
if (message.author.id !== botId) {
|
||||||
throw "You can only edit a message that was sent by the bot.";
|
throw "You can only edit a message that was sent by the bot.";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,14 +19,14 @@ export async function editMessage(
|
|||||||
|
|
||||||
if (content.tts) requiredPerms.push("SEND_TTS_MESSAGES");
|
if (content.tts) requiredPerms.push("SEND_TTS_MESSAGES");
|
||||||
|
|
||||||
await requireBotChannelPermissions(message.channelID, requiredPerms);
|
await requireBotChannelPermissions(message.channelId, requiredPerms);
|
||||||
|
|
||||||
if (content.content && content.content.length > 2000) {
|
if (content.content && content.content.length > 2000) {
|
||||||
throw new Error(Errors.MESSAGE_MAX_LENGTH);
|
throw new Error(Errors.MESSAGE_MAX_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await RequestManager.patch(
|
const result = await RequestManager.patch(
|
||||||
endpoints.CHANNEL_MESSAGE(message.channelID, message.id),
|
endpoints.CHANNEL_MESSAGE(message.channelId, message.id),
|
||||||
content,
|
content,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Fetch a single message from the server. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */
|
/** Fetch a single message from the server. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */
|
||||||
export async function getMessage(channelID: string, id: string) {
|
export async function getMessage(channelId: string, id: string) {
|
||||||
await requireBotChannelPermissions(channelID, [
|
await requireBotChannelPermissions(channelId, [
|
||||||
"VIEW_CHANNEL",
|
"VIEW_CHANNEL",
|
||||||
"READ_MESSAGE_HISTORY",
|
"READ_MESSAGE_HISTORY",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const result = (await RequestManager.get(
|
const result = (await RequestManager.get(
|
||||||
endpoints.CHANNEL_MESSAGE(channelID, id),
|
endpoints.CHANNEL_MESSAGE(channelId, id),
|
||||||
)) as MessageCreateOptions;
|
)) as MessageCreateOptions;
|
||||||
|
|
||||||
return structures.createMessageStruct(result);
|
return structures.createMessageStruct(result);
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
|||||||
|
|
||||||
/** Fetches between 2-100 messages. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */
|
/** Fetches between 2-100 messages. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */
|
||||||
export async function getMessages(
|
export async function getMessages(
|
||||||
channelID: string,
|
channelId: string,
|
||||||
options?:
|
options?:
|
||||||
| GetMessagesAfter
|
| GetMessagesAfter
|
||||||
| GetMessagesBefore
|
| GetMessagesBefore
|
||||||
| GetMessagesAround
|
| GetMessagesAround
|
||||||
| GetMessages,
|
| GetMessages,
|
||||||
) {
|
) {
|
||||||
await requireBotChannelPermissions(channelID, [
|
await requireBotChannelPermissions(channelId, [
|
||||||
"VIEW_CHANNEL",
|
"VIEW_CHANNEL",
|
||||||
"READ_MESSAGE_HISTORY",
|
"READ_MESSAGE_HISTORY",
|
||||||
]);
|
]);
|
||||||
@@ -20,7 +20,7 @@ export async function getMessages(
|
|||||||
if (options?.limit && options.limit > 100) return;
|
if (options?.limit && options.limit > 100) return;
|
||||||
|
|
||||||
const result = (await RequestManager.get(
|
const result = (await RequestManager.get(
|
||||||
endpoints.CHANNEL_MESSAGES(channelID),
|
endpoints.CHANNEL_MESSAGES(channelId),
|
||||||
options,
|
options,
|
||||||
)) as MessageCreateOptions[];
|
)) as MessageCreateOptions[];
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ import { endpoints } from "../../util/constants.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(
|
export async function getReactions(
|
||||||
channelID: string,
|
channelId: string,
|
||||||
messageID: string,
|
messageId: string,
|
||||||
reaction: string,
|
reaction: string,
|
||||||
options?: DiscordGetReactionsParams,
|
options?: DiscordGetReactionsParams,
|
||||||
) {
|
) {
|
||||||
const users = (await RequestManager.get(
|
const users = (await RequestManager.get(
|
||||||
endpoints.CHANNEL_MESSAGE_REACTION(channelID, messageID, reaction),
|
endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction),
|
||||||
options,
|
options,
|
||||||
)) as UserPayload[];
|
)) as UserPayload[];
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Pin a message in a channel. Requires MANAGE_MESSAGES. Max pins allowed in a channel = 50. */
|
/** Pin a message in a channel. Requires MANAGE_MESSAGES. Max pins allowed in a channel = 50. */
|
||||||
export async function pin(channelID: string, messageID: string) {
|
export async function pin(channelId: string, messageId: string) {
|
||||||
await requireBotChannelPermissions(channelID, ["MANAGE_MESSAGES"]);
|
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
|
||||||
|
|
||||||
const result = await RequestManager.put(
|
const result = await RequestManager.put(
|
||||||
endpoints.CHANNEL_PIN(channelID, messageID),
|
endpoints.CHANNEL_PIN(channelId, messageId),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import { structures } from "../../structures/mod.ts";
|
|||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** Crosspost a message in a News Channel to following channels. */
|
/** Crosspost a message in a News Channel to following channels. */
|
||||||
export async function publishMessage(channelID: string, messageID: string) {
|
export async function publishMessage(channelId: string, messageId: string) {
|
||||||
const data = (await RequestManager.post(
|
const data = (await RequestManager.post(
|
||||||
endpoints.CHANNEL_MESSAGE_CROSSPOST(channelID, messageID),
|
endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId),
|
||||||
)) as MessageCreateOptions;
|
)) as MessageCreateOptions;
|
||||||
|
|
||||||
return structures.createMessageStruct(data);
|
return structures.createMessageStruct(data);
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Removes all reactions for all emojis on this message. */
|
/** Removes all reactions for all emojis on this message. */
|
||||||
export async function removeAllReactions(channelID: string, messageID: string) {
|
export async function removeAllReactions(channelId: string, messageId: string) {
|
||||||
await requireBotChannelPermissions(channelID, ["MANAGE_MESSAGES"]);
|
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
|
||||||
|
|
||||||
const result = await RequestManager.delete(
|
const result = await RequestManager.delete(
|
||||||
endpoints.CHANNEL_MESSAGE_REACTIONS(channelID, messageID),
|
endpoints.CHANNEL_MESSAGE_REACTIONS(channelId, messageId),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
|
|
||||||
/** Removes a reaction from the bot on this message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */
|
/** Removes a reaction from the bot on this message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */
|
||||||
export async function removeReaction(
|
export async function removeReaction(
|
||||||
channelID: string,
|
channelId: string,
|
||||||
messageID: string,
|
messageId: string,
|
||||||
reaction: string,
|
reaction: string,
|
||||||
) {
|
) {
|
||||||
if (reaction.startsWith("<:")) {
|
if (reaction.startsWith("<:")) {
|
||||||
@@ -14,7 +14,7 @@ export async function removeReaction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = await RequestManager.delete(
|
const result = await RequestManager.delete(
|
||||||
endpoints.CHANNEL_MESSAGE_REACTION_ME(channelID, messageID, reaction),
|
endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
|||||||
|
|
||||||
/** Removes all reactions for a single emoji on this message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */
|
/** Removes all reactions for a single emoji on this message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */
|
||||||
export async function removeReactionEmoji(
|
export async function removeReactionEmoji(
|
||||||
channelID: string,
|
channelId: string,
|
||||||
messageID: string,
|
messageId: string,
|
||||||
reaction: string,
|
reaction: string,
|
||||||
) {
|
) {
|
||||||
await requireBotChannelPermissions(channelID, ["MANAGE_MESSAGES"]);
|
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
|
||||||
|
|
||||||
if (reaction.startsWith("<:")) {
|
if (reaction.startsWith("<:")) {
|
||||||
reaction = reaction.substring(2, reaction.length - 1);
|
reaction = reaction.substring(2, reaction.length - 1);
|
||||||
@@ -17,7 +17,7 @@ export async function removeReactionEmoji(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = await RequestManager.delete(
|
const result = await RequestManager.delete(
|
||||||
endpoints.CHANNEL_MESSAGE_REACTION(channelID, messageID, reaction),
|
endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
|||||||
|
|
||||||
/** Removes a reaction from the specified user on this message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */
|
/** Removes a reaction from the specified user on this message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */
|
||||||
export async function removeUserReaction(
|
export async function removeUserReaction(
|
||||||
channelID: string,
|
channelId: string,
|
||||||
messageID: string,
|
messageId: string,
|
||||||
reaction: string,
|
reaction: string,
|
||||||
userID: string,
|
userId: string,
|
||||||
) {
|
) {
|
||||||
await requireBotChannelPermissions(channelID, ["MANAGE_MESSAGES"]);
|
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
|
||||||
|
|
||||||
if (reaction.startsWith("<:")) {
|
if (reaction.startsWith("<:")) {
|
||||||
reaction = reaction.substring(2, reaction.length - 1);
|
reaction = reaction.substring(2, reaction.length - 1);
|
||||||
@@ -19,10 +19,10 @@ export async function removeUserReaction(
|
|||||||
|
|
||||||
const result = await RequestManager.delete(
|
const result = await RequestManager.delete(
|
||||||
endpoints.CHANNEL_MESSAGE_REACTION_USER(
|
endpoints.CHANNEL_MESSAGE_REACTION_USER(
|
||||||
channelID,
|
channelId,
|
||||||
messageID,
|
messageId,
|
||||||
reaction,
|
reaction,
|
||||||
userID,
|
userId,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
|||||||
|
|
||||||
/** Send a message to the channel. Requires SEND_MESSAGES permission. */
|
/** Send a message to the channel. Requires SEND_MESSAGES permission. */
|
||||||
export async function sendMessage(
|
export async function sendMessage(
|
||||||
channelID: string,
|
channelId: string,
|
||||||
content: string | MessageContent,
|
content: string | MessageContent,
|
||||||
) {
|
) {
|
||||||
if (typeof content === "string") content = { content };
|
if (typeof content === "string") content = { content };
|
||||||
|
|
||||||
const channel = await cacheHandlers.get("channels", channelID);
|
const channel = await cacheHandlers.get("channels", channelId);
|
||||||
if (channel) {
|
if (channel) {
|
||||||
if (
|
if (
|
||||||
![
|
![
|
||||||
@@ -30,11 +30,11 @@ export async function sendMessage(
|
|||||||
|
|
||||||
if (content.tts) requiredPerms.add("SEND_TTS_MESSAGES");
|
if (content.tts) requiredPerms.add("SEND_TTS_MESSAGES");
|
||||||
if (content.embed) requiredPerms.add("EMBED_LINKS");
|
if (content.embed) requiredPerms.add("EMBED_LINKS");
|
||||||
if (content.replyMessageID || content.mentions?.repliedUser) {
|
if (content.replyMessageId || content.mentions?.repliedUser) {
|
||||||
requiredPerms.add("READ_MESSAGE_HISTORY");
|
requiredPerms.add("READ_MESSAGE_HISTORY");
|
||||||
}
|
}
|
||||||
|
|
||||||
await requireBotChannelPermissions(channelID, [...requiredPerms]);
|
await requireBotChannelPermissions(channelId, [...requiredPerms]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use ... for content length due to unicode characters and js .length handling
|
// Use ... for content length due to unicode characters and js .length handling
|
||||||
@@ -69,7 +69,7 @@ export async function sendMessage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = (await RequestManager.post(
|
const result = (await RequestManager.post(
|
||||||
endpoints.CHANNEL_MESSAGES(channelID),
|
endpoints.CHANNEL_MESSAGES(channelId),
|
||||||
{
|
{
|
||||||
...content,
|
...content,
|
||||||
allowed_mentions: content.mentions
|
allowed_mentions: content.mentions
|
||||||
@@ -78,10 +78,10 @@ export async function sendMessage(
|
|||||||
replied_user: content.mentions.repliedUser,
|
replied_user: content.mentions.repliedUser,
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
...(content.replyMessageID
|
...(content.replyMessageId
|
||||||
? {
|
? {
|
||||||
message_reference: {
|
message_reference: {
|
||||||
message_id: content.replyMessageID,
|
message_id: content.replyMessageId,
|
||||||
fail_if_not_exists: content.failReplyIfNotExists === true,
|
fail_if_not_exists: content.failReplyIfNotExists === true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Unpin a message in a channel. Requires MANAGE_MESSAGES. */
|
/** Unpin a message in a channel. Requires MANAGE_MESSAGES. */
|
||||||
export async function unpin(channelID: string, messageID: string) {
|
export async function unpin(channelId: string, messageId: string) {
|
||||||
await requireBotChannelPermissions(channelID, ["MANAGE_MESSAGES"]);
|
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
|
||||||
|
|
||||||
const result = await RequestManager.delete(
|
const result = await RequestManager.delete(
|
||||||
endpoints.CHANNEL_PIN(channelID, messageID),
|
endpoints.CHANNEL_PIN(channelId, messageId),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import { RequestManager } from "../../rest/request_manager.ts";
|
|||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.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. */
|
||||||
export async function getUser(userID: string) {
|
export async function getUser(userId: string) {
|
||||||
const result = await RequestManager.get(endpoints.USER(userID));
|
const result = await RequestManager.get(endpoints.USER(userId));
|
||||||
|
|
||||||
return result as UserPayload;
|
return result as UserPayload;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
import { categoryChildrenIDs } from "./channels/category_children_ids.ts";
|
import { categoryChildrenIds } from "./channels/category_children_ids.ts";
|
||||||
import { channelOverwriteHasPermission } from "./channels/channel_overwrite_has_permission.ts";
|
import { channelOverwriteHasPermission } from "./channels/channel_overwrite_has_permission.ts";
|
||||||
import { createChannel } from "./channels/create_channel.ts";
|
import { createChannel } from "./channels/create_channel.ts";
|
||||||
import { deleteChannel } from "./channels/delete_channel.ts";
|
import { deleteChannel } from "./channels/delete_channel.ts";
|
||||||
@@ -124,7 +124,7 @@ export {
|
|||||||
avatarURL,
|
avatarURL,
|
||||||
ban,
|
ban,
|
||||||
banMember,
|
banMember,
|
||||||
categoryChildrenIDs,
|
categoryChildrenIds,
|
||||||
channelOverwriteHasPermission,
|
channelOverwriteHasPermission,
|
||||||
createChannel,
|
createChannel,
|
||||||
createEmoji,
|
createEmoji,
|
||||||
@@ -276,7 +276,7 @@ export let helpers = {
|
|||||||
getEmoji,
|
getEmoji,
|
||||||
getEmojis,
|
getEmojis,
|
||||||
// guilds
|
// guilds
|
||||||
categoryChildrenIDs,
|
categoryChildrenIds,
|
||||||
createGuild,
|
createGuild,
|
||||||
deleteServer,
|
deleteServer,
|
||||||
editGuild,
|
editGuild,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { botID } from "../../bot.ts";
|
import { botId } from "../../bot.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import {
|
import {
|
||||||
@@ -8,24 +8,24 @@ import {
|
|||||||
|
|
||||||
/** Add a role to the member */
|
/** Add a role to the member */
|
||||||
export async function addRole(
|
export async function addRole(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
memberID: string,
|
memberId: string,
|
||||||
roleID: string,
|
roleId: string,
|
||||||
reason?: string,
|
reason?: string,
|
||||||
) {
|
) {
|
||||||
const isHigherRolePosition = await isHigherPosition(
|
const isHigherRolePosition = await isHigherPosition(
|
||||||
guildID,
|
guildId,
|
||||||
botID,
|
botId,
|
||||||
roleID,
|
roleId,
|
||||||
);
|
);
|
||||||
if (!isHigherRolePosition) {
|
if (!isHigherRolePosition) {
|
||||||
throw new Error(Errors.BOTS_HIGHEST_ROLE_TOO_LOW);
|
throw new Error(Errors.BOTS_HIGHEST_ROLE_TOO_LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_ROLES"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||||
|
|
||||||
const result = await RequestManager.put(
|
const result = await RequestManager.put(
|
||||||
endpoints.GUILD_MEMBER_ROLE(guildID, memberID, roleID),
|
endpoints.GUILD_MEMBER_ROLE(guildId, memberId, roleId),
|
||||||
{ reason },
|
{ reason },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ import {
|
|||||||
|
|
||||||
/** Create a new role for the guild. Requires the MANAGE_ROLES permission. */
|
/** Create a new role for the guild. Requires the MANAGE_ROLES permission. */
|
||||||
export async function createRole(
|
export async function createRole(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
options: CreateRoleOptions,
|
options: CreateRoleOptions,
|
||||||
reason?: string,
|
reason?: string,
|
||||||
) {
|
) {
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_ROLES"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||||
|
|
||||||
const result = await RequestManager.post(endpoints.GUILD_ROLES(guildID), {
|
const result = await RequestManager.post(endpoints.GUILD_ROLES(guildId), {
|
||||||
...options,
|
...options,
|
||||||
permissions: calculateBits(options?.permissions || []),
|
permissions: calculateBits(options?.permissions || []),
|
||||||
reason,
|
reason,
|
||||||
@@ -23,7 +23,7 @@ export async function createRole(
|
|||||||
|
|
||||||
const roleData = result as RoleData;
|
const roleData = result as RoleData;
|
||||||
const role = await structures.createRoleStruct(roleData);
|
const role = await structures.createRoleStruct(roleData);
|
||||||
const guild = await cacheHandlers.get("guilds", guildID);
|
const guild = await cacheHandlers.get("guilds", guildId);
|
||||||
guild?.roles.set(role.id, role);
|
guild?.roles.set(role.id, role);
|
||||||
|
|
||||||
return role;
|
return role;
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import { endpoints } from "../../util/constants.ts";
|
|||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Delete a guild role. Requires the MANAGE_ROLES permission. */
|
/** Delete a guild role. Requires the MANAGE_ROLES permission. */
|
||||||
export async function deleteRole(guildID: string, id: string) {
|
export async function deleteRole(guildId: string, id: string) {
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_ROLES"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||||
|
|
||||||
const result = await RequestManager.delete(endpoints.GUILD_ROLE(guildID, id));
|
const result = await RequestManager.delete(endpoints.GUILD_ROLE(guildId, id));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ import {
|
|||||||
|
|
||||||
/** Edit a guild role. Requires the MANAGE_ROLES permission. */
|
/** Edit a guild role. Requires the MANAGE_ROLES permission. */
|
||||||
export async function editRole(
|
export async function editRole(
|
||||||
guildID: string,
|
guildId: string,
|
||||||
id: string,
|
id: string,
|
||||||
options: CreateRoleOptions,
|
options: CreateRoleOptions,
|
||||||
) {
|
) {
|
||||||
await requireBotGuildPermissions(guildID, ["MANAGE_ROLES"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||||
|
|
||||||
const result = await RequestManager.patch(endpoints.GUILD_ROLE(guildID, id), {
|
const result = await RequestManager.patch(endpoints.GUILD_ROLE(guildId, id), {
|
||||||
...options,
|
...options,
|
||||||
permissions: options.permissions
|
permissions: options.permissions
|
||||||
? calculateBits(options.permissions)
|
? calculateBits(options.permissions)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user