mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-04 09:50:07 +00:00
Progress
This commit is contained in:
@@ -74,7 +74,7 @@ import {
|
||||
DiscordenoShard,
|
||||
} from "./ws/mod.ts";
|
||||
import { validateLength } from "./util/validate_length.ts";
|
||||
import { delay, validateSlashOptionChoices, validateSlashOptions } from "./util/utils.ts";
|
||||
import {delay, validateComponents, validateSlashOptionChoices, validateSlashOptions} from "./util/utils.ts";
|
||||
import { iconBigintToHash, iconHashToBigInt } from "./util/hash.ts";
|
||||
import { calculateShardId } from "./util/calculate_shard_id.ts";
|
||||
|
||||
@@ -284,6 +284,7 @@ export function createUtils(options: Partial<HelperUtils>) {
|
||||
validateSlashOptions,
|
||||
validateSlashOptionChoices,
|
||||
requireBotChannelPermissions,
|
||||
validateComponents
|
||||
};
|
||||
}
|
||||
|
||||
@@ -310,6 +311,7 @@ export interface HelperUtils {
|
||||
validateSlashOptions: typeof validateSlashOptions;
|
||||
validateSlashOptionChoices: typeof validateSlashOptionChoices;
|
||||
requireBotChannelPermissions: typeof requireBotChannelPermissions;
|
||||
validateComponents: typeof validateComponents;
|
||||
}
|
||||
|
||||
export function createGatewayManager(options: Partial<GatewayManager>): GatewayManager {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { Bot } from "../../bot.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(bot: Bot, channelId: bigint, messageId: bigint, reaction: string) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
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 */
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { delay } from "../../util/utils.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Delete a message with the channel id and message id only. */
|
||||
export async function deleteMessage(
|
||||
@@ -16,7 +14,7 @@ export async function deleteMessage(
|
||||
await bot.utils.requireBotChannelPermissions(bot, message.channelId, ["MANAGE_MESSAGES"]);
|
||||
}
|
||||
|
||||
if (delayMilliseconds) await delay(delayMilliseconds);
|
||||
if (delayMilliseconds) await bot.utils.delay(delayMilliseconds);
|
||||
|
||||
return await bot.rest.runMethod<undefined>(
|
||||
bot.rest,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Delete messages from the channel. 2-100. Requires the MANAGE_MESSAGES permission */
|
||||
export async function deleteMessages(bot: Bot, channelId: bigint, ids: bigint[], reason?: string) {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { EditMessage } from "../../types/messages/edit_message.ts";
|
||||
import type { EditMessage } from "../../types/messages/edit_message.ts";
|
||||
import type { Message } from "../../types/messages/message.ts";
|
||||
import type { PermissionStrings } from "../../types/permissions/permission_strings.ts";
|
||||
import { validateComponents } from "../../util/utils.ts";
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
|
||||
/** Edit the message. */
|
||||
export async function editMessage(bot: Bot, channelId: bigint, messageId: bigint, content: string | EditMessage) {
|
||||
@@ -22,7 +21,7 @@ export async function editMessage(bot: Bot, channelId: bigint, messageId: bigint
|
||||
if (typeof content === "string") content = { content };
|
||||
|
||||
if (content.components?.length) {
|
||||
validateComponents(bot, content.components);
|
||||
bot.utils.validateComponents(bot, content.components);
|
||||
}
|
||||
|
||||
content.embeds?.splice(10);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import type { Message } from "../../types/messages/message.ts";
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
|
||||
/** Fetch a single message from the server. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */
|
||||
export async function getMessage(bot: Bot, channelId: bigint, id: bigint) {
|
||||
|
||||
@@ -1,28 +1,26 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { Errors } from "../../types/discordeno/errors.ts";
|
||||
import {
|
||||
import type {
|
||||
GetMessagesAfter,
|
||||
GetMessagesAround,
|
||||
GetMessagesBefore,
|
||||
GetMessagesLimit,
|
||||
} from "../../types/messages/get_messages.ts";
|
||||
import type { Message } from "../../types/messages/message.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type {SnakeCasedPropertiesDeep} from "../../types/util.ts";
|
||||
|
||||
/** Fetches between 2-100 messages. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */
|
||||
export async function getMessages(
|
||||
bot: Bot,
|
||||
channelId: bigint,
|
||||
options?: GetMessagesAfter | GetMessagesBefore | GetMessagesAround | GetMessagesLimit
|
||||
) {
|
||||
await requireBotChannelPermissions(channelId, ["VIEW_CHANNEL", "READ_MESSAGE_HISTORY"]);
|
||||
await bot.utils.requireBotChannelPermissions(bot, channelId, ["VIEW_CHANNEL", "READ_MESSAGE_HISTORY"]);
|
||||
|
||||
if (options?.limit && (options.limit < 0 || options.limit > 100)) {
|
||||
throw new Error(Errors.INVALID_GET_MESSAGES_LIMIT);
|
||||
throw new Error(bot.constants.Errors.INVALID_GET_MESSAGES_LIMIT);
|
||||
}
|
||||
|
||||
const result = await rest.runMethod<Message[]>("get", endpoints.CHANNEL_MESSAGES(channelId), options);
|
||||
const result = await bot.rest.runMethod<SnakeCasedPropertiesDeep<Message>[]>(bot.rest, "get", bot.constants.endpoints.CHANNEL_MESSAGES(channelId), options);
|
||||
|
||||
return await Promise.all(result.map((res) => structures.createDiscordenoMessage(res)));
|
||||
return await Promise.all(result.map((res) => bot.transformers.message(bot, res)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user