mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 17:00:08 +00:00
Fix some types
This commit is contained in:
@@ -3,13 +3,14 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.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) {
|
||||
const payload = data.d as DiscordInteraction;
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
payload.member,
|
||||
payload.guild_id,
|
||||
payload.member as DiscordGuildMemberWithUser,
|
||||
payload.guild_id ?? "",
|
||||
);
|
||||
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
|
||||
|
||||
|
||||
@@ -2,7 +2,10 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.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 { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
@@ -18,7 +21,7 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
||||
if (payload.member && guild) {
|
||||
// If in a guild cache the author as a member
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
{ ...payload.member, user: payload.author } as GuildMemberWithUser,
|
||||
{ ...payload.member, user: payload.author } as DiscordGuildMemberWithUser,
|
||||
guild.id,
|
||||
);
|
||||
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
|
||||
if (mention.member && guild) {
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
{ ...mention.member, user: mention },
|
||||
{ ...mention.member, user: mention } as DiscordGuildMemberWithUser,
|
||||
guild.id,
|
||||
);
|
||||
|
||||
@@ -40,7 +43,9 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
||||
}
|
||||
}));
|
||||
|
||||
const message = await structures.createDiscordenoMessage(payload);
|
||||
const message = await structures.createDiscordenoMessage(
|
||||
data.d as DiscordMessage,
|
||||
);
|
||||
// Cache the message
|
||||
await cacheHandlers.set("messages", payload.id, message);
|
||||
|
||||
|
||||
@@ -3,7 +3,10 @@ import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.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 { endpoints } from "../../util/constants.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. */
|
||||
export async function createChannel(
|
||||
guildId: string,
|
||||
options?: CreateGuildChannel
|
||||
options?: CreateGuildChannel,
|
||||
) {
|
||||
const requiredPerms: Set<PermissionStrings> = new Set(["MANAGE_CHANNELS"]);
|
||||
|
||||
options?.permissionOverwrites?.forEach((overwrite) => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`Running forEach loop in create_channel file.`
|
||||
`Running forEach loop in create_channel file.`,
|
||||
);
|
||||
overwrite.allow.forEach(requiredPerms.add, requiredPerms);
|
||||
overwrite.deny.forEach(requiredPerms.add, requiredPerms);
|
||||
@@ -36,7 +39,7 @@ export async function createChannel(
|
||||
"post",
|
||||
endpoints.GUILD_CHANNELS(guildId),
|
||||
{
|
||||
...camelKeysToSnakeCase(options),
|
||||
...camelKeysToSnakeCase<DiscordCreateGuildChannel>(options ?? {}),
|
||||
permission_overwrites: options?.permissionOverwrites?.map((perm) => ({
|
||||
...perm,
|
||||
|
||||
@@ -44,7 +47,7 @@ export async function createChannel(
|
||||
deny: calculateBits(perm.deny),
|
||||
})),
|
||||
type: options?.type || DiscordChannelTypes.GUILD_TEXT,
|
||||
}
|
||||
},
|
||||
)) as DiscordChannel;
|
||||
|
||||
const discordenoChannel = await structures.createDiscordenoChannel(result);
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { ModifyWebhook } from "../../types/webhooks/modify_webhook.ts";
|
||||
import { DiscordWebhook, Webhook } from "../../types/webhooks/webhook.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
/** Edit a webhook. Requires the `MANAGE_WEBHOOKS` permission. Returns the updated webhook object on success. */
|
||||
export async function editWebhook(
|
||||
channelId: string,
|
||||
webhookId: string,
|
||||
options: WebhookEditOptions,
|
||||
options: ModifyWebhook,
|
||||
) {
|
||||
await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]);
|
||||
|
||||
const result = await rest.runMethod(
|
||||
const result: DiscordWebhook = await rest.runMethod(
|
||||
"patch",
|
||||
endpoints.WEBHOOK_ID(webhookId),
|
||||
{
|
||||
@@ -19,5 +22,5 @@ export async function editWebhook(
|
||||
},
|
||||
);
|
||||
|
||||
return result as WebhookPayload;
|
||||
return snakeKeysToCamelCase<Webhook>(result);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export async function editWebhookMessage(
|
||||
webhookId: string,
|
||||
webhookToken: string,
|
||||
messageId: string,
|
||||
options: EditWebhookMessage
|
||||
options: EditWebhookMessage,
|
||||
) {
|
||||
if (options.content && options.content.length > 2000) {
|
||||
throw Error(Errors.MESSAGE_MAX_LENGTH);
|
||||
@@ -22,31 +22,39 @@ export async function editWebhookMessage(
|
||||
|
||||
if (options.allowedMentions) {
|
||||
if (options.allowedMentions.users?.length) {
|
||||
if (options.allowedMentions.parse.includes("users")) {
|
||||
if (
|
||||
options.allowedMentions.parse.includes(
|
||||
DiscordAllowedMentionsTypes.UserMentions,
|
||||
)
|
||||
) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter(
|
||||
(p) => p !== "users"
|
||||
(p) => p !== "users",
|
||||
);
|
||||
}
|
||||
|
||||
if (options.allowedMentions.users.length > 100) {
|
||||
options.allowedMentions.users = options.allowedMentions.users.slice(
|
||||
0,
|
||||
100
|
||||
100,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
(p) => p !== "roles"
|
||||
(p) => p !== "roles",
|
||||
);
|
||||
}
|
||||
|
||||
if (options.allowedMentions.roles.length > 100) {
|
||||
options.allowedMentions.roles = options.allowedMentions.roles.slice(
|
||||
0,
|
||||
100
|
||||
100,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -55,7 +63,7 @@ export async function editWebhookMessage(
|
||||
const result = (await rest.runMethod(
|
||||
"patch",
|
||||
endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId),
|
||||
{ ...options, allowedMentions: options.allowedMentions }
|
||||
{ ...options, allowedMentions: options.allowedMentions },
|
||||
)) as DiscordMessage;
|
||||
|
||||
const message = await structures.createDiscordenoMessage(result);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { ModifyWebhook } from "../../types/webhooks/modify_webhook.ts";
|
||||
import { Webhook } from "../../types/webhooks/webhook.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
@@ -7,7 +8,7 @@ import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
export async function editWebhookWithToken(
|
||||
webhookId: string,
|
||||
webhookToken: string,
|
||||
options: Omit<WebhookEditOptions, "channelId">,
|
||||
options: Omit<ModifyWebhook, "channelId">,
|
||||
) {
|
||||
const result = await rest.runMethod(
|
||||
"patch",
|
||||
|
||||
Reference in New Issue
Block a user