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:
ayntee
2021-03-29 21:03:46 +04:00
committed by GitHub
parent 618d30b65d
commit eaff54f90f
138 changed files with 895 additions and 908 deletions
+18 -18
View File
@@ -9,14 +9,14 @@ import { spawnShards } from "./ws/shard_manager.ts";
export let authorization = "";
export let restAuthorization = "";
export let botID = "";
export let applicationID = "";
export let botId = "";
export let applicationId = "";
export let eventHandlers: EventHandlers = {};
export let botGatewayData: DiscordGetGatewayBot;
export let proxyWSURL = `wss://gateway.discord.gg`;
export let lastShardID = 0;
export let lastShardId = 0;
export const identifyPayload: DiscordIdentify = {
token: "",
@@ -51,10 +51,10 @@ export async function startBot(config: BotConfig) {
: next),
0,
);
lastShardID = botGatewayData.shards;
identifyPayload.shard = [0, lastShardID];
lastShardId = botGatewayData.shards;
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 */
@@ -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. */
export function setBotID(id: string) {
if (botID !== id) botID = id;
/** INTERNAL LIB function used to set the bot Id once the READY event is sent by Discord. */
export function setBotId(id: string) {
if (botId !== id) botId = id;
}
/** INTERNAL LIB function used to set the application ID once the READY event is sent by Discord. */
export function setApplicationID(id: string) {
if (applicationID !== id) applicationID = id;
/** INTERNAL LIB function used to set the application Id once the READY event is sent by Discord. */
export function setApplicationId(id: string) {
if (applicationId !== id) applicationId = id;
}
// BIG BRAIN BOT STUFF ONLY BELOW THIS
@@ -113,10 +113,10 @@ export async function startBigBrainBot(data: BigBrainBotConfig) {
await spawnShards(
botGatewayData,
identifyPayload,
data.firstShardID,
data.lastShardID ||
data.firstShardId,
data.lastShardId ||
(botGatewayData.shards >= 25
? (data.firstShardID + 25)
? (data.firstShardId + 25)
: botGatewayData.shards),
);
}
@@ -130,9 +130,9 @@ export interface 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. */
firstShardID: number;
/** The last shard to start for this worker. By default it will be 25 + the firstShardID. */
lastShardID?: number;
firstShardId: number;
/** The last shard to start for this worker. By default it will be 25 + the firstShardId. */
lastShardId?: number;
/** This can be used to forward the ws handling to a proxy. */
wsURL?: string;
/** This can be used to forward the REST handling to a proxy. */
+6 -6
View File
@@ -5,17 +5,17 @@ import { Collection } from "./util/collection.ts";
export const cache: CacheData = {
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(),
/** 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(),
/** 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(),
/** 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(),
/** 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(),
/** 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(),
fetchAllMembersProcessingRequests: new Collection(),
executedSlashCommands: new Collection(),
+4 -4
View File
@@ -13,22 +13,22 @@ export async function handleChannelDelete(data: DiscordGatewayPayload) {
if (guild) {
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
guild.voiceStates.delete(key);
const member = await cacheHandlers.get("members", vs.userID);
const member = await cacheHandlers.get("members", vs.userId);
if (!member) return;
eventHandlers.voiceChannelLeave?.(member, vs.channelID);
eventHandlers.voiceChannelLeave?.(member, vs.channelId);
}));
}
}
await cacheHandlers.delete("channels", payload.id);
cacheHandlers.forEach("messages", (message) => {
if (message.channelID === payload.id) {
if (message.channelId === payload.id) {
cacheHandlers.delete("messages", message.id);
}
});
+5 -5
View File
@@ -6,7 +6,7 @@ import { basicShards } from "../../ws/shard.ts";
export async function handleGuildCreate(
data: DiscordGatewayPayload,
shardID: number,
shardId: number,
) {
const payload = data.d as DiscordGuild;
// When shards resume they emit GUILD_CREATE again.
@@ -14,16 +14,16 @@ export async function handleGuildCreate(
const guildStruct = await structures.createGuildStruct(
data.d,
shardID,
shardId,
);
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);
shard.unavailableGuildIDs.delete(payload.id);
shard.unavailableGuildIds.delete(payload.id);
}
if (!cache.isReady) return eventHandlers.guildLoaded?.(guildStruct);
+5 -5
View File
@@ -5,7 +5,7 @@ import { basicShards } from "../../ws/shard.ts";
export async function handleGuildDelete(
data: DiscordGatewayPayload,
shardID: number,
shardId: number,
) {
const payload = data.d as DiscordUnavailableGuild;
@@ -15,8 +15,8 @@ export async function handleGuildDelete(
await cacheHandlers.delete("guilds", payload.id);
if (payload.unavailable) {
const shard = basicShards.get(shardID);
if (shard) shard.unavailableGuildIDs.add(payload.id);
const shard = basicShards.get(shardId);
if (shard) shard.unavailableGuildIds.add(payload.id);
await cacheHandlers.set("unavailableGuilds", payload.id, Date.now());
}
@@ -24,13 +24,13 @@ export async function handleGuildDelete(
eventHandlers.guildDelete?.(guild);
cacheHandlers.forEach("messages", (message) => {
if (message.guildID === payload.id) {
if (message.guildId === payload.id) {
cacheHandlers.delete("messages", message.id);
}
});
cacheHandlers.forEach("channels", (channel) => {
if (channel.guildID === payload.id) {
if (channel.guildId === payload.id) {
cacheHandlers.delete("channels", channel.id);
}
});
+4 -4
View File
@@ -6,14 +6,14 @@ import {
export function handleInviteDelete(payload: DiscordGatewayPayload) {
const {
channel_id: channelID,
guild_id: guildID,
channel_id: channelId,
guild_id: guildId,
...rest
} = payload.d as DiscordInviteDelete;
eventHandlers.inviteDelete?.({
...rest,
channelID,
guildID,
channelId,
guildId,
});
}
+3 -3
View File
@@ -44,16 +44,16 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
eventHandlers.membershipScreeningPassed?.(guild, memberStruct);
}
const roleIDs = guildMember?.roles || [];
const roleIds = guildMember?.roles || [];
roleIDs.forEach((id) => {
roleIds.forEach((id) => {
if (!payload.roles.includes(id)) {
eventHandlers.roleLost?.(guild, memberStruct, id);
}
});
payload.roles.forEach((id) => {
if (!roleIDs.includes(id)) {
if (!roleIds.includes(id)) {
eventHandlers.roleGained?.(guild, memberStruct, id);
}
});
+1 -1
View File
@@ -6,7 +6,7 @@ import { DiscordGatewayPayload } from "../../types/gateway.ts";
export async function handleMessageCreate(data: DiscordGatewayPayload) {
const payload = data.d as DiscordMessage;
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
? 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 { structures } from "../../structures/mod.ts";
import {
@@ -21,7 +21,7 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
else {
const newReaction = {
count: 1,
me: payload.user_id === botID,
me: payload.user_id === botId,
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
};
message.reactions = message.reactions
@@ -46,8 +46,8 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
const uncachedOptions = {
...payload,
id: payload.message_id,
channelID: payload.channel_id,
guildID: payload.guild_id || "",
channelId: payload.channel_id,
guildId: payload.guild_id || "",
};
eventHandlers.reactionAdd?.(
@@ -1,4 +1,4 @@
import { botID, eventHandlers } from "../../bot.ts";
import { botId, eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import {
@@ -23,7 +23,7 @@ export async function handleMessageReactionRemove(
else {
const newReaction = {
count: 1,
me: payload.user_id === botID,
me: payload.user_id === botId,
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
};
message.reactions = message.reactions
@@ -48,8 +48,8 @@ export async function handleMessageReactionRemove(
const uncachedOptions = {
...payload,
id: payload.message_id,
channelID: payload.channel_id,
guildID: payload.guild_id,
channelId: payload.channel_id,
guildId: payload.guild_id,
};
eventHandlers.reactionRemove?.(
+23 -23
View File
@@ -1,8 +1,8 @@
import {
eventHandlers,
lastShardID,
setApplicationID,
setBotID,
lastShardId,
setApplicationId,
setBotId,
} from "../../bot.ts";
import { cache, cacheHandlers } from "../../cache.ts";
import { initialMemberLoadQueue } from "../../structures/guild.ts";
@@ -13,30 +13,30 @@ import { allowNextShard, basicShards } from "../../ws/mod.ts";
export async function handleReady(
data: DiscordGatewayPayload,
shardID: number,
shardId: number,
) {
// The bot has already started, the last shard is resumed, however.
if (cache.isReady) return;
const payload = data.d as DiscordReady;
setBotID(payload.user.id);
setApplicationID(payload.application.id);
setBotId(payload.user.id);
setApplicationId(payload.application.id);
// Triggered on each shard
eventHandlers.shardReady?.(shardID);
eventHandlers.shardReady?.(shardId);
// Save when the READY event was received to prevent infinite load loops
const now = Date.now();
const shard = basicShards.get(shardID);
const shard = basicShards.get(shardId);
if (!shard) return;
// Set ready to false just to go sure
shard.ready = false;
// 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
setTimeout(() => checkReady(payload, shardID, now), 2000);
setTimeout(() => checkReady(payload, shardId, now), 2000);
// Wait 5 seconds to spawn next shard
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
/** This function checks if the shard is fully loaded */
function checkReady(payload: DiscordReady, shardID: number, now: number) {
const shard = basicShards.get(shardID);
function checkReady(payload: DiscordReady, shardId: number, now: number) {
const shard = basicShards.get(shardId);
if (!shard) return;
// Check if all guilds were loaded
if (shard.unavailableGuildIDs.size) {
if (shard.unavailableGuildIds.size) {
if (Date.now() - now > 10000) {
eventHandlers.shardFailedToLoad?.(shardID, shard.unavailableGuildIDs);
eventHandlers.shardFailedToLoad?.(shardId, shard.unavailableGuildIds);
// Force execute the loaded function to prevent infinite loop
loaded(shardID);
loaded(shardId);
} else {
// 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 {
// All guilds were loaded
loaded(shardID);
loaded(shardId);
}
}
async function loaded(shardID: number) {
const shard = basicShards.get(shardID);
async function loaded(shardId: number) {
const shard = basicShards.get(shardId);
if (!shard) return;
shard.ready = true;
// 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
if (basicShards.some((shard) => !shard.ready)) {
setTimeout(() => loaded(shardID), 2000);
setTimeout(() => loaded(shardId), 2000);
} else {
cache.isReady = true;
eventHandlers.ready?.();
// 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(
members.map(async (member) => {
const memberStruct = await structures.createMemberStruct(
member,
guildID,
guildId,
);
return cacheHandlers.set(
+9 -9
View File
@@ -20,10 +20,10 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
guild.voiceStates.set(payload.user_id, {
...payload,
guildID: payload.guild_id,
channelID: payload.channel_id || "",
userID: payload.user_id,
sessionID: payload.session_id,
guildId: payload.guild_id,
channelId: payload.channel_id || "",
userId: payload.user_id,
sessionId: payload.session_id,
selfDeaf: payload.self_deaf,
selfMute: payload.self_mute,
selfStream: payload.self_stream || false,
@@ -31,22 +31,22 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
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
if (payload.channel_id) {
if (cachedState?.channelID) { // Was in a channel before
if (cachedState?.channelId) { // Was in a channel before
eventHandlers.voiceChannelSwitch?.(
member,
payload.channel_id,
cachedState.channelID,
cachedState.channelId,
);
} else { // Was not in a channel before so user just joined
eventHandlers.voiceChannelJoin?.(member, payload.channel_id);
}
} // Left the channel
else if (cachedState?.channelID) {
else if (cachedState?.channelId) {
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";
/** 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(
"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 */
export function channelOverwriteHasPermission(
guildID: string,
guildId: string,
id: string,
overwrites: RawOverwrite[],
permissions: Permission[],
) {
const overwrite = overwrites.find((perm) => perm.id === id) ||
overwrites.find((perm) => perm.id === guildID);
overwrites.find((perm) => perm.id === guildId);
return permissions.every((perm) => {
if (overwrite) {
+3 -3
View File
@@ -9,7 +9,7 @@ import {
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
export async function createChannel(
guildID: string,
guildId: string,
name: string,
options?: ChannelCreateOptions,
) {
@@ -20,10 +20,10 @@ export async function createChannel(
overwrite.deny.forEach(requiredPerms.add, requiredPerms);
});
await requireBotGuildPermissions(guildID, [...requiredPerms]);
await requireBotGuildPermissions(guildId, [...requiredPerms]);
const result = (await RequestManager.post(
endpoints.GUILD_CHANNELS(guildID),
endpoints.GUILD_CHANNELS(guildId),
{
...options,
name,
+7 -7
View File
@@ -5,25 +5,25 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
export async function deleteChannel(
guildID: string,
channelID: string,
guildId: string,
channelId: 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?.rulesChannelID === channelID) {
if (guild?.rulesChannelId === channelId) {
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);
}
const result = await RequestManager.delete(
endpoints.CHANNEL_BASE(channelID),
endpoints.CHANNEL_BASE(channelId),
{ 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. */
export async function deleteChannelOverwrite(
guildID: string,
channelID: string,
overwriteID: string,
guildId: string,
channelId: string,
overwriteId: string,
) {
await requireBotGuildPermissions(guildID, ["MANAGE_ROLES"]);
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
const result = await RequestManager.delete(
endpoints.CHANNEL_OVERWRITE(channelID, overwriteID),
endpoints.CHANNEL_OVERWRITE(channelId, overwriteId),
);
return result;
+11 -11
View File
@@ -7,18 +7,18 @@ import {
/** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */
export async function editChannel(
channelID: string,
channelId: string,
options: ChannelEditOptions,
reason?: string,
) {
await requireBotChannelPermissions(channelID, ["MANAGE_CHANNELS"]);
await requireBotChannelPermissions(channelId, ["MANAGE_CHANNELS"]);
if (options.name || options.topic) {
const request = editChannelNameTopicQueue.get(channelID);
const request = editChannelNameTopicQueue.get(channelId);
if (!request) {
// If this hasnt been done before simply add 1 for it
editChannelNameTopicQueue.set(channelID, {
channelID: channelID,
editChannelNameTopicQueue.set(channelId, {
channelId: channelId,
amount: 1,
// 10 minutes from now
timestamp: Date.now() + 600000,
@@ -30,7 +30,7 @@ export async function editChannel(
request.timestamp = Date.now() + 600000;
} else {
// 2 have already been used add to queue
request.items.push({ channelID, options });
request.items.push({ channelId, options });
if (editChannelProcessing) return;
editChannelProcessing = true;
processEditChannelQueue();
@@ -43,7 +43,7 @@ export async function editChannel(
// deno-lint-ignore camelcase
rate_limit_per_user: options.rateLimitPerUser,
// deno-lint-ignore camelcase
parent_id: options.parentID,
parent_id: options.parentId,
// deno-lint-ignore camelcase
user_limit: options.userLimit,
// 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,
reason,
});
@@ -75,7 +75,7 @@ function processEditChannelQueue() {
if (now > request.timestamp) return;
// 10 minutes have passed so we can reset this channel again
if (!request.items.length) {
return editChannelNameTopicQueue.delete(request.channelID);
return editChannelNameTopicQueue.delete(request.channelId);
}
request.amount = 0;
// There are items to process for this request
@@ -83,11 +83,11 @@ function processEditChannelQueue() {
if (!details) return;
editChannel(details.channelID, details.options);
editChannel(details.channelId, details.options);
const secondDetails = request.items.shift();
if (!secondDetails) return;
return editChannel(secondDetails.channelID, secondDetails.options);
return editChannel(secondDetails.channelId, secondDetails.options);
});
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. */
export async function editChannelOverwrite(
guildID: string,
channelID: string,
overwriteID: string,
guildId: string,
channelId: string,
overwriteId: string,
options: Omit<Overwrite, "id">,
) {
await requireBotGuildPermissions(guildID, ["MANAGE_ROLES"]);
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
const result = await RequestManager.put(
endpoints.CHANNEL_OVERWRITE(channelID, overwriteID),
endpoints.CHANNEL_OVERWRITE(channelId, overwriteId),
{
allow: calculateBits(options.allow),
deny: calculateBits(options.deny),
+5 -5
View File
@@ -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. */
export async function followChannel(
sourceChannelID: string,
targetChannelID: string,
sourceChannelId: string,
targetChannelId: string,
) {
await requireBotChannelPermissions(targetChannelID, ["MANAGE_WEBHOOKS"]);
await requireBotChannelPermissions(targetChannelId, ["MANAGE_WEBHOOKS"]);
const data = (await RequestManager.post(
endpoints.CHANNEL_FOLLOW(sourceChannelID),
endpoints.CHANNEL_FOLLOW(sourceChannelId),
{
webhook_channel_id: targetChannelID,
webhook_channel_id: targetChannelId,
},
)) as FollowedChannelPayload;
+2 -2
View File
@@ -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.**
*/
export async function getChannel(channelID: string, addToCache = true) {
export async function getChannel(channelId: string, addToCache = true) {
const result = (await RequestManager.get(
endpoints.CHANNEL_BASE(channelID),
endpoints.CHANNEL_BASE(channelId),
)) as ChannelCreatePayload;
const channelStruct = await structures.createChannelStruct(
+3 -3
View File
@@ -3,11 +3,11 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
/** Gets the webhooks for this channel. Requires MANAGE_WEBHOOKS */
export async function getChannelWebhooks(channelID: string) {
await requireBotChannelPermissions(channelID, ["MANAGE_WEBHOOKS"]);
export async function getChannelWebhooks(channelId: string) {
await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]);
const result = await RequestManager.get(
endpoints.CHANNEL_WEBHOOKS(channelID),
endpoints.CHANNEL_WEBHOOKS(channelId),
);
return result as WebhookPayload[];
+3 -3
View File
@@ -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.**
*/
export async function getChannels(guildID: string, addToCache = true) {
export async function getChannels(guildId: string, addToCache = true) {
const result = (await RequestManager.get(
endpoints.GUILD_CHANNELS(guildID),
endpoints.GUILD_CHANNELS(guildId),
) as ChannelCreatePayload[]);
return Promise.all(result.map(async (res) => {
const channelStruct = await structures.createChannelStruct(res, guildID);
const channelStruct = await structures.createChannelStruct(res, guildId);
if (addToCache) {
await cacheHandlers.set("channels", channelStruct.id, channelStruct);
}
+2 -2
View File
@@ -3,9 +3,9 @@ import { structures } from "../../structures/mod.ts";
import { endpoints } from "../../util/constants.ts";
/** Get pinned messages in this channel. */
export async function getPins(channelID: string) {
export async function getPins(channelId: string) {
const result = (await RequestManager.get(
endpoints.CHANNEL_PINS(channelID),
endpoints.CHANNEL_PINS(channelId),
)) as MessageCreateOptions[];
return Promise.all(
+4 -4
View File
@@ -1,11 +1,11 @@
import { cacheHandlers } from "../../cache.ts";
/** Checks whether a channel is synchronized with its parent/category channel or not. */
export async function isChannelSynced(channelID: string) {
const channel = await cacheHandlers.get("channels", channelID);
if (!channel?.parentID) return false;
export async function isChannelSynced(channelId: string) {
const channel = await cacheHandlers.get("channels", channelId);
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;
return channel.permissionOverwrites?.every((overwrite) => {
+4 -4
View File
@@ -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,
* this endpoint may be called to let the user know that the bot is processing their message.
*/
export async function startTyping(channelID: string) {
const channel = await cacheHandlers.get("channels", channelID);
export async function startTyping(channelId: string) {
const channel = await cacheHandlers.get("channels", channelId);
// If the channel is cached, we can do extra checks/safety
if (channel) {
if (
@@ -23,7 +23,7 @@ export async function startTyping(channelID: string) {
}
const hasSendMessagesPerm = await botHasChannelPermissions(
channelID,
channelId,
["SEND_MESSAGES"],
);
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;
}
+2 -2
View File
@@ -3,7 +3,7 @@ import { endpoints } from "../../util/constants.ts";
/** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */
export async function swapChannels(
guildID: string,
guildId: string,
channelPositions: PositionSwap[],
) {
if (channelPositions.length < 2) {
@@ -11,7 +11,7 @@ export async function swapChannels(
}
const result = await RequestManager.patch(
endpoints.GUILD_CHANNELS(guildID),
endpoints.GUILD_CHANNELS(guildId),
channelPositions,
);
+4 -4
View File
@@ -1,4 +1,4 @@
import { applicationID } from "../../bot.ts";
import { applicationId } from "../../bot.ts";
import { RequestManager } from "../../rest/request_manager.ts";
import { endpoints } from "../../util/constants.ts";
import { validateSlashCommands } from "../../util/utils.ts";
@@ -18,9 +18,9 @@ export async function createSlashCommand(options: CreateSlashCommandOptions) {
validateSlashCommands([options], true);
const result = await RequestManager.post(
options.guildID
? endpoints.COMMANDS_GUILD(applicationID, options.guildID)
: endpoints.COMMANDS(applicationID),
options.guildId
? endpoints.COMMANDS_GUILD(applicationId, options.guildId)
: endpoints.COMMANDS(applicationId),
{
...options,
},
+5 -5
View File
@@ -1,13 +1,13 @@
import { applicationID } from "../../bot.ts";
import { applicationId } from "../../bot.ts";
import { RequestManager } from "../../rest/request_manager.ts";
import { endpoints } from "../../util/constants.ts";
/** Deletes a slash command. */
export function deleteSlashCommand(id: string, guildID?: string) {
if (!guildID) {
return RequestManager.delete(endpoints.COMMANDS_ID(applicationID, id));
export function deleteSlashCommand(id: string, guildId?: string) {
if (!guildId) {
return RequestManager.delete(endpoints.COMMANDS_ID(applicationId, id));
}
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 { 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. */
export async function deleteSlashResponse(token: string, messageID?: string) {
export async function deleteSlashResponse(token: string, messageId?: string) {
const result = await RequestManager.delete(
messageID
? endpoints.INTERACTION_ID_TOKEN_MESSAGEID(
applicationID,
messageId
? endpoints.INTERACTION_ID_TOKEN_MESSAGE_ID(
applicationId,
token,
messageID,
messageId,
)
: endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationID, token),
: endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token),
);
return result;
+6 -6
View File
@@ -1,9 +1,9 @@
import { applicationID } from "../../bot.ts";
import { applicationId } from "../../bot.ts";
import { RequestManager } from "../../rest/request_manager.ts";
import { structures } from "../../structures/mod.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(
token: string,
options: EditSlashResponseOptions,
@@ -49,14 +49,14 @@ export async function editSlashResponse(
}
const result = await RequestManager.patch(
options.messageID
? endpoints.WEBHOOK_MESSAGE(applicationID, token, options.messageID)
: endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationID, token),
options.messageId
? endpoints.WEBHOOK_MESSAGE(applicationId, token, options.messageId)
: endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token),
options,
);
// 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(
result as MessageCreateOptions,
+6 -6
View File
@@ -1,13 +1,13 @@
import { applicationID } from "../../bot.ts";
import { applicationId } from "../../bot.ts";
import { RequestManager } from "../../rest/request_manager.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. */
export async function getSlashCommand(commandID: string, guildID?: string) {
/** 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) {
const result = await RequestManager.get(
guildID
? endpoints.COMMANDS_GUILD_ID(applicationID, guildID, commandID)
: endpoints.COMMANDS_ID(applicationID, commandID),
guildId
? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, commandId)
: endpoints.COMMANDS_ID(applicationId, commandId),
);
return result as SlashCommand;
+5 -5
View File
@@ -1,14 +1,14 @@
import { applicationID } from "../../bot.ts";
import { applicationId } from "../../bot.ts";
import { RequestManager } from "../../rest/request_manager.ts";
import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
/** 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(
guildID
? endpoints.COMMANDS_GUILD(applicationID, guildID)
: endpoints.COMMANDS(applicationID),
guildId
? endpoints.COMMANDS_GUILD(applicationId, guildId)
: endpoints.COMMANDS(applicationId),
)) as SlashCommand[];
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 { RequestManager } from "../../rest/request_manager.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 (cache.executedSlashCommands.has(token)) {
return RequestManager.post(endpoints.WEBHOOK(applicationID, token), {
return RequestManager.post(endpoints.WEBHOOK(applicationId, token), {
...options,
});
}
+6 -6
View File
@@ -1,4 +1,4 @@
import { applicationID } from "../../bot.ts";
import { applicationId } from "../../bot.ts";
import { RequestManager } from "../../rest/request_manager.ts";
import { endpoints } from "../../util/constants.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.
*/
export async function upsertSlashCommand(
commandID: string,
commandId: string,
options: UpsertSlashCommandOptions,
guildID?: string,
guildId?: string,
) {
validateSlashCommands([options]);
const result = await RequestManager.patch(
guildID
? endpoints.COMMANDS_GUILD_ID(applicationID, guildID, commandID)
: endpoints.COMMANDS_ID(applicationID, commandID),
guildId
? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, commandId)
: endpoints.COMMANDS_ID(applicationId, commandId),
options,
);
@@ -1,4 +1,4 @@
import { applicationID } from "../../bot.ts";
import { applicationId } from "../../bot.ts";
import { RequestManager } from "../../rest/request_manager.ts";
import { endpoints } from "../../util/constants.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.
*
* **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(
options: UpsertSlashCommandsOptions[],
guildID?: string,
guildId?: string,
) {
validateSlashCommands(options);
const result = await RequestManager.put(
guildID
? endpoints.COMMANDS_GUILD(applicationID, guildID)
: endpoints.COMMANDS(applicationID),
guildId
? endpoints.COMMANDS_GUILD(applicationId, guildId)
: endpoints.COMMANDS(applicationId),
options,
);
+3 -3
View File
@@ -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. */
export async function createEmoji(
guildID: string,
guildId: string,
name: string,
image: string,
options: CreateEmojisOptions,
) {
await requireBotGuildPermissions(guildID, ["MANAGE_EMOJIS"]);
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
if (image && !image.startsWith("data:image/")) {
image = await urlToBase64(image);
}
const result = await RequestManager.post(endpoints.GUILD_EMOJIS(guildID), {
const result = await RequestManager.post(endpoints.GUILD_EMOJIS(guildId), {
...options,
name,
image,
+3 -3
View File
@@ -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. */
export async function deleteEmoji(
guildID: string,
guildId: string,
id: string,
reason?: string,
) {
await requireBotGuildPermissions(guildID, ["MANAGE_EMOJIS"]);
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
const result = await RequestManager.delete(
endpoints.GUILD_EMOJI(guildID, id),
endpoints.GUILD_EMOJI(guildId, id),
{ reason },
);
+3 -3
View File
@@ -4,14 +4,14 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Modify the given emoji. Requires the MANAGE_EMOJIS permission. */
export async function editEmoji(
guildID: string,
guildId: string,
id: string,
options: EditEmojisOptions,
) {
await requireBotGuildPermissions(guildID, ["MANAGE_EMOJIS"]);
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
const result = await RequestManager.patch(
endpoints.GUILD_EMOJI(guildID, id),
endpoints.GUILD_EMOJI(guildId, id),
{
name: options.name,
roles: options.roles,
+6 -6
View File
@@ -3,26 +3,26 @@ import { RequestManager } from "../../rest/request_manager.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
*/
export async function getEmoji(
guildID: string,
emojiID: string,
guildId: string,
emojiId: string,
addToCache = true,
) {
const result = (await RequestManager.get(
endpoints.GUILD_EMOJI(guildID, emojiID),
endpoints.GUILD_EMOJI(guildId, emojiId),
)) as Emoji;
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);
guild.emojis.set(result.id ?? result.name, result);
cacheHandlers.set(
"guilds",
guildID,
guildId,
guild,
);
}
+4 -4
View File
@@ -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
*/
export async function getEmojis(guildID: string, addToCache = true) {
export async function getEmojis(guildId: string, addToCache = true) {
const result = (await RequestManager.get(
endpoints.GUILD_EMOJIS(guildID),
endpoints.GUILD_EMOJIS(guildId),
)) as Emoji[];
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);
result.forEach((emoji) => guild.emojis.set(emoji.id ?? emoji.name, emoji));
cacheHandlers.set("guilds", guildID, guild);
cacheHandlers.set("guilds", guildId, guild);
}
return result;
+2 -2
View File
@@ -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.
*/
export async function deleteServer(guildID: string) {
const result = await RequestManager.delete(endpoints.GUILDS_BASE(guildID));
export async function deleteServer(guildId: string) {
const result = await RequestManager.delete(endpoints.GUILDS_BASE(guildId));
return result;
}
+3 -3
View File
@@ -4,8 +4,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { urlToBase64 } from "../../util/utils.ts";
/** Modify a guilds settings. Requires the MANAGE_GUILD permission. */
export async function editGuild(guildID: string, options: GuildEditOptions) {
await requireBotGuildPermissions(guildID, ["MANAGE_GUILD"]);
export async function editGuild(guildId: string, options: GuildEditOptions) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
if (options.icon && !options.icon.startsWith("data:image/")) {
options.icon = await urlToBase64(options.icon);
@@ -20,7 +20,7 @@ export async function editGuild(guildID: string, options: GuildEditOptions) {
}
const result = await RequestManager.patch(
endpoints.GUILDS_BASE(guildID),
endpoints.GUILDS_BASE(guildId),
options,
);
+5 -5
View File
@@ -4,15 +4,15 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Modify a guild widget object for the guild. Requires the MANAGE_GUILD permission. */
export async function editWidget(
guildID: string,
guildId: string,
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,
channel_id: channelID,
channel_id: channelId,
});
return result;
+3 -3
View File
@@ -4,12 +4,12 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */
export async function getAuditLogs(
guildID: string,
guildId: string,
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,
action_type: options.action_type
? AuditLogs[options.action_type]
+3 -3
View File
@@ -3,11 +3,11 @@ import { endpoints } from "../../util/constants.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. */
export async function getBan(guildID: string, memberID: string) {
await requireBotGuildPermissions(guildID, ["BAN_MEMBERS"]);
export async function getBan(guildId: string, memberId: string) {
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
const result = await RequestManager.get(
endpoints.GUILD_BAN(guildID, memberID),
endpoints.GUILD_BAN(guildId, memberId),
);
return result as BannedUser;
+3 -3
View File
@@ -4,11 +4,11 @@ import { endpoints } from "../../util/constants.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. */
export async function getBans(guildID: string) {
await requireBotGuildPermissions(guildID, ["BAN_MEMBERS"]);
export async function getBans(guildId: string) {
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
const results = (await RequestManager.get(
endpoints.GUILD_BANS(guildID),
endpoints.GUILD_BANS(guildId),
)) as BannedUser[];
return new Collection<string, BannedUser>(
+2 -2
View File
@@ -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.
* So it does not cache the guild, you must do it manually.
* */
export async function getGuild(guildID: string, counts = true) {
const result = await RequestManager.get(endpoints.GUILDS_BASE(guildID), {
export async function getGuild(guildId: string, counts = true) {
const result = await RequestManager.get(endpoints.GUILDS_BASE(guildId), {
with_counts: counts,
});
+2 -2
View File
@@ -2,8 +2,8 @@ import { RequestManager } from "../../rest/request_manager.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. */
export async function getGuildPreview(guildID: string) {
const result = await RequestManager.get(endpoints.GUILD_PREVIEW(guildID));
export async function getGuildPreview(guildId: string) {
const result = await RequestManager.get(endpoints.GUILD_PREVIEW(guildId));
return result;
}
+4 -4
View File
@@ -1,19 +1,19 @@
import { RequestManager } from "../../rest/request_manager.ts";
import { endpoints } from "../../util/constants.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 */
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 > 30) {
throw new Error(Errors.PRUNE_MAX_DAYS);
}
await requireBotGuildPermissions(guildID, ["KICK_MEMBERS"]);
await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]);
const result = await RequestManager.get(
endpoints.GUILD_PRUNE(guildID),
endpoints.GUILD_PRUNE(guildId),
camelKeysToSnakeCase(options ?? {}),
) as PrunePayload;
+2 -2
View File
@@ -2,8 +2,8 @@ import { RequestManager } from "../../rest/request_manager.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. */
export async function getVanityURL(guildID: string) {
const result = await RequestManager.get(endpoints.GUILD_VANITY_URL(guildID));
export async function getVanityURL(guildId: string) {
const result = await RequestManager.get(endpoints.GUILD_VANITY_URL(guildId));
return result;
}
+2 -2
View File
@@ -2,8 +2,8 @@ import { RequestManager } from "../../rest/request_manager.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. */
export async function getVoiceRegions(guildID: string) {
const result = await RequestManager.get(endpoints.GUILD_REGIONS(guildID));
export async function getVoiceRegions(guildId: string) {
const result = await RequestManager.get(endpoints.GUILD_REGIONS(guildId));
return result;
}
+3 -3
View File
@@ -3,12 +3,12 @@ import { RequestManager } from "../../rest/request_manager.ts";
import { endpoints } from "../../util/constants.ts";
/** 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) {
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?.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 -3
View File
@@ -3,18 +3,18 @@ import { endpoints } from "../../util/constants.ts";
/** Returns the widget image URL for the guild. */
export async function getWidgetImageURL(
guildID: string,
guildId: string,
options?: {
style?: "shield" | "banner1" | "banner2" | "banner3" | "banner4";
force?: boolean;
},
) {
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.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"}`;
}
+3 -3
View File
@@ -3,10 +3,10 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Returns the guild widget object. Requires the MANAGE_GUILD permission. */
export async function getWidgetSettings(guildID: string) {
await requireBotGuildPermissions(guildID, ["MANAGE_GUILD"]);
export async function getWidgetSettings(guildId: string) {
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;
}
+2 -2
View File
@@ -2,8 +2,8 @@ import { RequestManager } from "../../rest/request_manager.ts";
import { endpoints } from "../../util/constants.ts";
/** Leave a guild */
export async function leaveGuild(guildID: string) {
const result = await RequestManager.delete(endpoints.GUILD_LEAVE(guildID));
export async function leaveGuild(guildId: string) {
const result = await RequestManager.delete(endpoints.GUILD_LEAVE(guildId));
return result;
}
@@ -3,11 +3,11 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Delete the attached integration object for the guild with this id. Requires MANAGE_GUILD permission. */
export async function deleteIntegration(guildID: string, id: string) {
await requireBotGuildPermissions(guildID, ["MANAGE_GUILD"]);
export async function deleteIntegration(guildId: string, id: string) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const result = await RequestManager.delete(
endpoints.GUILD_INTEGRATION(guildID, id),
endpoints.GUILD_INTEGRATION(guildId, id),
);
return result;
+3 -3
View File
@@ -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. */
export async function editIntegration(
guildID: string,
guildId: string,
id: string,
options: EditIntegrationOptions,
) {
await requireBotGuildPermissions(guildID, ["MANAGE_GUILD"]);
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const result = await RequestManager.patch(
endpoints.GUILD_INTEGRATION(guildID, id),
endpoints.GUILD_INTEGRATION(guildId, id),
options,
);
+3 -3
View File
@@ -3,11 +3,11 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Returns a list of integrations for the guild. Requires the MANAGE_GUILD permission. */
export async function getIntegrations(guildID: string) {
await requireBotGuildPermissions(guildID, ["MANAGE_GUILD"]);
export async function getIntegrations(guildId: string) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const result = await RequestManager.get(
endpoints.GUILD_INTEGRATIONS(guildID),
endpoints.GUILD_INTEGRATIONS(guildId),
);
return result;
+3 -3
View File
@@ -3,11 +3,11 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Sync an integration. Requires the MANAGE_GUILD permission. */
export async function syncIntegration(guildID: string, id: string) {
await requireBotGuildPermissions(guildID, ["MANAGE_GUILD"]);
export async function syncIntegration(guildId: string, id: string) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const result = await RequestManager.post(
endpoints.GUILD_INTEGRATION_SYNC(guildID, id),
endpoints.GUILD_INTEGRATION_SYNC(guildId, id),
);
return result;
+5 -5
View File
@@ -4,27 +4,27 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
/** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */
export async function createInvite(
channelID: string,
channelId: string,
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)) {
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;
}
if (options.max_uses && (options.max_uses > 100 || options.max_uses < 0)) {
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;
}
const result = await RequestManager.post(
endpoints.CHANNEL_INVITES(channelID),
endpoints.CHANNEL_INVITES(channelId),
options,
);
+3 -3
View File
@@ -7,8 +7,8 @@ import {
} from "../../util/permissions.ts";
/** Deletes an invite for the given code. Requires `MANAGE_CHANNELS` or `MANAGE_GUILD` permission */
export async function deleteInvite(channelID: string, inviteCode: string) {
const channel = await cacheHandlers.get("channels", channelID);
export async function deleteInvite(channelId: string, inviteCode: string) {
const channel = await cacheHandlers.get("channels", channelId);
if (!channel) throw new Error(Errors.CHANNEL_NOT_FOUND);
@@ -17,7 +17,7 @@ export async function deleteInvite(channelID: string, inviteCode: string) {
]);
if (!hasPerm) {
await requireBotGuildPermissions(channel!.guildID, ["MANAGE_GUILD"]);
await requireBotGuildPermissions(channel!.guildId, ["MANAGE_GUILD"]);
}
const result = await RequestManager.delete(endpoints.INVITE(inviteCode));
+3 -3
View File
@@ -3,10 +3,10 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
/** Gets the invites for this channel. Requires MANAGE_CHANNEL */
export async function getChannelInvites(channelID: string) {
await requireBotChannelPermissions(channelID, ["MANAGE_CHANNELS"]);
export async function getChannelInvites(channelId: string) {
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;
}
+3 -3
View File
@@ -3,10 +3,10 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Get all the invites for this guild. Requires MANAGE_GUILD permission */
export async function getInvites(guildID: string) {
await requireBotGuildPermissions(guildID, ["MANAGE_GUILD"]);
export async function getInvites(guildId: string) {
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;
}
+3 -3
View File
@@ -3,10 +3,10 @@ import { endpoints } from "../../util/constants.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. */
export async function ban(guildID: string, id: string, options: BanOptions) {
await requireBotGuildPermissions(guildID, ["BAN_MEMBERS"]);
export async function ban(guildId: string, id: string, options: BanOptions) {
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,
delete_message_days: options.days,
});
+2 -2
View File
@@ -1,6 +1,6 @@
import { editMember } from "./edit_member.ts";
/** Kicks a member from a voice channel */
export function disconnectMember(guildID: string, memberID: string) {
return editMember(guildID, memberID, { channel_id: null });
export function disconnectMember(guildId: string, memberId: string) {
return editMember(guildId, memberId, { channel_id: null });
}
+3 -3
View File
@@ -4,13 +4,13 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Edit the nickname of the bot in this guild */
export async function editBotNickname(
guildID: string,
guildId: string,
nickname: string | null,
) {
await requireBotGuildPermissions(guildID, ["CHANGE_NICKNAME"]);
await requireBotGuildPermissions(guildId, ["CHANGE_NICKNAME"]);
const response = await RequestManager.patch(
endpoints.USER_NICK(guildID),
endpoints.USER_NICK(guildId),
{ nick: nickname },
) as { nick: string };
+9 -9
View File
@@ -9,8 +9,8 @@ import {
/** Edit the member */
export async function editMember(
guildID: string,
memberID: string,
guildId: string,
memberId: string,
options: EditMemberOptions,
) {
const requiredPerms: Set<Permission> = new Set();
@@ -29,10 +29,10 @@ export async function editMember(
typeof options.deaf !== "undefined" ||
(typeof options.channel_id !== "undefined" || "null")
) {
const memberVoiceState = (await cacheHandlers.get("guilds", guildID))
?.voiceStates.get(memberID);
const memberVoiceState = (await cacheHandlers.get("guilds", guildId))
?.voiceStates.get(memberId);
if (!memberVoiceState?.channelID) {
if (!memberVoiceState?.channelId) {
throw new Error(Errors.MEMBER_NOT_IN_VOICE_CHANNEL);
}
@@ -51,7 +51,7 @@ export async function editMember(
]);
if (memberVoiceState) {
await requireBotChannelPermissions(
memberVoiceState?.channelID,
memberVoiceState?.channelId,
[...requiredVoicePerms],
);
}
@@ -62,13 +62,13 @@ export async function editMember(
}
}
await requireBotGuildPermissions(guildID, [...requiredPerms]);
await requireBotGuildPermissions(guildId, [...requiredPerms]);
const result = await RequestManager.patch(
endpoints.GUILD_MEMBER(guildID, memberID),
endpoints.GUILD_MEMBER(guildId, memberId),
options,
) as MemberCreatePayload;
const member = await structures.createMemberStruct(result, guildID);
const member = await structures.createMemberStruct(result, guildId);
return member;
}
+5 -5
View File
@@ -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.
*/
export function fetchMembers(
guildID: string,
shardID: number,
guildId: string,
shardId: number,
options?: FetchMembersOptions,
) {
// You can request 1 member without the intent
@@ -24,11 +24,11 @@ export function fetchMembers(
throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS);
}
if (options?.userIDs?.length) {
options.limit = options.userIDs.length;
if (options?.userIds?.length) {
options.limit = options.userIds.length;
}
return new Promise((resolve) => {
return requestAllMembers(guildID, shardID, resolve, options);
return requestAllMembers(guildId, shardId, resolve, options);
}) as Promise<Collection<string, Member>>;
}
+4 -4
View File
@@ -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.**
*/
export async function getMember(
guildID: string,
guildId: string,
id: string,
options?: { force?: boolean },
) {
const guild = await cacheHandlers.get("guilds", guildID);
const guild = await cacheHandlers.get("guilds", guildId);
if (!guild && !options?.force) return;
const data = (await RequestManager.get(
endpoints.GUILD_MEMBER(guildID, id),
endpoints.GUILD_MEMBER(guildId, id),
)) as MemberCreatePayload;
const memberStruct = await structures.createMemberStruct(data, guildID);
const memberStruct = await structures.createMemberStruct(data, guildId);
await cacheHandlers.set("members", memberStruct.id, memberStruct);
return memberStruct;
+4 -4
View File
@@ -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
* 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)) {
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);
const members = new Collection<string, Member>();
@@ -40,7 +40,7 @@ export async function getMembers(guildID: string, options?: GetMemberOptions) {
}
const result = (await RequestManager.get(
`${endpoints.GUILD_MEMBERS(guildID)}?limit=${
`${endpoints.GUILD_MEMBERS(guildId)}?limit=${
membersLeft > 1000 ? 1000 : membersLeft
}${options?.after ? `&after=${options.after}` : ""}`,
)) as MemberCreatePayload[];
@@ -49,7 +49,7 @@ export async function getMembers(guildID: string, options?: GetMemberOptions) {
result.map(async (member) => {
const memberStruct = await structures.createMemberStruct(
member,
guildID,
guildId,
);
await cacheHandlers.set("members", memberStruct.id, memberStruct);
+3 -3
View File
@@ -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.**
*/
export async function getMembersByQuery(
guildID: string,
guildId: string,
name: string,
limit = 1,
) {
const guild = await cacheHandlers.get("guilds", guildID);
const guild = await cacheHandlers.get("guilds", guildId);
if (!guild) return;
return new Promise((resolve) => {
return requestAllMembers(guild.id, guild.shardID, resolve, {
return requestAllMembers(guild.id, guild.shardId, resolve, {
query: name,
limit,
});
+6 -6
View File
@@ -1,4 +1,4 @@
import { botID } from "../../bot.ts";
import { botId } from "../../bot.ts";
import { RequestManager } from "../../rest/request_manager.ts";
import { endpoints } from "../../util/constants.ts";
import {
@@ -7,9 +7,9 @@ import {
} from "../../util/permissions.ts";
/** Kick a member from the server */
export async function kick(guildID: string, memberID: string, reason?: string) {
const botsHighestRole = await highestRole(guildID, botID);
const membersHighestRole = await highestRole(guildID, memberID);
export async function kick(guildId: string, memberId: string, reason?: string) {
const botsHighestRole = await highestRole(guildId, botId);
const membersHighestRole = await highestRole(guildId, memberId);
if (
botsHighestRole && membersHighestRole &&
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);
}
await requireBotGuildPermissions(guildID, ["KICK_MEMBERS"]);
await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]);
const result = await RequestManager.delete(
endpoints.GUILD_MEMBER(guildID, memberID),
endpoints.GUILD_MEMBER(guildId, memberId),
{ reason },
);
+7 -7
View File
@@ -2,14 +2,14 @@ import { editMember } from "./edit_member.ts";
/**
* Move a member from a voice channel to another.
* @param guildID the id of the guild which the channel exists in
* @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 guildId the id of the guild which the channel exists in
* @param memberId the id of the member to move.
* @param channelId id of channel to move user to (if they are connected to voice)
*/
export function moveMember(
guildID: string,
memberID: string,
channelID: string,
guildId: string,
memberId: string,
channelId: string,
) {
return editMember(guildID, memberID, { channel_id: channelID });
return editMember(guildId, memberId, { channel_id: channelId });
}
+3 -3
View File
@@ -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.
*/
export async function pruneMembers(
guildID: string,
guildId: string,
options: PruneOptions,
) {
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);
await requireBotGuildPermissions(guildID, ["KICK_MEMBERS"]);
await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]);
const result = await RequestManager.post(
endpoints.GUILD_PRUNE(guildID),
endpoints.GUILD_PRUNE(guildId),
camelKeysToSnakeCase(options),
);
+2 -2
View File
@@ -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. */
export function rawAvatarURL(
userID: string,
userId: string,
discriminator: string,
avatar?: string | null,
size: ImageSize = 128,
format?: ImageFormats,
) {
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);
}
+4 -4
View File
@@ -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. */
export async function sendDirectMessage(
memberID: string,
memberId: string,
content: string | MessageContent,
) {
let dmChannel = await cacheHandlers.get("channels", memberID);
let dmChannel = await cacheHandlers.get("channels", memberId);
if (!dmChannel) {
// If not available in cache create a new one.
const dmChannelData = await RequestManager.post(
endpoints.USER_DM,
{ recipient_id: memberID },
{ recipient_id: memberId },
) as DMChannelCreatePayload;
const channelStruct = await structures.createChannelStruct(
dmChannelData as unknown as ChannelCreatePayload,
);
// Recreate the channel and add it undert he users id
await cacheHandlers.set("channels", memberID, channelStruct);
await cacheHandlers.set("channels", memberId, channelStruct);
dmChannel = channelStruct;
}
+3 -3
View File
@@ -3,10 +3,10 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Remove the ban for a user. Requires BAN_MEMBERS permission */
export async function unban(guildID: string, id: string) {
await requireBotGuildPermissions(guildID, ["BAN_MEMBERS"]);
export async function unban(guildId: string, id: string) {
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;
}
+4 -4
View File
@@ -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 */
export async function addReaction(
channelID: string,
messageID: string,
channelId: string,
messageId: string,
reaction: string,
) {
await requireBotChannelPermissions(channelID, [
await requireBotChannelPermissions(channelId, [
"ADD_REACTIONS",
"READ_MESSAGE_HISTORY",
]);
@@ -20,7 +20,7 @@ export async function addReaction(
}
const result = await RequestManager.put(
endpoints.CHANNEL_MESSAGE_REACTION_ME(channelID, messageID, reaction),
endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction),
);
return result;
+4 -4
View File
@@ -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 */
export async function addReactions(
channelID: string,
messageID: string,
channelId: string,
messageId: string,
reactions: string[],
ordered = false,
) {
if (!ordered) {
await Promise.all(
reactions.map((reaction) => addReaction(channelID, messageID, reaction)),
reactions.map((reaction) => addReaction(channelId, messageId, reaction)),
);
} else {
for (const reaction of reactions) {
await addReaction(channelID, messageID, reaction);
await addReaction(channelId, messageId, reaction);
}
}
}
+7 -7
View File
@@ -1,4 +1,4 @@
import { botID } from "../../bot.ts";
import { botId } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { RequestManager } from "../../rest/request_manager.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. */
export async function deleteMessage(
channelID: string,
messageID: string,
channelId: string,
messageId: string,
reason?: string,
delayMilliseconds = 0,
) {
const message = await cacheHandlers.get("messages", messageID);
const message = await cacheHandlers.get("messages", messageId);
if (message && message.author.id !== botID) {
await requireBotChannelPermissions(message.channelID, ["MANAGE_MESSAGES"]);
if (message && message.author.id !== botId) {
await requireBotChannelPermissions(message.channelId, ["MANAGE_MESSAGES"]);
}
if (delayMilliseconds) await delay(delayMilliseconds);
const result = await RequestManager.delete(
endpoints.CHANNEL_MESSAGE(channelID, messageID),
endpoints.CHANNEL_MESSAGE(channelId, messageId),
{ reason },
);
+3 -3
View File
@@ -4,11 +4,11 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
/** Delete messages from the channel. 2-100. Requires the MANAGE_MESSAGES permission */
export async function deleteMessages(
channelID: string,
channelId: string,
ids: string[],
reason?: string,
) {
await requireBotChannelPermissions(channelID, ["MANAGE_MESSAGES"]);
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
if (ids.length < 2) {
throw new Error(Errors.DELETE_MESSAGES_MIN);
@@ -21,7 +21,7 @@ export async function deleteMessages(
}
const result = await RequestManager.post(
endpoints.CHANNEL_BULK_DELETE(channelID),
endpoints.CHANNEL_BULK_DELETE(channelId),
{
messages: ids.splice(0, 100),
reason,
+4 -4
View File
@@ -1,4 +1,4 @@
import { botID } from "../../bot.ts";
import { botId } from "../../bot.ts";
import { RequestManager } from "../../rest/request_manager.ts";
import { Message, structures } from "../../structures/mod.ts";
import { endpoints } from "../../util/constants.ts";
@@ -9,7 +9,7 @@ export async function editMessage(
message: Message,
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.";
}
@@ -19,14 +19,14 @@ export async function editMessage(
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) {
throw new Error(Errors.MESSAGE_MAX_LENGTH);
}
const result = await RequestManager.patch(
endpoints.CHANNEL_MESSAGE(message.channelID, message.id),
endpoints.CHANNEL_MESSAGE(message.channelId, message.id),
content,
);
+3 -3
View File
@@ -4,14 +4,14 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
/** Fetch a single message from the server. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */
export async function getMessage(channelID: string, id: string) {
await requireBotChannelPermissions(channelID, [
export async function getMessage(channelId: string, id: string) {
await requireBotChannelPermissions(channelId, [
"VIEW_CHANNEL",
"READ_MESSAGE_HISTORY",
]);
const result = (await RequestManager.get(
endpoints.CHANNEL_MESSAGE(channelID, id),
endpoints.CHANNEL_MESSAGE(channelId, id),
)) as MessageCreateOptions;
return structures.createMessageStruct(result);
+3 -3
View File
@@ -5,14 +5,14 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
/** Fetches between 2-100 messages. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */
export async function getMessages(
channelID: string,
channelId: string,
options?:
| GetMessagesAfter
| GetMessagesBefore
| GetMessagesAround
| GetMessages,
) {
await requireBotChannelPermissions(channelID, [
await requireBotChannelPermissions(channelId, [
"VIEW_CHANNEL",
"READ_MESSAGE_HISTORY",
]);
@@ -20,7 +20,7 @@ export async function getMessages(
if (options?.limit && options.limit > 100) return;
const result = (await RequestManager.get(
endpoints.CHANNEL_MESSAGES(channelID),
endpoints.CHANNEL_MESSAGES(channelId),
options,
)) as MessageCreateOptions[];
+3 -3
View File
@@ -4,13 +4,13 @@ import { endpoints } from "../../util/constants.ts";
/** Get a list of users that reacted with this emoji. */
export async function getReactions(
channelID: string,
messageID: string,
channelId: string,
messageId: string,
reaction: string,
options?: DiscordGetReactionsParams,
) {
const users = (await RequestManager.get(
endpoints.CHANNEL_MESSAGE_REACTION(channelID, messageID, reaction),
endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction),
options,
)) as UserPayload[];
+3 -3
View File
@@ -3,11 +3,11 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
/** Pin a message in a channel. Requires MANAGE_MESSAGES. Max pins allowed in a channel = 50. */
export async function pin(channelID: string, messageID: string) {
await requireBotChannelPermissions(channelID, ["MANAGE_MESSAGES"]);
export async function pin(channelId: string, messageId: string) {
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
const result = await RequestManager.put(
endpoints.CHANNEL_PIN(channelID, messageID),
endpoints.CHANNEL_PIN(channelId, messageId),
);
return result;
+2 -2
View File
@@ -3,9 +3,9 @@ import { structures } from "../../structures/mod.ts";
import { endpoints } from "../../util/constants.ts";
/** 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(
endpoints.CHANNEL_MESSAGE_CROSSPOST(channelID, messageID),
endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId),
)) as MessageCreateOptions;
return structures.createMessageStruct(data);
+3 -3
View File
@@ -3,11 +3,11 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
/** Removes all reactions for all emojis on this message. */
export async function removeAllReactions(channelID: string, messageID: string) {
await requireBotChannelPermissions(channelID, ["MANAGE_MESSAGES"]);
export async function removeAllReactions(channelId: string, messageId: string) {
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
const result = await RequestManager.delete(
endpoints.CHANNEL_MESSAGE_REACTIONS(channelID, messageID),
endpoints.CHANNEL_MESSAGE_REACTIONS(channelId, messageId),
);
return result;
+3 -3
View File
@@ -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. */
export async function removeReaction(
channelID: string,
messageID: string,
channelId: string,
messageId: string,
reaction: string,
) {
if (reaction.startsWith("<:")) {
@@ -14,7 +14,7 @@ export async function removeReaction(
}
const result = await RequestManager.delete(
endpoints.CHANNEL_MESSAGE_REACTION_ME(channelID, messageID, reaction),
endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction),
);
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. */
export async function removeReactionEmoji(
channelID: string,
messageID: string,
channelId: string,
messageId: string,
reaction: string,
) {
await requireBotChannelPermissions(channelID, ["MANAGE_MESSAGES"]);
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
if (reaction.startsWith("<:")) {
reaction = reaction.substring(2, reaction.length - 1);
@@ -17,7 +17,7 @@ export async function removeReactionEmoji(
}
const result = await RequestManager.delete(
endpoints.CHANNEL_MESSAGE_REACTION(channelID, messageID, reaction),
endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction),
);
return result;
+7 -7
View File
@@ -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. */
export async function removeUserReaction(
channelID: string,
messageID: string,
channelId: string,
messageId: string,
reaction: string,
userID: string,
userId: string,
) {
await requireBotChannelPermissions(channelID, ["MANAGE_MESSAGES"]);
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
if (reaction.startsWith("<:")) {
reaction = reaction.substring(2, reaction.length - 1);
@@ -19,10 +19,10 @@ export async function removeUserReaction(
const result = await RequestManager.delete(
endpoints.CHANNEL_MESSAGE_REACTION_USER(
channelID,
messageID,
channelId,
messageId,
reaction,
userID,
userId,
),
);
+7 -7
View File
@@ -6,12 +6,12 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
/** Send a message to the channel. Requires SEND_MESSAGES permission. */
export async function sendMessage(
channelID: string,
channelId: string,
content: string | MessageContent,
) {
if (typeof content === "string") content = { content };
const channel = await cacheHandlers.get("channels", channelID);
const channel = await cacheHandlers.get("channels", channelId);
if (channel) {
if (
![
@@ -30,11 +30,11 @@ export async function sendMessage(
if (content.tts) requiredPerms.add("SEND_TTS_MESSAGES");
if (content.embed) requiredPerms.add("EMBED_LINKS");
if (content.replyMessageID || content.mentions?.repliedUser) {
if (content.replyMessageId || content.mentions?.repliedUser) {
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
@@ -69,7 +69,7 @@ export async function sendMessage(
}
const result = (await RequestManager.post(
endpoints.CHANNEL_MESSAGES(channelID),
endpoints.CHANNEL_MESSAGES(channelId),
{
...content,
allowed_mentions: content.mentions
@@ -78,10 +78,10 @@ export async function sendMessage(
replied_user: content.mentions.repliedUser,
}
: undefined,
...(content.replyMessageID
...(content.replyMessageId
? {
message_reference: {
message_id: content.replyMessageID,
message_id: content.replyMessageId,
fail_if_not_exists: content.failReplyIfNotExists === true,
},
}
+3 -3
View File
@@ -3,11 +3,11 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
/** Unpin a message in a channel. Requires MANAGE_MESSAGES. */
export async function unpin(channelID: string, messageID: string) {
await requireBotChannelPermissions(channelID, ["MANAGE_MESSAGES"]);
export async function unpin(channelId: string, messageId: string) {
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
const result = await RequestManager.delete(
endpoints.CHANNEL_PIN(channelID, messageID),
endpoints.CHANNEL_PIN(channelId, messageId),
);
return result;
+2 -2
View File
@@ -2,8 +2,8 @@ import { RequestManager } from "../../rest/request_manager.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. */
export async function getUser(userID: string) {
const result = await RequestManager.get(endpoints.USER(userID));
export async function getUser(userId: string) {
const result = await RequestManager.get(endpoints.USER(userId));
return result as UserPayload;
}
+3 -3
View File
@@ -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 { createChannel } from "./channels/create_channel.ts";
import { deleteChannel } from "./channels/delete_channel.ts";
@@ -124,7 +124,7 @@ export {
avatarURL,
ban,
banMember,
categoryChildrenIDs,
categoryChildrenIds,
channelOverwriteHasPermission,
createChannel,
createEmoji,
@@ -276,7 +276,7 @@ export let helpers = {
getEmoji,
getEmojis,
// guilds
categoryChildrenIDs,
categoryChildrenIds,
createGuild,
deleteServer,
editGuild,
+9 -9
View File
@@ -1,4 +1,4 @@
import { botID } from "../../bot.ts";
import { botId } from "../../bot.ts";
import { RequestManager } from "../../rest/request_manager.ts";
import { endpoints } from "../../util/constants.ts";
import {
@@ -8,24 +8,24 @@ import {
/** Add a role to the member */
export async function addRole(
guildID: string,
memberID: string,
roleID: string,
guildId: string,
memberId: string,
roleId: string,
reason?: string,
) {
const isHigherRolePosition = await isHigherPosition(
guildID,
botID,
roleID,
guildId,
botId,
roleId,
);
if (!isHigherRolePosition) {
throw new Error(Errors.BOTS_HIGHEST_ROLE_TOO_LOW);
}
await requireBotGuildPermissions(guildID, ["MANAGE_ROLES"]);
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
const result = await RequestManager.put(
endpoints.GUILD_MEMBER_ROLE(guildID, memberID, roleID),
endpoints.GUILD_MEMBER_ROLE(guildId, memberId, roleId),
{ reason },
);
+4 -4
View File
@@ -9,13 +9,13 @@ import {
/** Create a new role for the guild. Requires the MANAGE_ROLES permission. */
export async function createRole(
guildID: string,
guildId: string,
options: CreateRoleOptions,
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,
permissions: calculateBits(options?.permissions || []),
reason,
@@ -23,7 +23,7 @@ export async function createRole(
const roleData = result as 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);
return role;
+3 -3
View File
@@ -3,10 +3,10 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Delete a guild role. Requires the MANAGE_ROLES permission. */
export async function deleteRole(guildID: string, id: string) {
await requireBotGuildPermissions(guildID, ["MANAGE_ROLES"]);
export async function deleteRole(guildId: string, id: string) {
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;
}
+3 -3
View File
@@ -7,13 +7,13 @@ import {
/** Edit a guild role. Requires the MANAGE_ROLES permission. */
export async function editRole(
guildID: string,
guildId: string,
id: string,
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,
permissions: options.permissions
? calculateBits(options.permissions)

Some files were not shown because too many files have changed in this diff Show More