mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
Merge branch 'main' of https://github.com/discordeno/discordeno into main
This commit is contained in:
@@ -3,13 +3,14 @@ import { eventHandlers } from "../../bot.ts";
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import { DiscordInteraction } from "../../types/mod.ts";
|
import { DiscordGuildMemberWithUser } from "../../types/guilds/guild_member.ts";
|
||||||
|
import { DiscordInteraction } from "../../types/interactions/interaction.ts";
|
||||||
|
|
||||||
export async function handleInteractionCreate(data: DiscordGatewayPayload) {
|
export async function handleInteractionCreate(data: DiscordGatewayPayload) {
|
||||||
const payload = data.d as DiscordInteraction;
|
const payload = data.d as DiscordInteraction;
|
||||||
const discordenoMember = await structures.createDiscordenoMember(
|
const discordenoMember = await structures.createDiscordenoMember(
|
||||||
payload.member,
|
payload.member as DiscordGuildMemberWithUser,
|
||||||
payload.guild_id,
|
payload.guild_id ?? "",
|
||||||
);
|
);
|
||||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ import { eventHandlers } from "../../bot.ts";
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||||
import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts";
|
import {
|
||||||
|
DiscordGuildMemberWithUser,
|
||||||
|
GuildMemberWithUser,
|
||||||
|
} from "../../types/guilds/guild_member.ts";
|
||||||
import { DiscordMessage, Message } from "../../types/messages/message.ts";
|
import { DiscordMessage, Message } from "../../types/messages/message.ts";
|
||||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
@@ -18,7 +21,7 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
|||||||
if (payload.member && guild) {
|
if (payload.member && guild) {
|
||||||
// If in a guild cache the author as a member
|
// If in a guild cache the author as a member
|
||||||
const discordenoMember = await structures.createDiscordenoMember(
|
const discordenoMember = await structures.createDiscordenoMember(
|
||||||
{ ...payload.member, user: payload.author } as GuildMemberWithUser,
|
{ ...payload.member, user: payload.author } as DiscordGuildMemberWithUser,
|
||||||
guild.id,
|
guild.id,
|
||||||
);
|
);
|
||||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||||
@@ -28,7 +31,7 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
|||||||
// Cache the member if its a valid member
|
// Cache the member if its a valid member
|
||||||
if (mention.member && guild) {
|
if (mention.member && guild) {
|
||||||
const discordenoMember = await structures.createDiscordenoMember(
|
const discordenoMember = await structures.createDiscordenoMember(
|
||||||
{ ...mention.member, user: mention },
|
{ ...mention.member, user: mention } as DiscordGuildMemberWithUser,
|
||||||
guild.id,
|
guild.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -40,7 +43,9 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const message = await structures.createDiscordenoMessage(data.d as DiscordMessage);
|
const message = await structures.createDiscordenoMessage(
|
||||||
|
data.d as DiscordMessage,
|
||||||
|
);
|
||||||
// Cache the message
|
// Cache the message
|
||||||
await cacheHandlers.set("messages", payload.id, message);
|
await cacheHandlers.set("messages", payload.id, message);
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ 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 { DiscordChannel } from "../../types/channels/channel.ts";
|
import { DiscordChannel } from "../../types/channels/channel.ts";
|
||||||
import { CreateGuildChannel } from "../../types/guilds/create_guild_channel.ts";
|
import {
|
||||||
|
CreateGuildChannel,
|
||||||
|
DiscordCreateGuildChannel,
|
||||||
|
} from "../../types/guilds/create_guild_channel.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";
|
||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
@@ -14,14 +17,14 @@ import { calculateBits } from "../../util/permissions.ts";
|
|||||||
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
||||||
export async function createChannel(
|
export async function createChannel(
|
||||||
guildId: string,
|
guildId: string,
|
||||||
options?: CreateGuildChannel
|
options?: CreateGuildChannel,
|
||||||
) {
|
) {
|
||||||
const requiredPerms: Set<PermissionStrings> = new Set(["MANAGE_CHANNELS"]);
|
const requiredPerms: Set<PermissionStrings> = new Set(["MANAGE_CHANNELS"]);
|
||||||
|
|
||||||
options?.permissionOverwrites?.forEach((overwrite) => {
|
options?.permissionOverwrites?.forEach((overwrite) => {
|
||||||
eventHandlers.debug?.(
|
eventHandlers.debug?.(
|
||||||
"loop",
|
"loop",
|
||||||
`Running forEach loop in create_channel file.`
|
`Running forEach loop in create_channel file.`,
|
||||||
);
|
);
|
||||||
overwrite.allow.forEach(requiredPerms.add, requiredPerms);
|
overwrite.allow.forEach(requiredPerms.add, requiredPerms);
|
||||||
overwrite.deny.forEach(requiredPerms.add, requiredPerms);
|
overwrite.deny.forEach(requiredPerms.add, requiredPerms);
|
||||||
@@ -36,7 +39,7 @@ export async function createChannel(
|
|||||||
"post",
|
"post",
|
||||||
endpoints.GUILD_CHANNELS(guildId),
|
endpoints.GUILD_CHANNELS(guildId),
|
||||||
{
|
{
|
||||||
...camelKeysToSnakeCase(options),
|
...camelKeysToSnakeCase<DiscordCreateGuildChannel>(options ?? {}),
|
||||||
permission_overwrites: options?.permissionOverwrites?.map((perm) => ({
|
permission_overwrites: options?.permissionOverwrites?.map((perm) => ({
|
||||||
...perm,
|
...perm,
|
||||||
|
|
||||||
@@ -44,7 +47,7 @@ export async function createChannel(
|
|||||||
deny: calculateBits(perm.deny),
|
deny: calculateBits(perm.deny),
|
||||||
})),
|
})),
|
||||||
type: options?.type || DiscordChannelTypes.GUILD_TEXT,
|
type: options?.type || DiscordChannelTypes.GUILD_TEXT,
|
||||||
}
|
},
|
||||||
)) as DiscordChannel;
|
)) as DiscordChannel;
|
||||||
|
|
||||||
const discordenoChannel = await structures.createDiscordenoChannel(result);
|
const discordenoChannel = await structures.createDiscordenoChannel(result);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { rest } from "../../rest/rest.ts";
|
import { rest } from "../../rest/rest.ts";
|
||||||
import { ModifyWebhook } from "../../types/webhooks/modify_webhook.ts";
|
import { ModifyWebhook } from "../../types/webhooks/modify_webhook.ts";
|
||||||
import { Webhook, DiscordWebhook } from "../../types/webhooks/webhook.ts";
|
import { DiscordWebhook, Webhook } from "../../types/webhooks/webhook.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";
|
||||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
@@ -9,11 +9,11 @@ import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
|||||||
export async function editWebhook(
|
export async function editWebhook(
|
||||||
channelId: string,
|
channelId: string,
|
||||||
webhookId: string,
|
webhookId: string,
|
||||||
options: ModifyWebhook
|
options: ModifyWebhook,
|
||||||
) {
|
) {
|
||||||
await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]);
|
await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]);
|
||||||
|
|
||||||
const result = await rest.runMethod(
|
const result: DiscordWebhook = await rest.runMethod(
|
||||||
"patch",
|
"patch",
|
||||||
endpoints.WEBHOOK_ID(webhookId),
|
endpoints.WEBHOOK_ID(webhookId),
|
||||||
{
|
{
|
||||||
@@ -22,5 +22,5 @@ export async function editWebhook(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return snakeKeysToCamelCase(result as DiscordWebhook) as Webhook;
|
return snakeKeysToCamelCase<Webhook>(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export async function editWebhookMessage(
|
|||||||
webhookId: string,
|
webhookId: string,
|
||||||
webhookToken: string,
|
webhookToken: string,
|
||||||
messageId: string,
|
messageId: string,
|
||||||
options: EditWebhookMessage
|
options: EditWebhookMessage,
|
||||||
) {
|
) {
|
||||||
if (options.content && options.content.length > 2000) {
|
if (options.content && options.content.length > 2000) {
|
||||||
throw Error(Errors.MESSAGE_MAX_LENGTH);
|
throw Error(Errors.MESSAGE_MAX_LENGTH);
|
||||||
@@ -22,31 +22,39 @@ export async function editWebhookMessage(
|
|||||||
|
|
||||||
if (options.allowedMentions) {
|
if (options.allowedMentions) {
|
||||||
if (options.allowedMentions.users?.length) {
|
if (options.allowedMentions.users?.length) {
|
||||||
if (options.allowedMentions.parse.includes(DiscordAllowedMentionsTypes.UserMentions)) {
|
if (
|
||||||
|
options.allowedMentions.parse.includes(
|
||||||
|
DiscordAllowedMentionsTypes.UserMentions,
|
||||||
|
)
|
||||||
|
) {
|
||||||
options.allowedMentions.parse = options.allowedMentions.parse.filter(
|
options.allowedMentions.parse = options.allowedMentions.parse.filter(
|
||||||
(p) => p !== "users"
|
(p) => p !== "users",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.allowedMentions.users.length > 100) {
|
if (options.allowedMentions.users.length > 100) {
|
||||||
options.allowedMentions.users = options.allowedMentions.users.slice(
|
options.allowedMentions.users = options.allowedMentions.users.slice(
|
||||||
0,
|
0,
|
||||||
100
|
100,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.allowedMentions.roles?.length) {
|
if (options.allowedMentions.roles?.length) {
|
||||||
if (options.allowedMentions.parse.includes(DiscordAllowedMentionsTypes.RoleMentions)) {
|
if (
|
||||||
|
options.allowedMentions.parse.includes(
|
||||||
|
DiscordAllowedMentionsTypes.RoleMentions,
|
||||||
|
)
|
||||||
|
) {
|
||||||
options.allowedMentions.parse = options.allowedMentions.parse.filter(
|
options.allowedMentions.parse = options.allowedMentions.parse.filter(
|
||||||
(p) => p !== "roles"
|
(p) => p !== "roles",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.allowedMentions.roles.length > 100) {
|
if (options.allowedMentions.roles.length > 100) {
|
||||||
options.allowedMentions.roles = options.allowedMentions.roles.slice(
|
options.allowedMentions.roles = options.allowedMentions.roles.slice(
|
||||||
0,
|
0,
|
||||||
100
|
100,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,7 +63,7 @@ export async function editWebhookMessage(
|
|||||||
const result = (await rest.runMethod(
|
const result = (await rest.runMethod(
|
||||||
"patch",
|
"patch",
|
||||||
endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId),
|
endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId),
|
||||||
{ ...options, allowedMentions: options.allowedMentions }
|
{ ...options, allowedMentions: options.allowedMentions },
|
||||||
)) as DiscordMessage;
|
)) as DiscordMessage;
|
||||||
|
|
||||||
const message = await structures.createDiscordenoMessage(result);
|
const message = await structures.createDiscordenoMessage(result);
|
||||||
|
|||||||
Reference in New Issue
Block a user