Merge pull request #876 from discordeno/some-things

Some things
This commit is contained in:
ITOH
2021-04-30 19:00:23 +02:00
committed by GitHub
15 changed files with 79 additions and 142 deletions
+2 -2
View File
@@ -29,8 +29,8 @@ export async function cloneChannel(channelId: string, reason?: string) {
) => ({
id: overwrite.id,
type: overwrite.type,
allow: calculatePermissions(BigInt(overwrite.allow)),
deny: calculatePermissions(BigInt(overwrite.deny)),
allow: calculatePermissions(overwrite.allow),
deny: calculatePermissions(overwrite.deny),
})),
};
@@ -1,9 +1,8 @@
import { rest } from "../../rest/rest.ts";
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) {
/** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event. */
export async function deleteGuild(guildId: string) {
return await rest.runMethod<undefined>(
"delete",
endpoints.GUILDS_BASE(guildId),
+11 -6
View File
@@ -19,7 +19,10 @@ import { ws } from "../../ws/ws.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?: ListGuildMembers) {
export async function getMembers(
guildId: string,
options?: ListGuildMembers & { addToCache?: boolean },
) {
if (!(ws.identifyPayload.intents && DiscordGatewayIntents.GUILD_MEMBERS)) {
throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS);
}
@@ -61,11 +64,13 @@ export async function getMembers(guildId: string, options?: ListGuildMembers) {
guildId,
);
await cacheHandlers.set(
"members",
discordenoMember.id,
discordenoMember,
);
if (options?.addToCache !== false) {
await cacheHandlers.set(
"members",
discordenoMember.id,
discordenoMember,
);
}
return discordenoMember;
}),
+15 -2
View File
@@ -1,12 +1,18 @@
import { rest } from "../../rest/rest.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.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 given user on this message, defaults to bot. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */
export async function removeReaction(
channelId: string,
messageId: string,
reaction: string,
options?: { userId?: string },
) {
if (options?.userId) {
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
}
if (reaction.startsWith("<:")) {
reaction = reaction.substring(2, reaction.length - 1);
} else if (reaction.startsWith("<a:")) {
@@ -15,6 +21,13 @@ export async function removeReaction(
return await rest.runMethod<undefined>(
"delete",
endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction),
options?.userId
? endpoints.CHANNEL_MESSAGE_REACTION_USER(
channelId,
messageId,
reaction,
options.userId,
)
: endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction),
);
}
@@ -1,29 +0,0 @@
import { rest } from "../../rest/rest.ts";
import { endpoints } from "../../util/constants.ts";
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,
reaction: string,
userId: string,
) {
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
if (reaction.startsWith("<:")) {
reaction = reaction.substring(2, reaction.length - 1);
} else if (reaction.startsWith("<a:")) {
reaction = reaction.substring(3, reaction.length - 1);
}
return await rest.runMethod<undefined>(
"delete",
endpoints.CHANNEL_MESSAGE_REACTION_USER(
channelId,
messageId,
reaction,
userId,
),
);
}
+3 -6
View File
@@ -38,7 +38,7 @@ import { emojiURL } from "./emojis/emoji_url.ts";
import { getEmoji } from "./emojis/get_emoji.ts";
import { getEmojis } from "./emojis/get_emojis.ts";
import { createGuild } from "./guilds/create_guild.ts";
import { deleteServer } from "./guilds/delete_server.ts";
import { deleteGuild } from "./guilds/delete_guild.ts";
import { editGuild } from "./guilds/edit_guild.ts";
import { editWelcomeScreen } from "./guilds/edit_welcome_screen.ts";
import { editWidget } from "./guilds/edit_widget.ts";
@@ -93,7 +93,6 @@ import { publishMessage } from "./messages/publish_message.ts";
import { removeAllReactions } from "./messages/remove_all_reactions.ts";
import { removeReaction } from "./messages/remove_reaction.ts";
import { removeReactionEmoji } from "./messages/remove_reaction_emoji.ts";
import { removeUserReaction } from "./messages/remove_user_reaction.ts";
import { sendMessage } from "./messages/send_message.ts";
import { unpin, unpinMessage } from "./messages/unpin_message.ts";
import { editBotStatus } from "./misc/edit_bot_status.ts";
@@ -147,13 +146,13 @@ export {
deleteChannel,
deleteChannelOverwrite,
deleteEmoji,
deleteGuild,
deleteGuildTemplate,
deleteIntegration,
deleteInvite,
deleteMessage,
deleteMessages,
deleteRole,
deleteServer,
deleteSlashCommand,
deleteSlashResponse,
deleteWebhook,
@@ -240,7 +239,6 @@ export {
removeReaction,
removeReactionEmoji,
removeRole,
removeUserReaction,
sendDirectMessage,
sendInteractionResponse,
sendMessage,
@@ -295,7 +293,7 @@ export let helpers = {
// guilds
categoryChildren,
createGuild,
deleteServer,
deleteGuild,
editGuild,
editWidget,
editWelcomeScreen,
@@ -361,7 +359,6 @@ export let helpers = {
removeAllReactions,
removeReactionEmoji,
removeReaction,
removeUserReaction,
sendMessage,
unpinMessage,
// misc