mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
messages
This commit is contained in:
@@ -19,10 +19,8 @@ export async function addReaction(
|
|||||||
reaction = reaction.substring(3, reaction.length - 1);
|
reaction = reaction.substring(3, reaction.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await rest.runMethod(
|
return await rest.runMethod<undefined>(
|
||||||
"put",
|
"put",
|
||||||
endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction),
|
endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,9 @@ export async function deleteMessage(
|
|||||||
|
|
||||||
if (delayMilliseconds) await delay(delayMilliseconds);
|
if (delayMilliseconds) await delay(delayMilliseconds);
|
||||||
|
|
||||||
const result = await rest.runMethod(
|
return await rest.runMethod<undefined>(
|
||||||
"delete",
|
"delete",
|
||||||
endpoints.CHANNEL_MESSAGE(channelId, messageId),
|
endpoints.CHANNEL_MESSAGE(channelId, messageId),
|
||||||
{ reason },
|
{ reason },
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { rest } from "../../rest/rest.ts";
|
|||||||
import { DiscordenoMessage } from "../../structures/message.ts";
|
import { DiscordenoMessage } from "../../structures/message.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { EditMessage } from "../../types/messages/edit_message.ts";
|
import { EditMessage } from "../../types/messages/edit_message.ts";
|
||||||
import { DiscordMessage } from "../../types/messages/message.ts";
|
import { Message } from "../../types/messages/message.ts";
|
||||||
import { Errors } from "../../types/misc/errors.ts";
|
import { Errors } from "../../types/misc/errors.ts";
|
||||||
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
|
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
@@ -28,11 +28,11 @@ export async function editMessage(
|
|||||||
throw new Error(Errors.MESSAGE_MAX_LENGTH);
|
throw new Error(Errors.MESSAGE_MAX_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result: DiscordMessage = await rest.runMethod(
|
const result = await rest.runMethod<Message>(
|
||||||
"patch",
|
"patch",
|
||||||
endpoints.CHANNEL_MESSAGE(message.channelId, message.id),
|
endpoints.CHANNEL_MESSAGE(message.channelId, message.id),
|
||||||
content,
|
content,
|
||||||
);
|
);
|
||||||
|
|
||||||
return structures.createDiscordenoMessage(result);
|
return await structures.createDiscordenoMessage(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { rest } from "../../rest/rest.ts";
|
import { rest } from "../../rest/rest.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { DiscordMessage } from "../../types/messages/message.ts";
|
import { Message } from "../../types/messages/message.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
@@ -14,10 +14,10 @@ export async function getMessage(channelId: string, id: string) {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = (await rest.runMethod(
|
const result = await rest.runMethod<Message>(
|
||||||
"get",
|
"get",
|
||||||
endpoints.CHANNEL_MESSAGE(channelId, id),
|
endpoints.CHANNEL_MESSAGE(channelId, id),
|
||||||
)) as DiscordMessage;
|
);
|
||||||
|
|
||||||
return structures.createDiscordenoMessage(result);
|
return await structures.createDiscordenoMessage(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
GetMessagesBefore,
|
GetMessagesBefore,
|
||||||
GetMessagesLimit,
|
GetMessagesLimit,
|
||||||
} from "../../types/messages/get_messages.ts";
|
} from "../../types/messages/get_messages.ts";
|
||||||
import { DiscordMessage } from "../../types/messages/message.ts";
|
import { Message } from "../../types/messages/message.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
@@ -26,13 +26,13 @@ export async function getMessages(
|
|||||||
|
|
||||||
if (options?.limit && options.limit > 100) return;
|
if (options?.limit && options.limit > 100) return;
|
||||||
|
|
||||||
const result = (await rest.runMethod(
|
const result = await rest.runMethod<Message[]>(
|
||||||
"get",
|
"get",
|
||||||
endpoints.CHANNEL_MESSAGES(channelId),
|
endpoints.CHANNEL_MESSAGES(channelId),
|
||||||
options,
|
options,
|
||||||
)) as DiscordMessage[];
|
);
|
||||||
|
|
||||||
return Promise.all(
|
return await Promise.all(
|
||||||
result.map((res) => structures.createDiscordenoMessage(res)),
|
result.map((res) => structures.createDiscordenoMessage(res)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { rest } from "../../rest/rest.ts";
|
import { rest } from "../../rest/rest.ts";
|
||||||
import { DiscordUser } from "../../types/users/user.ts";
|
import { GetReactions } from "../../types/messages/message_get_reactions.ts";
|
||||||
|
import { User } from "../../types/users/user.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../../util/collection.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { GetReactions } from "../../types/messages/message_get_reactions.ts";
|
|
||||||
|
|
||||||
/** Get a list of users that reacted with this emoji. */
|
/** Get a list of users that reacted with this emoji. */
|
||||||
export async function getReactions(
|
export async function getReactions(
|
||||||
@@ -11,11 +11,11 @@ export async function getReactions(
|
|||||||
reaction: string,
|
reaction: string,
|
||||||
options?: GetReactions,
|
options?: GetReactions,
|
||||||
) {
|
) {
|
||||||
const users = (await rest.runMethod(
|
const users = await rest.runMethod<User[]>(
|
||||||
"get",
|
"get",
|
||||||
endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction),
|
endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction),
|
||||||
options,
|
options,
|
||||||
)) as DiscordUser[];
|
);
|
||||||
|
|
||||||
return new Collection(users.map((user) => [user.id, user]));
|
return new Collection(users.map((user) => [user.id, user]));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,10 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
|||||||
export async function pin(channelId: string, messageId: string) {
|
export async function pin(channelId: string, messageId: string) {
|
||||||
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
|
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
|
||||||
|
|
||||||
const result = await rest.runMethod(
|
return await rest.runMethod<undefined>(
|
||||||
"put",
|
"put",
|
||||||
endpoints.CHANNEL_PIN(channelId, messageId),
|
endpoints.CHANNEL_PIN(channelId, messageId),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// aliases
|
// aliases
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import { rest } from "../../rest/rest.ts";
|
import { rest } from "../../rest/rest.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { DiscordMessage } from "../../types/messages/message.ts";
|
import { Message } from "../../types/messages/message.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** Crosspost a message in a News Channel to following channels. */
|
/** Crosspost a message in a News Channel to following channels. */
|
||||||
export async function publishMessage(channelId: string, messageId: string) {
|
export async function publishMessage(channelId: string, messageId: string) {
|
||||||
const data = (await rest.runMethod(
|
const data = await rest.runMethod<Message>(
|
||||||
"post",
|
"post",
|
||||||
endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId),
|
endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId),
|
||||||
)) as DiscordMessage;
|
);
|
||||||
|
|
||||||
return structures.createDiscordenoMessage(data);
|
return await structures.createDiscordenoMessage(data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
|||||||
export async function removeAllReactions(channelId: string, messageId: string) {
|
export async function removeAllReactions(channelId: string, messageId: string) {
|
||||||
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
|
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
|
||||||
|
|
||||||
const result = await rest.runMethod(
|
return await rest.runMethod<undefined>(
|
||||||
"delete",
|
"delete",
|
||||||
endpoints.CHANNEL_MESSAGE_REACTIONS(channelId, messageId),
|
endpoints.CHANNEL_MESSAGE_REACTIONS(channelId, messageId),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,8 @@ export async function removeReaction(
|
|||||||
reaction = reaction.substring(3, reaction.length - 1);
|
reaction = reaction.substring(3, reaction.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await rest.runMethod(
|
return await rest.runMethod<undefined>(
|
||||||
"delete",
|
"delete",
|
||||||
endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction),
|
endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,8 @@ export async function removeReactionEmoji(
|
|||||||
reaction = reaction.substring(3, reaction.length - 1);
|
reaction = reaction.substring(3, reaction.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await rest.runMethod(
|
return await rest.runMethod<undefined>(
|
||||||
"delete",
|
"delete",
|
||||||
endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction),
|
endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export async function removeUserReaction(
|
|||||||
reaction = reaction.substring(3, reaction.length - 1);
|
reaction = reaction.substring(3, reaction.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await rest.runMethod(
|
return await rest.runMethod<undefined>(
|
||||||
"delete",
|
"delete",
|
||||||
endpoints.CHANNEL_MESSAGE_REACTION_USER(
|
endpoints.CHANNEL_MESSAGE_REACTION_USER(
|
||||||
channelId,
|
channelId,
|
||||||
@@ -26,6 +26,4 @@ export async function removeUserReaction(
|
|||||||
userId,
|
userId,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { structures } from "../../structures/mod.ts";
|
|||||||
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
|
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
|
||||||
import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts";
|
import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts";
|
||||||
import { CreateMessage } from "../../types/messages/create_message.ts";
|
import { CreateMessage } from "../../types/messages/create_message.ts";
|
||||||
import { DiscordMessage } from "../../types/messages/message.ts";
|
import { DiscordMessage, Message } from "../../types/messages/message.ts";
|
||||||
import { Errors } from "../../types/misc/errors.ts";
|
import { Errors } from "../../types/misc/errors.ts";
|
||||||
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
|
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
@@ -93,7 +93,7 @@ export async function sendMessage(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = (await rest.runMethod(
|
const result = await rest.runMethod<Message>(
|
||||||
"post",
|
"post",
|
||||||
endpoints.CHANNEL_MESSAGES(channelId),
|
endpoints.CHANNEL_MESSAGES(channelId),
|
||||||
camelKeysToSnakeCase<DiscordMessage>({
|
camelKeysToSnakeCase<DiscordMessage>({
|
||||||
@@ -107,7 +107,7 @@ export async function sendMessage(
|
|||||||
}
|
}
|
||||||
: {}),
|
: {}),
|
||||||
}),
|
}),
|
||||||
)) as DiscordMessage;
|
);
|
||||||
|
|
||||||
return structures.createDiscordenoMessage(result);
|
return structures.createDiscordenoMessage(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,10 @@ export async function unpin(
|
|||||||
): Promise<undefined> {
|
): Promise<undefined> {
|
||||||
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
|
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
|
||||||
|
|
||||||
const result = await rest.runMethod(
|
return await rest.runMethod<undefined>(
|
||||||
"delete",
|
"delete",
|
||||||
endpoints.CHANNEL_PIN(channelId, messageId),
|
endpoints.CHANNEL_PIN(channelId, messageId),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// aliases
|
// aliases
|
||||||
|
|||||||
Reference in New Issue
Block a user