mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
Merge branch 'main' of https://github.com/discordeno/discordeno into main
This commit is contained in:
@@ -4,6 +4,6 @@ import { cacheHandlers } from "../../cache.ts";
|
||||
export function categoryChildren(id: string) {
|
||||
return cacheHandlers.filter(
|
||||
"channels",
|
||||
(channel) => channel.parentId === id
|
||||
(channel) => channel.parentId === id,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,14 +12,14 @@ export async function createGuild(options: CreateGuild) {
|
||||
const result = (await rest.runMethod(
|
||||
"post",
|
||||
endpoints.GUILDS,
|
||||
options
|
||||
options,
|
||||
)) as DiscordGuild;
|
||||
|
||||
const guild = await structures.createDiscordenoGuild(result, 0);
|
||||
// MANUALLY CACHE THE GUILD
|
||||
await cacheHandlers.set("guilds", guild.id, guild);
|
||||
// MANUALLY CACHE THE BOT
|
||||
await getMember(guild.id, botId)
|
||||
await getMember(guild.id, botId);
|
||||
|
||||
return guild;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { ModifyGuildIntegration } from "../../types/mod.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
@@ -6,7 +7,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
export async function editIntegration(
|
||||
guildId: string,
|
||||
id: string,
|
||||
options: EditIntegrationOptions,
|
||||
options: ModifyGuildIntegration,
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
|
||||
@@ -73,7 +73,10 @@ export async function editMember(
|
||||
endpoints.GUILD_MEMBER(guildId, memberId),
|
||||
options,
|
||||
) as DiscordGuildMember;
|
||||
const member = await structures.createDiscordenoMember(snakeKeysToCamelCase(result), guildId);
|
||||
const member = await structures.createDiscordenoMember(
|
||||
snakeKeysToCamelCase(result),
|
||||
guildId,
|
||||
);
|
||||
|
||||
return member;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
/** Edit the message. */
|
||||
export async function editMessage(
|
||||
message: Message,
|
||||
content: string | MessageContent
|
||||
content: string | MessageContent,
|
||||
) {
|
||||
if (message.author.id !== botId) {
|
||||
throw "You can only edit a message that was sent by the bot.";
|
||||
@@ -30,7 +30,7 @@ export async function editMessage(
|
||||
const result = await rest.runMethod(
|
||||
"patch",
|
||||
endpoints.CHANNEL_MESSAGE(message.channelId, message.id),
|
||||
content
|
||||
content,
|
||||
);
|
||||
|
||||
return structures.createDiscordenoMessage(result as DiscordMessage);
|
||||
|
||||
@@ -16,7 +16,7 @@ export async function getMessage(channelId: string, id: string) {
|
||||
|
||||
const result = (await rest.runMethod(
|
||||
"get",
|
||||
endpoints.CHANNEL_MESSAGE(channelId, id)
|
||||
endpoints.CHANNEL_MESSAGE(channelId, id),
|
||||
)) as DiscordMessage;
|
||||
|
||||
return structures.createDiscordenoMessage(result);
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function getMessages(
|
||||
| GetMessagesAfter
|
||||
| GetMessagesBefore
|
||||
| GetMessagesAround
|
||||
| GetMessages
|
||||
| GetMessages,
|
||||
) {
|
||||
await requireBotChannelPermissions(channelId, [
|
||||
"VIEW_CHANNEL",
|
||||
@@ -23,10 +23,10 @@ export async function getMessages(
|
||||
const result = (await rest.runMethod(
|
||||
"get",
|
||||
endpoints.CHANNEL_MESSAGES(channelId),
|
||||
options
|
||||
options,
|
||||
)) as DiscordMessage[];
|
||||
|
||||
return Promise.all(
|
||||
result.map((res) => structures.createDiscordenoMessage(res))
|
||||
result.map((res) => structures.createDiscordenoMessage(res)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function publishMessage(channelId: string, messageId: string) {
|
||||
const data = (await rest.runMethod(
|
||||
"post",
|
||||
endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId)
|
||||
endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId),
|
||||
)) as DiscordMessage;
|
||||
|
||||
return structures.createDiscordenoMessage(data);
|
||||
|
||||
@@ -14,7 +14,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
/** Send a message to the channel. Requires SEND_MESSAGES permission. */
|
||||
export async function sendMessage(
|
||||
channelId: string,
|
||||
content: string | CreateMessage
|
||||
content: string | CreateMessage,
|
||||
) {
|
||||
if (typeof content === "string") content = { content };
|
||||
|
||||
@@ -56,18 +56,18 @@ export async function sendMessage(
|
||||
if (content.allowedMentions.users?.length) {
|
||||
if (
|
||||
content.allowedMentions.parse?.includes(
|
||||
DiscordAllowedMentionsTypes.UserMentions
|
||||
DiscordAllowedMentionsTypes.UserMentions,
|
||||
)
|
||||
) {
|
||||
content.allowedMentions.parse = content.allowedMentions.parse.filter(
|
||||
(p) => p !== "users"
|
||||
(p) => p !== "users",
|
||||
);
|
||||
}
|
||||
|
||||
if (content.allowedMentions.users.length > 100) {
|
||||
content.allowedMentions.users = content.allowedMentions.users.slice(
|
||||
0,
|
||||
100
|
||||
100,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -75,18 +75,18 @@ export async function sendMessage(
|
||||
if (content.allowedMentions.roles?.length) {
|
||||
if (
|
||||
content.allowedMentions.parse?.includes(
|
||||
DiscordAllowedMentionsTypes.RoleMentions
|
||||
DiscordAllowedMentionsTypes.RoleMentions,
|
||||
)
|
||||
) {
|
||||
content.allowedMentions.parse = content.allowedMentions.parse.filter(
|
||||
(p) => p !== "roles"
|
||||
(p) => p !== "roles",
|
||||
);
|
||||
}
|
||||
|
||||
if (content.allowedMentions.roles.length > 100) {
|
||||
content.allowedMentions.roles = content.allowedMentions.roles.slice(
|
||||
0,
|
||||
100
|
||||
100,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -99,14 +99,13 @@ export async function sendMessage(
|
||||
...content,
|
||||
...(content.messageReference?.messageId
|
||||
? {
|
||||
messageReference: {
|
||||
...content.messageReference,
|
||||
failIfNotExists:
|
||||
content.messageReference.failIfNotExists === true,
|
||||
},
|
||||
}
|
||||
messageReference: {
|
||||
...content.messageReference,
|
||||
failIfNotExists: content.messageReference.failIfNotExists === true,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
})
|
||||
}),
|
||||
)) as DiscordMessage;
|
||||
|
||||
return structures.createDiscordenoMessage(result);
|
||||
|
||||
@@ -7,7 +7,7 @@ export function editBotStatus(data: Omit<StatusUpdate, "afk" | "since">) {
|
||||
ws.shards.forEach((shard) => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`Running forEach loop in editBotStatus function.`
|
||||
`Running forEach loop in editBotStatus function.`,
|
||||
);
|
||||
shard.ws.send(
|
||||
JSON.stringify({
|
||||
@@ -17,7 +17,7 @@ export function editBotStatus(data: Omit<StatusUpdate, "afk" | "since">) {
|
||||
afk: false,
|
||||
...data,
|
||||
},
|
||||
})
|
||||
}),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { DiscordGetGatewayBot, GetGatewayBot } from "../../types/gateway/get_gateway_bot.ts";
|
||||
import {
|
||||
DiscordGetGatewayBot,
|
||||
GetGatewayBot,
|
||||
} from "../../types/gateway/get_gateway_bot.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ export async function getGuildTemplates(guildId: string) {
|
||||
|
||||
const templates = (await rest.runMethod(
|
||||
"get",
|
||||
endpoints.GUILD_TEMPLATES(guildId)
|
||||
endpoints.GUILD_TEMPLATES(guildId),
|
||||
)) as DiscordTemplate[];
|
||||
|
||||
return templates.map((template) => structures.createTemplateStruct(template));
|
||||
|
||||
@@ -19,7 +19,7 @@ export async function editWebhook(
|
||||
{
|
||||
...options,
|
||||
channel_id: options.channelId,
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return snakeKeysToCamelCase<Webhook>(result);
|
||||
|
||||
@@ -10,7 +10,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function executeWebhook(
|
||||
webhookId: string,
|
||||
webhookToken: string,
|
||||
options: ExecuteWebhook
|
||||
options: ExecuteWebhook,
|
||||
) {
|
||||
if (!options.content && !options.file && !options.embeds) {
|
||||
throw new Error(Errors.INVALID_WEBHOOK_OPTIONS);
|
||||
@@ -28,18 +28,18 @@ export async function executeWebhook(
|
||||
if (options.allowedMentions.users?.length) {
|
||||
if (
|
||||
options.allowedMentions.parse.includes(
|
||||
DiscordAllowedMentionsTypes.UserMentions
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -47,18 +47,18 @@ export async function executeWebhook(
|
||||
if (options.allowedMentions.roles?.length) {
|
||||
if (
|
||||
options.allowedMentions.parse.includes(
|
||||
DiscordAllowedMentionsTypes.RoleMentions
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ export async function executeWebhook(
|
||||
...options,
|
||||
allowed_mentions: options.allowedMentions,
|
||||
avatar_url: options.avatarUrl,
|
||||
}
|
||||
},
|
||||
);
|
||||
if (!options.wait) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user