mirror of
https://github.com/discordeno/discordeno.git
synced 2026-05-21 02:40:08 +00:00
refactor: typings using ReturnType (#2105)
* fix: check new types idea * fix: type errors * fix: new style * fix: more cleanup * fix: more cleanup * fix: cleanup audit logs * fix: cleanup stickers * fix: cleanup integrations * fix: more cleanup * fix: organize into 1 place * fix: few errors * fix: some broken import fixes * fix: quite a lot of fixes across the board * fix: more fixes for broken imports * fix: more fixes for broken imports * fix: handler imports * fix: all remaining import errors * fix: more errors needing fixes * fix: clearing up transformers * fix: few moer types * fix: more cleanup of extra types * fix: fmt * fix: cleanup discordeno file * Nuke Base Types (#2102) * fix: cleanup snake stuff * convert camelCase to snake_case (#2103) * fix: add camelize * fix: finalize remaining errors * fix: imports in test Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com>
This commit is contained in:
@@ -30,7 +30,6 @@
|
||||
"extensions": [
|
||||
"denoland.vscode-deno",
|
||||
"pkief.material-icon-theme",
|
||||
"coenraads.bracket-pair-colorizer",
|
||||
"equinusocio.vsc-material-theme",
|
||||
"tabnine.tabnine-vscode"
|
||||
],
|
||||
|
||||
161
bot.ts
161
bot.ts
@@ -1,16 +1,13 @@
|
||||
import { createRestManager, CreateRestManagerOptions } from "./rest/mod.ts";
|
||||
import { GatewayIntents } from "./types/gateway/gatewayIntents.ts";
|
||||
import { GetGatewayBot } from "./types/gateway/getGatewayBot.ts";
|
||||
import { bigintToSnowflake, snowflakeToBigint } from "./util/bigint.ts";
|
||||
import { Collection } from "./util/collection.ts";
|
||||
import {
|
||||
DiscordenoChannel,
|
||||
DiscordenoGuild,
|
||||
DiscordenoMember,
|
||||
DiscordenoMessage,
|
||||
DiscordenoRole,
|
||||
DiscordenoUser,
|
||||
DiscordenoVoiceState,
|
||||
Channel,
|
||||
Guild,
|
||||
Member,
|
||||
Message,
|
||||
Role,
|
||||
ScheduledEvent,
|
||||
transformChannel,
|
||||
transformGuild,
|
||||
transformMember,
|
||||
@@ -18,6 +15,8 @@ import {
|
||||
transformRole,
|
||||
transformUser,
|
||||
transformVoiceState,
|
||||
User,
|
||||
VoiceState,
|
||||
} from "./transformers/mod.ts";
|
||||
import {
|
||||
baseEndpoints,
|
||||
@@ -29,25 +28,21 @@ import {
|
||||
SLASH_COMMANDS_NAME_REGEX,
|
||||
USER_AGENT,
|
||||
} from "./util/constants.ts";
|
||||
import { Errors } from "./types/discordeno/errors.ts";
|
||||
import { DiscordGatewayPayload, GatewayDispatchEventNames, GatewayPayload } from "./types/gateway/gatewayPayload.ts";
|
||||
import { createGatewayManager, GatewayManager } from "./gateway/mod.ts";
|
||||
import { validateLength } from "./util/validateLength.ts";
|
||||
import { delay, formatImageURL, hasProperty } from "./util/utils.ts";
|
||||
import { iconBigintToHash, iconHashToBigInt } from "./util/hash.ts";
|
||||
import { calculateShardId } from "./util/calculateShardId.ts";
|
||||
import * as handlers from "./handlers/mod.ts";
|
||||
import { DiscordenoInteraction, transformInteraction } from "./transformers/interaction.ts";
|
||||
import { DiscordenoIntegration, transformIntegration } from "./transformers/integration.ts";
|
||||
import { Emoji } from "./types/emojis/emoji.ts";
|
||||
import { Interaction, transformInteraction } from "./transformers/interaction.ts";
|
||||
import { Integration, transformIntegration } from "./transformers/integration.ts";
|
||||
import { transformApplication } from "./transformers/application.ts";
|
||||
import { transformTeam } from "./transformers/team.ts";
|
||||
import { DiscordenoInvite, transformInvite } from "./transformers/invite.ts";
|
||||
import { Invite, transformInvite } from "./transformers/invite.ts";
|
||||
import * as helpers from "./helpers/mod.ts";
|
||||
import { DiscordenoEmoji, transformEmoji } from "./transformers/emoji.ts";
|
||||
import { Emoji, transformEmoji } from "./transformers/emoji.ts";
|
||||
import { transformActivity } from "./transformers/activity.ts";
|
||||
import { DiscordenoPresence, transformPresence } from "./transformers/presence.ts";
|
||||
import { DiscordReady } from "./types/gateway/ready.ts";
|
||||
import { PresenceUpdate, transformPresence } from "./transformers/presence.ts";
|
||||
import { urlToBase64 } from "./util/urlToBase64.ts";
|
||||
import { transformAttachment } from "./transformers/attachment.ts";
|
||||
import { transformEmbed } from "./transformers/embed.ts";
|
||||
@@ -57,8 +52,7 @@ import { transformAuditlogEntry } from "./transformers/auditlogEntry.ts";
|
||||
import { transformApplicationCommandPermission } from "./transformers/applicationCommandPermission.ts";
|
||||
import { calculateBits, calculatePermissions } from "./util/permissions.ts";
|
||||
import { transformScheduledEvent } from "./transformers/scheduledEvent.ts";
|
||||
import { DiscordenoScheduledEvent } from "./transformers/scheduledEvent.ts";
|
||||
import { DiscordenoThreadMember, transformThreadMember } from "./transformers/threadMember.ts";
|
||||
import { ThreadMember, transformThreadMember } from "./transformers/threadMember.ts";
|
||||
import { transformApplicationCommandOption } from "./transformers/applicationCommandOption.ts";
|
||||
import { transformApplicationCommand } from "./transformers/applicationCommand.ts";
|
||||
import { transformWelcomeScreen } from "./transformers/welcomeScreen.ts";
|
||||
@@ -66,7 +60,9 @@ import { transformVoiceRegion } from "./transformers/voiceRegion.ts";
|
||||
import { transformWidget } from "./transformers/widget.ts";
|
||||
import { transformStageInstance } from "./transformers/stageInstance.ts";
|
||||
import { transformSticker } from "./transformers/sticker.ts";
|
||||
import { transformGatewayBot } from "./transformers/gatewayBot.ts";
|
||||
import { GetGatewayBot, transformGatewayBot } from "./transformers/gatewayBot.ts";
|
||||
import { DiscordEmoji, DiscordGatewayPayload, DiscordReady } from "./types/discord.ts";
|
||||
import { Errors, GatewayDispatchEventNames, GatewayIntents } from "./types/shared.ts";
|
||||
|
||||
export function createBot(options: CreateBotOptions): Bot {
|
||||
const bot = {
|
||||
@@ -160,7 +156,6 @@ export function createEventHandlers(
|
||||
voiceServerUpdate: events.voiceServerUpdate ?? ignore,
|
||||
voiceStateUpdate: events.voiceStateUpdate ?? ignore,
|
||||
channelCreate: events.channelCreate ?? ignore,
|
||||
voiceChannelLeave: events.voiceChannelLeave ?? ignore,
|
||||
channelDelete: events.channelDelete ?? ignore,
|
||||
channelPinsUpdate: events.channelPinsUpdate ?? ignore,
|
||||
channelUpdate: events.channelUpdate ?? ignore,
|
||||
@@ -297,8 +292,8 @@ export function createHelpers(
|
||||
...createBaseHelpers(customHelpers || {}),
|
||||
})
|
||||
) {
|
||||
// @ts-ignore - TODO: make the types better
|
||||
converted[name as keyof FinalHelpers] = (
|
||||
// @ts-ignore - TODO: make the types better
|
||||
...args: RemoveFirstFromTuple<Parameters<typeof fun>>
|
||||
) =>
|
||||
// @ts-ignore - TODO: make the types better
|
||||
@@ -394,21 +389,21 @@ export type RestManager = ReturnType<typeof createRestManager>;
|
||||
|
||||
export interface EventHandlers {
|
||||
debug: (text: string, ...args: any[]) => unknown;
|
||||
threadCreate: (bot: Bot, thread: DiscordenoChannel) => unknown;
|
||||
threadDelete: (bot: Bot, thread: DiscordenoChannel) => unknown;
|
||||
threadCreate: (bot: Bot, thread: Channel) => unknown;
|
||||
threadDelete: (bot: Bot, thread: Channel) => unknown;
|
||||
threadMembersUpdate: (
|
||||
bot: Bot,
|
||||
payload: {
|
||||
id: bigint;
|
||||
guildId: bigint;
|
||||
addedMembers?: DiscordenoThreadMember[];
|
||||
addedMembers?: ThreadMember[];
|
||||
removedMemberIds?: bigint[];
|
||||
},
|
||||
) => unknown;
|
||||
threadUpdate: (bot: Bot, thread: DiscordenoChannel) => unknown;
|
||||
scheduledEventCreate: (bot: Bot, event: DiscordenoScheduledEvent) => unknown;
|
||||
scheduledEventUpdate: (bot: Bot, event: DiscordenoScheduledEvent) => unknown;
|
||||
scheduledEventDelete: (bot: Bot, event: DiscordenoScheduledEvent) => unknown;
|
||||
threadUpdate: (bot: Bot, thread: Channel) => unknown;
|
||||
scheduledEventCreate: (bot: Bot, event: ScheduledEvent) => unknown;
|
||||
scheduledEventUpdate: (bot: Bot, event: ScheduledEvent) => unknown;
|
||||
scheduledEventDelete: (bot: Bot, event: ScheduledEvent) => unknown;
|
||||
/** Sent when a user has subscribed to a guild scheduled event. EXPERIMENTAL! */
|
||||
scheduledEventUserAdd: (
|
||||
bot: Bot,
|
||||
@@ -432,7 +427,7 @@ export interface EventHandlers {
|
||||
payload: {
|
||||
shardId: number;
|
||||
v: number;
|
||||
user: DiscordenoUser;
|
||||
user: User;
|
||||
guilds: bigint[];
|
||||
sessionId: string;
|
||||
shard?: number[];
|
||||
@@ -440,14 +435,14 @@ export interface EventHandlers {
|
||||
},
|
||||
rawPayload: DiscordReady,
|
||||
) => any;
|
||||
interactionCreate: (bot: Bot, interaction: DiscordenoInteraction) => any;
|
||||
integrationCreate: (bot: Bot, integration: DiscordenoIntegration) => any;
|
||||
interactionCreate: (bot: Bot, interaction: Interaction) => any;
|
||||
integrationCreate: (bot: Bot, integration: Integration) => any;
|
||||
integrationDelete: (
|
||||
bot: Bot,
|
||||
payload: { id: bigint; guildId: bigint; applicationId?: bigint },
|
||||
) => any;
|
||||
integrationUpdate: (bot: Bot, payload: { guildId: bigint }) => any;
|
||||
inviteCreate: (bot: Bot, invite: DiscordenoInvite) => any;
|
||||
inviteCreate: (bot: Bot, invite: Invite) => any;
|
||||
inviteDelete: (
|
||||
bot: Bot,
|
||||
payload: {
|
||||
@@ -458,25 +453,25 @@ export interface EventHandlers {
|
||||
) => any;
|
||||
guildMemberAdd: (
|
||||
bot: Bot,
|
||||
member: DiscordenoMember,
|
||||
user: DiscordenoUser,
|
||||
member: Member,
|
||||
user: User,
|
||||
) => any;
|
||||
guildMemberRemove: (bot: Bot, user: DiscordenoUser, guildId: bigint) => any;
|
||||
guildMemberRemove: (bot: Bot, user: User, guildId: bigint) => any;
|
||||
guildMemberUpdate: (
|
||||
bot: Bot,
|
||||
member: DiscordenoMember,
|
||||
user: DiscordenoUser,
|
||||
member: Member,
|
||||
user: User,
|
||||
) => any;
|
||||
messageCreate: (bot: Bot, message: DiscordenoMessage) => any;
|
||||
messageCreate: (bot: Bot, message: Message) => any;
|
||||
messageDelete: (
|
||||
bot: Bot,
|
||||
payload: { id: bigint; channelId: bigint; guildId?: bigint },
|
||||
message?: DiscordenoMessage,
|
||||
message?: Message,
|
||||
) => any;
|
||||
messageUpdate: (
|
||||
bot: Bot,
|
||||
message: DiscordenoMessage,
|
||||
oldMessage?: DiscordenoMessage,
|
||||
message: Message,
|
||||
oldMessage?: Message,
|
||||
) => any;
|
||||
reactionAdd: (
|
||||
bot: Bot,
|
||||
@@ -485,8 +480,8 @@ export interface EventHandlers {
|
||||
channelId: bigint;
|
||||
messageId: bigint;
|
||||
guildId?: bigint;
|
||||
member?: DiscordenoMember;
|
||||
emoji: DiscordenoEmoji;
|
||||
member?: Member;
|
||||
emoji: Emoji;
|
||||
},
|
||||
) => any;
|
||||
reactionRemove: (
|
||||
@@ -496,7 +491,7 @@ export interface EventHandlers {
|
||||
channelId: bigint;
|
||||
messageId: bigint;
|
||||
guildId?: bigint;
|
||||
emoji: DiscordenoEmoji;
|
||||
emoji: Emoji;
|
||||
},
|
||||
) => any;
|
||||
reactionRemoveEmoji: (
|
||||
@@ -505,7 +500,7 @@ export interface EventHandlers {
|
||||
channelId: bigint;
|
||||
messageId: bigint;
|
||||
guildId?: bigint;
|
||||
emoji: DiscordenoEmoji;
|
||||
emoji: Emoji;
|
||||
},
|
||||
) => any;
|
||||
reactionRemoveAll: (
|
||||
@@ -518,8 +513,8 @@ export interface EventHandlers {
|
||||
) => any;
|
||||
presenceUpdate: (
|
||||
bot: Bot,
|
||||
presence: DiscordenoPresence,
|
||||
oldPresence?: DiscordenoPresence,
|
||||
presence: PresenceUpdate,
|
||||
oldPresence?: PresenceUpdate,
|
||||
) => any;
|
||||
voiceServerUpdate: (
|
||||
bot: Bot,
|
||||
@@ -527,41 +522,20 @@ export interface EventHandlers {
|
||||
) => any;
|
||||
voiceStateUpdate: (
|
||||
bot: Bot,
|
||||
voiceState: {
|
||||
guildId?: bigint;
|
||||
channelId?: bigint;
|
||||
userId: bigint;
|
||||
member?: DiscordenoMember;
|
||||
user?: DiscordenoUser;
|
||||
sessionId: string;
|
||||
deaf: boolean;
|
||||
mute: boolean;
|
||||
selfDeaf: boolean;
|
||||
selfMute: boolean;
|
||||
selfStream?: boolean;
|
||||
selfVideo: boolean;
|
||||
suppress: boolean;
|
||||
requestToSpeakTimestamp?: number;
|
||||
},
|
||||
voiceState: VoiceState,
|
||||
) => any;
|
||||
channelCreate: (bot: Bot, channel: DiscordenoChannel) => any;
|
||||
channelCreate: (bot: Bot, channel: Channel) => any;
|
||||
dispatchRequirements: (
|
||||
bot: Bot,
|
||||
data: GatewayPayload,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number,
|
||||
) => any;
|
||||
voiceChannelLeave: (
|
||||
bot: Bot,
|
||||
voiceState: DiscordenoVoiceState,
|
||||
guild: DiscordenoGuild,
|
||||
channel?: DiscordenoChannel,
|
||||
) => any;
|
||||
channelDelete: (bot: Bot, channel: DiscordenoChannel) => any;
|
||||
channelDelete: (bot: Bot, channel: Channel) => any;
|
||||
channelPinsUpdate: (
|
||||
bot: Bot,
|
||||
data: { guildId?: bigint; channelId: bigint; lastPinTimestamp?: number },
|
||||
) => any;
|
||||
channelUpdate: (bot: Bot, channel: DiscordenoChannel) => any;
|
||||
channelUpdate: (bot: Bot, channel: Channel) => any;
|
||||
stageInstanceCreate: (
|
||||
bot: Bot,
|
||||
data: {
|
||||
@@ -589,29 +563,28 @@ export interface EventHandlers {
|
||||
topic: string;
|
||||
},
|
||||
) => any;
|
||||
// TODO: THREADS
|
||||
guildEmojisUpdate: (
|
||||
bot: Bot,
|
||||
payload: {
|
||||
guildId: bigint;
|
||||
emojis: Collection<bigint, Emoji>;
|
||||
emojis: Collection<bigint, DiscordEmoji>;
|
||||
},
|
||||
) => any;
|
||||
guildBanAdd: (bot: Bot, user: DiscordenoUser, guildId: bigint) => any;
|
||||
guildBanRemove: (bot: Bot, user: DiscordenoUser, guildId: bigint) => any;
|
||||
guildLoaded: (bot: Bot, guild: DiscordenoGuild) => any;
|
||||
guildCreate: (bot: Bot, guild: DiscordenoGuild) => any;
|
||||
guildBanAdd: (bot: Bot, user: User, guildId: bigint) => any;
|
||||
guildBanRemove: (bot: Bot, user: User, guildId: bigint) => any;
|
||||
guildLoaded: (bot: Bot, guild: Guild) => any;
|
||||
guildCreate: (bot: Bot, guild: Guild) => any;
|
||||
guildDelete: (bot: Bot, id: bigint, shardId: number) => any;
|
||||
guildUpdate: (bot: Bot, guild: DiscordenoGuild) => any;
|
||||
raw: (bot: Bot, data: GatewayPayload, shardId: number) => any;
|
||||
roleCreate: (bot: Bot, role: DiscordenoRole) => any;
|
||||
guildUpdate: (bot: Bot, guild: Guild) => any;
|
||||
raw: (bot: Bot, data: DiscordGatewayPayload, shardId: number) => any;
|
||||
roleCreate: (bot: Bot, role: Role) => any;
|
||||
roleDelete: (bot: Bot, payload: { guildId: bigint; roleId: bigint }) => any;
|
||||
roleUpdate: (bot: Bot, role: DiscordenoRole) => any;
|
||||
roleUpdate: (bot: Bot, role: Role) => any;
|
||||
webhooksUpdate: (
|
||||
bot: Bot,
|
||||
payload: { channelId: bigint; guildId: bigint },
|
||||
) => any;
|
||||
botUpdate: (bot: Bot, user: DiscordenoUser) => any;
|
||||
botUpdate: (bot: Bot, user: User) => any;
|
||||
typingStart: (
|
||||
bot: Bot,
|
||||
payload: {
|
||||
@@ -619,7 +592,7 @@ export interface EventHandlers {
|
||||
channelId: bigint;
|
||||
userId: bigint;
|
||||
timestamp: number;
|
||||
member: DiscordenoMember | undefined;
|
||||
member: Member | undefined;
|
||||
},
|
||||
) => any;
|
||||
}
|
||||
@@ -702,7 +675,7 @@ export function createBotGatewayHandlers(
|
||||
options: Partial<BotGatewayHandlerOptions>,
|
||||
): Record<
|
||||
GatewayDispatchEventNames | "GUILD_LOADED_DD",
|
||||
(bot: Bot, data: GatewayPayload, shardId: number) => any
|
||||
(bot: Bot, data: DiscordGatewayPayload, shardId: number) => any
|
||||
> {
|
||||
return {
|
||||
// misc
|
||||
@@ -713,12 +686,12 @@ export function createBotGatewayHandlers(
|
||||
CHANNEL_PINS_UPDATE: options.CHANNEL_PINS_UPDATE ??
|
||||
handlers.handleChannelPinsUpdate,
|
||||
CHANNEL_UPDATE: options.CHANNEL_UPDATE ?? handlers.handleChannelUpdate,
|
||||
// THREAD_CREATE: options.THREAD_CREATE ?? handlers.handleThreadCreate,
|
||||
// THREAD_UPDATE: options.THREAD_UPDATE ?? handlers.handleThreadUpdate,
|
||||
// THREAD_DELETE: options.THREAD_DELETE ?? handlers.handleThreadDelete,
|
||||
// THREAD_LIST_SYNC: options.THREAD_LIST_SYNC ?? handlers.handleThreadListSync,
|
||||
// THREAD_MEMBER_UPDATE: options.THREAD_MEMBER_UPDATE ?? handlers.handleThreadMemberUpdate,
|
||||
// THREAD_MEMBERS_UPDATE: options.THREAD_MEMBERS_UPDATE ?? handlers.handleThreadMembersUpdate,
|
||||
THREAD_CREATE: options.THREAD_CREATE ?? handlers.handleThreadCreate,
|
||||
THREAD_UPDATE: options.THREAD_UPDATE ?? handlers.handleThreadUpdate,
|
||||
THREAD_DELETE: options.THREAD_DELETE ?? handlers.handleThreadDelete,
|
||||
THREAD_LIST_SYNC: options.THREAD_LIST_SYNC ?? handlers.handleThreadListSync,
|
||||
THREAD_MEMBER_UPDATE: options.THREAD_MEMBER_UPDATE ?? handlers.handleThreadMemberUpdate,
|
||||
THREAD_MEMBERS_UPDATE: options.THREAD_MEMBERS_UPDATE ?? handlers.handleThreadMembersUpdate,
|
||||
STAGE_INSTANCE_CREATE: options.STAGE_INSTANCE_CREATE ??
|
||||
handlers.handleStageInstanceCreate,
|
||||
STAGE_INSTANCE_UPDATE: options.STAGE_INSTANCE_UPDATE ??
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GatewayCloseEventCodes } from "../types/codes/gatewayCloseEventCodes.ts";
|
||||
import { GatewayCloseEventCodes } from "../types/shared.ts";
|
||||
import { GatewayManager } from "./gateway_manager.ts";
|
||||
|
||||
export function createShard(gateway: GatewayManager, shardId: number) {
|
||||
|
||||
@@ -20,9 +20,9 @@ import { prepareBuckets, spawnShards } from "./spawnShards.ts";
|
||||
import { stopGateway } from "./stopGateway.ts";
|
||||
import { tellWorkerToIdentify } from "./tellWorkerToIdentify.ts";
|
||||
import { DiscordenoShard } from "./shard.ts";
|
||||
import { GatewayIntents } from "../types/gateway/gatewayIntents.ts";
|
||||
import { StatusUpdate } from "../types/gateway/statusUpdate.ts";
|
||||
import { GatewayPayload } from "../types/gateway/gatewayPayload.ts";
|
||||
import { GatewayIntents } from "../types/shared.ts";
|
||||
import { StatusUpdate } from "../helpers/misc/editBotStatus.ts";
|
||||
import { DiscordGatewayPayload } from "../types/discord.ts";
|
||||
|
||||
/** Create a new Gateway Manager.
|
||||
*
|
||||
@@ -188,7 +188,7 @@ export interface GatewayManager {
|
||||
/** Begins heartbeating of the shard to keep it alive. */
|
||||
heartbeat: typeof heartbeat;
|
||||
/** Sends the discord payload to another server. */
|
||||
handleDiscordPayload: (gateway: GatewayManager, data: GatewayPayload, shardId: number) => any;
|
||||
handleDiscordPayload: (gateway: GatewayManager, data: DiscordGatewayPayload, shardId: number) => any;
|
||||
/** Tell the worker to begin identifying this shard */
|
||||
tellWorkerToIdentify: typeof tellWorkerToIdentify;
|
||||
/** Handle the different logs. Used for debugging. */
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { GatewayManager } from "./gateway_manager.ts";
|
||||
import { GatewayOpcodes } from "../types/codes/gatewayOpcodes.ts";
|
||||
import type { DiscordGatewayPayload } from "../types/gateway/gatewayPayload.ts";
|
||||
import type { DiscordHello } from "../types/gateway/hello.ts";
|
||||
import type { DiscordReady } from "../types/gateway/ready.ts";
|
||||
import { Guild } from "../types/guilds/guild.ts";
|
||||
import { UnavailableGuild } from "../types/guilds/unavailableGuild.ts";
|
||||
import { Message } from "../types/messages/mod.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../types/util.ts";
|
||||
import { snowflakeToBigint } from "../util/bigint.ts";
|
||||
import { delay } from "../util/utils.ts";
|
||||
import { decompressWith } from "./deps.ts";
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuild,
|
||||
DiscordHello,
|
||||
DiscordMessage,
|
||||
DiscordReady,
|
||||
DiscordUnavailableGuild,
|
||||
} from "../types/discord.ts";
|
||||
import { GatewayOpcodes } from "../types/shared.ts";
|
||||
|
||||
/** Handler for handling every message event from websocket. */
|
||||
// deno-lint-ignore no-explicit-any
|
||||
@@ -125,7 +126,7 @@ export async function handleOnMessage(gateway: GatewayManager, message: any, sha
|
||||
|
||||
// MUST HANDLE GUILD_CREATE EVENTS AS THEY ARE EXPENSIVE WITHOUT GATEWAY CACHE
|
||||
if (messageData.t === "GUILD_CREATE") {
|
||||
const id = snowflakeToBigint((messageData.d as SnakeCasedPropertiesDeep<Guild>).id);
|
||||
const id = snowflakeToBigint((messageData.d as DiscordGuild).id);
|
||||
|
||||
// SHARD RESUMED MOST LIKELY, THEY EMIT GUILD CREATES. OR GUILD BECAME AVAILABLE AGAIN
|
||||
if (gateway.cache.guildIds.has(id)) return;
|
||||
@@ -142,7 +143,7 @@ export async function handleOnMessage(gateway: GatewayManager, message: any, sha
|
||||
|
||||
// MESSAGE_UPDATE CAN SPAM FOR NO REASON USE THIS TO IGNORE
|
||||
if (messageData.t === "MESSAGE_UPDATE") {
|
||||
const payload = messageData.d as SnakeCasedPropertiesDeep<Message>;
|
||||
const payload = messageData.d as DiscordMessage;
|
||||
|
||||
const id = snowflakeToBigint(payload.id);
|
||||
const content = payload.content || "";
|
||||
@@ -161,7 +162,7 @@ export async function handleOnMessage(gateway: GatewayManager, message: any, sha
|
||||
|
||||
// MUST HANDLE GUILD_DELETE EVENTS FOR UNAVAILABLE
|
||||
if (messageData.t === "GUILD_DELETE") {
|
||||
if ((messageData.d as UnavailableGuild).unavailable) return;
|
||||
if ((messageData.d as DiscordUnavailableGuild).unavailable) return;
|
||||
}
|
||||
|
||||
// IF NO TYPE THEN THIS SHOULD NOT BE SENT FORWARD
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GatewayOpcodes } from "../types/codes/gatewayOpcodes.ts";
|
||||
import { GatewayOpcodes } from "../types/shared.ts";
|
||||
import { delay } from "../util/utils.ts";
|
||||
import { GatewayManager } from "./gateway_manager.ts";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GatewayOpcodes } from "../types/codes/gatewayOpcodes.ts";
|
||||
import { GatewayOpcodes } from "../types/shared.ts";
|
||||
import { GatewayManager } from "./gateway_manager.ts";
|
||||
|
||||
export function identify(gateway: GatewayManager, shardId: number, maxShards: number) {
|
||||
|
||||
@@ -8,7 +8,6 @@ export * from "./resharder.ts";
|
||||
export * from "./resume.ts";
|
||||
export * from "./spawnShards.ts";
|
||||
export * from "./sendShardMessage.ts";
|
||||
export * from "./startGatewayOptions.ts";
|
||||
export * from "./tellWorkerToIdentify.ts";
|
||||
export * from "./shard.ts";
|
||||
export * from "./gateway_manager.ts";
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { transformGatewayBot } from "../transformers/gatewayBot.ts";
|
||||
import { GetGatewayBot } from "../types/gateway/getGatewayBot.ts";
|
||||
import { DiscordReady } from "../types/gateway/ready.ts";
|
||||
import { GetGatewayBot, transformGatewayBot } from "../transformers/gatewayBot.ts";
|
||||
import { DiscordReady } from "../types/discord.ts";
|
||||
import { createGatewayManager, GatewayManager } from "./gateway_manager.ts";
|
||||
|
||||
/** The handler to automatically reshard when necessary. */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GatewayOpcodes } from "../types/codes/gatewayOpcodes.ts";
|
||||
import { GatewayOpcodes } from "../types/shared.ts";
|
||||
import { GatewayManager } from "./gateway_manager.ts";
|
||||
|
||||
export function resume(gateway: GatewayManager, shardId: number) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GatewayOpcodes } from "../types/codes/gatewayOpcodes.ts";
|
||||
import { GatewayOpcodes } from "../types/shared.ts";
|
||||
|
||||
export interface DiscordenoShard {
|
||||
/** The shard id number. */
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import { GatewayIntents } from "../types/gateway/gatewayIntents.ts";
|
||||
|
||||
export interface StartGatewayOptions {
|
||||
/** The bot token. */
|
||||
token: string;
|
||||
/** Whether or not to use compression for gateway payloads. */
|
||||
compress?: boolean;
|
||||
/** The intents you would like to enable. */
|
||||
intents: (GatewayIntents | keyof typeof GatewayIntents)[];
|
||||
/** The max amount of shards used for identifying. This can be useful for zero-downtime updates or resharding. */
|
||||
maxShards?: number;
|
||||
/** The first shard Id for this group of shards. */
|
||||
firstShardId: number;
|
||||
/** The last shard Id for this group. If none is provided, it will default to loading all shards. */
|
||||
lastShardId?: number;
|
||||
/** The url to forward all payloads to. */
|
||||
url: string;
|
||||
/** The amount of shards per worker. By default this is 25. Use this to spread the load from shards to different CPU cores. */
|
||||
shardsPerWorker?: number;
|
||||
/** The maximum amount of workers available. By default this is 4. Another way to think of worker is how many CPU cores does your server/machine have. */
|
||||
maxWorkers?: number;
|
||||
/** Whether or not you want to allow automated sharding. By default this is true. */
|
||||
reshard?: boolean;
|
||||
/** The authorization key that the bot http server will expect. */
|
||||
secretKey: string;
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
import type { Channel } from "../../types/channels/channel.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts";
|
||||
|
||||
export async function handleChannelCreate(bot: Bot, payload: DiscordGatewayPayload) {
|
||||
const channel = bot.transformers.channel(bot, { channel: payload.d as SnakeCasedPropertiesDeep<Channel> });
|
||||
const channel = bot.transformers.channel(bot, { channel: payload.d as DiscordChannel });
|
||||
|
||||
bot.events.channelCreate(bot, channel);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import type { Channel } from "../../types/channels/channel.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts";
|
||||
|
||||
export async function handleChannelDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<Channel>;
|
||||
const payload = data.d as DiscordChannel;
|
||||
if (!payload.guild_id) return;
|
||||
|
||||
bot.events.channelDelete(
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { ChannelPinsUpdate } from "../../types/channels/channelPinsUpdate.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordChannelPinsUpdate, DiscordGatewayPayload } from "../../types/discord.ts";
|
||||
|
||||
export async function handleChannelPinsUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<ChannelPinsUpdate>;
|
||||
const payload = data.d as DiscordChannelPinsUpdate;
|
||||
|
||||
bot.events.channelPinsUpdate(bot, {
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { Channel } from "../../types/channels/channel.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts";
|
||||
|
||||
export async function handleChannelUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<Channel>;
|
||||
const payload = data.d as DiscordChannel;
|
||||
const channel = bot.transformers.channel(bot, { channel: payload });
|
||||
|
||||
bot.events.channelUpdate(bot, channel);
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { StageInstance } from "../../types/channels/stageInstance.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordStageInstance } from "../../types/discord.ts";
|
||||
|
||||
export function handleStageInstanceCreate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<StageInstance>;
|
||||
const payload = data.d as DiscordStageInstance;
|
||||
|
||||
bot.events.stageInstanceCreate(bot, {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { StageInstance } from "../../types/channels/stageInstance.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordStageInstance } from "../../types/discord.ts";
|
||||
|
||||
export function handleStageInstanceDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<StageInstance>;
|
||||
const payload = data.d as DiscordStageInstance;
|
||||
|
||||
bot.events.stageInstanceDelete(bot, {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { StageInstance } from "../../types/channels/stageInstance.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordStageInstance } from "../../types/discord.ts";
|
||||
|
||||
export function handleStageInstanceUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<StageInstance>;
|
||||
const payload = data.d as DiscordStageInstance;
|
||||
|
||||
bot.events.stageInstanceUpdate(bot, {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts";
|
||||
|
||||
export async function handleThreadCreate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<Channel>;
|
||||
const payload = data.d as DiscordChannel;
|
||||
|
||||
bot.events.threadCreate(bot, bot.transformers.channel(bot, { channel: payload }));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts";
|
||||
|
||||
export async function handleThreadDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<Channel>;
|
||||
const payload = data.d as DiscordChannel;
|
||||
bot.events.threadDelete(bot, bot.transformers.channel(bot, { channel: payload }));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { ThreadListSync } from "../../types/channels/threads/threadListSync.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordThreadListSync } from "../../types/discord.ts";
|
||||
|
||||
export async function handleThreadListSync(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<ThreadListSync>;
|
||||
const payload = data.d as DiscordThreadListSync;
|
||||
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id);
|
||||
return {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { ThreadMembersUpdate } from "../../types/channels/threads/threadMembersUpdate.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordThreadMembersUpdate } from "../../types/discord.ts";
|
||||
|
||||
export async function handleThreadMembersUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<ThreadMembersUpdate>;
|
||||
const payload = data.d as DiscordThreadMembersUpdate;
|
||||
bot.events.threadMembersUpdate(bot, {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/discord.ts";
|
||||
|
||||
export async function handleThreadMemberUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
// This event is documented for completeness, but unlikely to be used by most bots
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordChannel, DiscordGatewayPayload } from "../../types/discord.ts";
|
||||
|
||||
export async function handleThreadUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<Channel>;
|
||||
const payload = data.d as DiscordChannel;
|
||||
|
||||
bot.events.threadUpdate(bot, bot.transformers.channel(bot, { channel: payload }));
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { GuildEmojisUpdate } from "../../types/emojis/guildEmojisUpdate.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildEmojisUpdate } from "../../types/discord.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
|
||||
export async function handleGuildEmojisUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<GuildEmojisUpdate>;
|
||||
const payload = data.d as DiscordGuildEmojisUpdate;
|
||||
|
||||
bot.events.guildEmojisUpdate(bot, {
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { GuildBanAddRemove } from "../../types/guilds/guildBanAddRemove.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildBanAddRemove } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildBanAdd(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<GuildBanAddRemove>;
|
||||
const payload = data.d as DiscordGuildBanAddRemove;
|
||||
bot.events.guildBanAdd(bot, bot.transformers.user(bot, payload.user), bot.transformers.snowflake(payload.guild_id));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { GuildBanAddRemove } from "../../types/guilds/guildBanAddRemove.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildBanAddRemove } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildBanRemove(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<GuildBanAddRemove>;
|
||||
const payload = data.d as DiscordGuildBanAddRemove;
|
||||
|
||||
await bot.events.guildBanRemove(
|
||||
bot,
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { Guild } from "../../types/guilds/guild.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuild } from "../../types/discord.ts";
|
||||
|
||||
export function handleGuildCreate(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<Guild>;
|
||||
const payload = data.d as DiscordGuild;
|
||||
bot.events.guildCreate(bot, bot.transformers.guild(bot, { guild: payload, shardId }));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { UnavailableGuild } from "../../types/guilds/unavailableGuild.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordUnavailableGuild } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildDelete(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<UnavailableGuild>;
|
||||
const payload = data.d as DiscordUnavailableGuild;
|
||||
bot.events.guildDelete(bot, bot.transformers.snowflake(payload.id), shardId);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { GuildIntegrationsUpdate } from "../../types/integrations/guildIntegrationsUpdate.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildIntegrationsUpdate } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildIntegrationsUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<GuildIntegrationsUpdate>;
|
||||
const payload = data.d as DiscordGuildIntegrationsUpdate;
|
||||
|
||||
bot.events.integrationUpdate(bot, { guildId: bot.transformers.snowflake(payload.guild_id) });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { Guild } from "../../types/guilds/guild.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuild } from "../../types/discord.ts";
|
||||
|
||||
export function handleGuildLoaded(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<Guild>;
|
||||
const payload = data.d as DiscordGuild;
|
||||
|
||||
const guild = bot.transformers.guild(bot, { guild: payload, shardId });
|
||||
bot.events.guildLoaded(bot, guild);
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { Guild } from "../../types/guilds/guild.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuild } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<Guild>;
|
||||
const payload = data.d as DiscordGuild;
|
||||
|
||||
bot.events.guildUpdate(bot, bot.transformers.guild(bot, { guild: payload, shardId }));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { ScheduledEvent } from "../../../types/guilds/scheduledEvents.ts";
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../../types/gateway/gatewayPayload.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordScheduledEvent } from "../../../types/discord.ts";
|
||||
|
||||
export function handleGuildScheduledEventCreate(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<ScheduledEvent>;
|
||||
const payload = data.d as DiscordScheduledEvent;
|
||||
bot.events.scheduledEventCreate(bot, bot.transformers.scheduledEvent(bot, payload));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { ScheduledEvent } from "../../../types/guilds/scheduledEvents.ts";
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../../types/gateway/gatewayPayload.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordScheduledEvent } from "../../../types/discord.ts";
|
||||
|
||||
export function handleGuildScheduledEventDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<ScheduledEvent>;
|
||||
const payload = data.d as DiscordScheduledEvent;
|
||||
bot.events.scheduledEventDelete(bot, bot.transformers.scheduledEvent(bot, payload));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { ScheduledEvent } from "../../../types/guilds/scheduledEvents.ts";
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../../types/gateway/gatewayPayload.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordScheduledEvent } from "../../../types/discord.ts";
|
||||
|
||||
export function handleGuildScheduledEventUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<ScheduledEvent>;
|
||||
const payload = data.d as DiscordScheduledEvent;
|
||||
bot.events.scheduledEventUpdate(bot, bot.transformers.scheduledEvent(bot, payload));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../../types/gateway/gatewayPayload.ts";
|
||||
import { ScheduledEventUserAdd } from "../../../types/guilds/scheduledEvents.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordScheduledEventUserAdd } from "../../../types/discord.ts";
|
||||
|
||||
export function handleGuildScheduledEventUserAdd(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<ScheduledEventUserAdd>;
|
||||
const payload = data.d as DiscordScheduledEventUserAdd;
|
||||
|
||||
return bot.events.scheduledEventUserAdd(bot, {
|
||||
guildScheduledEventId: bot.transformers.snowflake(payload.guild_scheduled_event_id),
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../../types/gateway/gatewayPayload.ts";
|
||||
import { ScheduledEventUserRemove } from "../../../types/guilds/scheduledEvents.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordScheduledEventUserRemove } from "../../../types/discord.ts";
|
||||
|
||||
export function handleGuildScheduledEventUserRemove(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<ScheduledEventUserRemove>;
|
||||
const payload = data.d as DiscordScheduledEventUserRemove;
|
||||
|
||||
return bot.events.scheduledEventUserRemove(bot, {
|
||||
guildScheduledEventId: bot.transformers.snowflake(payload.guild_scheduled_event_id),
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { IntegrationCreateUpdate } from "../../types/integrations/integrationCreateUpdate.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordIntegrationCreateUpdate } from "../../types/discord.ts";
|
||||
|
||||
export function handleIntegrationCreate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
bot.events.integrationCreate(
|
||||
bot,
|
||||
bot.transformers.integration(bot, data.d as SnakeCasedPropertiesDeep<IntegrationCreateUpdate>),
|
||||
bot.transformers.integration(bot, data.d as DiscordIntegrationCreateUpdate),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { IntegrationDelete } from "../../types/integrations/integrationDelete.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordIntegrationDelete } from "../../types/discord.ts";
|
||||
|
||||
export function handleIntegrationDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<IntegrationDelete>;
|
||||
const payload = data.d as DiscordIntegrationDelete;
|
||||
|
||||
bot.events.integrationDelete(bot, {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { IntegrationCreateUpdate } from "../../types/integrations/integrationCreateUpdate.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordIntegrationCreateUpdate } from "../../types/discord.ts";
|
||||
|
||||
export function handleIntegrationUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
bot.events.integrationUpdate(
|
||||
bot,
|
||||
bot.transformers.integration(bot, data.d as SnakeCasedPropertiesDeep<IntegrationCreateUpdate>),
|
||||
bot.transformers.integration(bot, data.d as DiscordIntegrationCreateUpdate),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { Interaction } from "../../types/interactions/interaction.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordInteraction } from "../../types/discord.ts";
|
||||
|
||||
export async function handleInteractionCreate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
bot.cache.unrepliedInteractions.add(bot.transformers.snowflake((data.d as SnakeCasedPropertiesDeep<Interaction>).id));
|
||||
bot.events.interactionCreate(bot, bot.transformers.interaction(bot, data.d as SnakeCasedPropertiesDeep<Interaction>));
|
||||
bot.cache.unrepliedInteractions.add(bot.transformers.snowflake((data.d as DiscordInteraction).id));
|
||||
bot.events.interactionCreate(bot, bot.transformers.interaction(bot, data.d as DiscordInteraction));
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { InviteCreate } from "../../types/invites/inviteCreate.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordInviteCreate } from "../../types/discord.ts";
|
||||
|
||||
export function handleInviteCreate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
bot.events.inviteCreate(bot, bot.transformers.invite(bot, data.d as SnakeCasedPropertiesDeep<InviteCreate>));
|
||||
bot.events.inviteCreate(bot, bot.transformers.invite(bot, data.d as DiscordInviteCreate));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { InviteDelete } from "../../types/invites/inviteDelete.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordInviteDelete } from "../../types/discord.ts";
|
||||
|
||||
export function handleInviteDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<InviteDelete>;
|
||||
const payload = data.d as DiscordInviteDelete;
|
||||
|
||||
bot.events.inviteDelete(bot, {
|
||||
/** The channel of the invite */
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { statusTypes } from "../../transformers/presence.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { GuildMembersChunk } from "../../types/members/guildMembersChunk.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildMembersChunk } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildMembersChunk(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<GuildMembersChunk>;
|
||||
const payload = data.d as DiscordGuildMembersChunk;
|
||||
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id);
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { GuildMemberAdd } from "../../types/members/guildMemberAdd.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildMemberAdd } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildMemberAdd(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<GuildMemberAdd>;
|
||||
const payload = data.d as DiscordGuildMemberAdd;
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id);
|
||||
const user = bot.transformers.user(bot, payload.user);
|
||||
const member = bot.transformers.member(bot, payload, guildId, user.id);
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { GuildMemberRemove } from "../../types/members/guildMemberRemove.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildMemberRemove } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildMemberRemove(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<GuildMemberRemove>;
|
||||
const payload = data.d as DiscordGuildMemberRemove;
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id);
|
||||
const user = bot.transformers.user(bot, payload.user);
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { GuildMemberUpdate } from "../../types/members/guildMemberUpdate.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildMemberUpdate } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildMemberUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<GuildMemberUpdate>;
|
||||
const payload = data.d as DiscordGuildMemberUpdate;
|
||||
|
||||
const user = bot.transformers.user(bot, payload.user);
|
||||
bot.events.guildMemberUpdate(
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { Message } from "../../types/messages/message.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordMessage } from "../../types/discord.ts";
|
||||
|
||||
export async function handleMessageCreate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<Message>;
|
||||
const payload = data.d as DiscordMessage;
|
||||
|
||||
bot.events.messageCreate(bot, bot.transformers.message(bot, payload));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { MessageDelete } from "../../types/messages/messageDelete.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordMessageDelete } from "../../types/discord.ts";
|
||||
|
||||
export async function handleMessageDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<MessageDelete>;
|
||||
const payload = data.d as DiscordMessageDelete;
|
||||
|
||||
bot.events.messageDelete(bot, {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { MessageDeleteBulk } from "../../types/messages/messageDeleteBulk.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordMessageDeleteBulk } from "../../types/discord.ts";
|
||||
|
||||
export async function handleMessageDeleteBulk(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<MessageDeleteBulk>;
|
||||
const payload = data.d as DiscordMessageDeleteBulk;
|
||||
|
||||
return {
|
||||
ids: payload.ids.map((id) => bot.transformers.snowflake(id)),
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { MessageReactionAdd } from "../../types/messages/messageReactionAdd.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordMessageReactionAdd } from "../../types/discord.ts";
|
||||
|
||||
export async function handleMessageReactionAdd(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<MessageReactionAdd>;
|
||||
const payload = data.d as DiscordMessageReactionAdd;
|
||||
|
||||
const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined;
|
||||
const userId = bot.transformers.snowflake(payload.user_id);
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { MessageReactionRemove } from "../../types/messages/messageReactionRemove.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordMessageReactionRemove } from "../../types/discord.ts";
|
||||
|
||||
export async function handleMessageReactionRemove(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<MessageReactionRemove>;
|
||||
const payload = data.d as DiscordMessageReactionRemove;
|
||||
|
||||
bot.events.reactionRemove(bot, {
|
||||
userId: bot.transformers.snowflake(payload.user_id),
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { MessageReactionRemoveAll } from "../../types/messages/messageReactionRemoveAll.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordMessageReactionRemoveAll } from "../../types/discord.ts";
|
||||
|
||||
export async function handleMessageReactionRemoveAll(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<MessageReactionRemoveAll>;
|
||||
const payload = data.d as DiscordMessageReactionRemoveAll;
|
||||
|
||||
bot.events.reactionRemoveAll(bot, {
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { MessageReactionRemoveEmoji } from "../../types/messages/messageReactionRemoveEmoji.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordMessageReactionRemoveEmoji } from "../../types/discord.ts";
|
||||
|
||||
export async function handleMessageReactionRemoveEmoji(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<MessageReactionRemoveEmoji>;
|
||||
const payload = data.d as DiscordMessageReactionRemoveEmoji;
|
||||
|
||||
bot.events.reactionRemoveEmoji(bot, {
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { Message } from "../../types/messages/message.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordMessage } from "../../types/discord.ts";
|
||||
|
||||
export async function handleMessageUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<Message>;
|
||||
const payload = data.d as DiscordMessage;
|
||||
if (!payload.edited_timestamp) return;
|
||||
|
||||
bot.events.messageUpdate(bot, bot.transformers.message(bot, payload));
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { PresenceUpdate } from "../../types/activity/presenceUpdate.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordPresenceUpdate } from "../../types/discord.ts";
|
||||
|
||||
export async function handlePresenceUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<PresenceUpdate>;
|
||||
bot.events.presenceUpdate(bot, bot.transformers.presence(bot, payload));
|
||||
bot.events.presenceUpdate(bot, bot.transformers.presence(bot, data.d as DiscordPresenceUpdate));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { DiscordReady } from "../../types/gateway/ready.ts";
|
||||
import { DiscordGatewayPayload, DiscordReady } from "../../types/discord.ts";
|
||||
|
||||
export function handleReady(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as DiscordReady;
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { TypingStart } from "../../types/misc/typingStart.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordTypingStart } from "../../types/discord.ts";
|
||||
|
||||
export function handleTypingStart(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<TypingStart>;
|
||||
const payload = data.d as DiscordTypingStart;
|
||||
|
||||
const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined;
|
||||
const userId = bot.transformers.snowflake(payload.user_id);
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { User } from "../../types/users/user.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordUser } from "../../types/discord.ts";
|
||||
|
||||
export async function handleUserUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<User>;
|
||||
const payload = data.d as DiscordUser;
|
||||
bot.events.botUpdate(bot, bot.transformers.user(bot, payload));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { GuildRoleCreate } from "../../types/guilds/guildRoleCreate.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildRoleCreate } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildRoleCreate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<GuildRoleCreate>;
|
||||
const payload = data.d as DiscordGuildRoleCreate;
|
||||
bot.events.roleCreate(
|
||||
bot,
|
||||
bot.transformers.role(bot, { role: payload.role, guildId: bot.transformers.snowflake(payload.guild_id) }),
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { GuildRoleDelete } from "../../types/guilds/guildRoleDelete.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildRoleDelete } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildRoleDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<GuildRoleDelete>;
|
||||
const payload = data.d as DiscordGuildRoleDelete;
|
||||
bot.events.roleDelete(bot, {
|
||||
roleId: bot.transformers.snowflake(payload.role_id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { GuildRoleUpdate } from "../../types/guilds/guildRoleUpdate.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuildRoleUpdate } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildRoleUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<GuildRoleUpdate>;
|
||||
const payload = data.d as DiscordGuildRoleUpdate;
|
||||
|
||||
bot.events.roleUpdate(
|
||||
bot,
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { VoiceServerUpdate } from "../../types/voice/voiceServerUpdate.ts";
|
||||
import { DiscordGatewayPayload, DiscordVoiceServerUpdate } from "../../types/discord.ts";
|
||||
|
||||
export async function handleVoiceServerUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<VoiceServerUpdate>;
|
||||
const payload = data.d as DiscordVoiceServerUpdate;
|
||||
|
||||
bot.events.voiceServerUpdate(bot, {
|
||||
token: payload.token,
|
||||
|
||||
@@ -1,31 +1,11 @@
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { VoiceState } from "../../types/voice/voiceState.ts";
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordVoiceState } from "../../types/discord.ts";
|
||||
|
||||
export async function handleVoiceStateUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<VoiceState>;
|
||||
const payload = data.d as DiscordVoiceState;
|
||||
if (!payload.guild_id) return;
|
||||
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id);
|
||||
const userId = bot.transformers.snowflake(payload.user_id);
|
||||
|
||||
bot.events.voiceStateUpdate(bot, {
|
||||
guildId,
|
||||
userId,
|
||||
channelId: payload.channel_id ? bot.transformers.snowflake(payload.channel_id) : undefined,
|
||||
member: payload.member ? bot.transformers.member(bot, payload.member, guildId, userId) : undefined,
|
||||
user: payload.member ? bot.transformers.user(bot, payload.member.user) : undefined,
|
||||
sessionId: payload.session_id,
|
||||
deaf: payload.deaf,
|
||||
mute: payload.mute,
|
||||
selfDeaf: payload.self_deaf,
|
||||
selfMute: payload.self_mute,
|
||||
selfStream: payload.self_stream,
|
||||
selfVideo: payload.self_video,
|
||||
suppress: payload.suppress,
|
||||
requestToSpeakTimestamp: payload.request_to_speak_timestamp
|
||||
? Date.parse(payload.request_to_speak_timestamp)
|
||||
: undefined,
|
||||
});
|
||||
bot.events.voiceStateUpdate(bot, bot.transformers.voiceState(bot, { voiceState: payload, guildId }));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts";
|
||||
import type { WebhookUpdate } from "../../types/webhooks/webhooksUpdate.ts";
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordGatewayPayload, DiscordWebhookUpdate } from "../../types/discord.ts";
|
||||
|
||||
export function handleWebhooksUpdate(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<WebhookUpdate>;
|
||||
const payload = data.d as DiscordWebhookUpdate;
|
||||
bot.events.webhooksUpdate(bot, {
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import type { Channel } from "../../types/channels/channel.ts";
|
||||
import { ChannelTypes } from "../../types/channels/channelTypes.ts";
|
||||
import type { CreateGuildChannel } from "../../types/guilds/createGuildChannel.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { ChannelTypes } from "../../types/shared.ts";
|
||||
import { DiscordChannel } from "../../types/discord.ts";
|
||||
import { OverwriteReadable } from "./editChannelOverwrite.ts";
|
||||
|
||||
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
||||
export async function createChannel(bot: Bot, guildId: bigint, options?: CreateGuildChannel, reason?: string) {
|
||||
// BITRATES ARE IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000
|
||||
if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000;
|
||||
|
||||
const result = await bot.rest.runMethod<Channel>(
|
||||
const result = await bot.rest.runMethod<DiscordChannel>(
|
||||
bot.rest,
|
||||
"post",
|
||||
bot.constants.endpoints.GUILD_CHANNELS(guildId),
|
||||
@@ -36,3 +36,26 @@ export async function createChannel(bot: Bot, guildId: bigint, options?: CreateG
|
||||
|
||||
return bot.transformers.channel(bot, { channel: result, guildId });
|
||||
}
|
||||
|
||||
export interface CreateGuildChannel {
|
||||
/** Channel name (1-100 characters) */
|
||||
name: string;
|
||||
/** The type of channel */
|
||||
type?: ChannelTypes;
|
||||
/** Channel topic (0-1024 characters) */
|
||||
topic?: string;
|
||||
/** The bitrate (in bits) of the voice channel (voice only) */
|
||||
bitrate?: number;
|
||||
/** The user limit of the voice channel (voice only) */
|
||||
userLimit?: number;
|
||||
/** Amount of seconds a user has to wait before sending another message (0-21600); bots, as well as users with the permission `manage_messages` or `manage_channel`, are unaffected */
|
||||
rateLimitPerUser?: number;
|
||||
/** Sorting position of the channel */
|
||||
position?: number;
|
||||
/** The channel's permission overwrites */
|
||||
permissionOverwrites?: OverwriteReadable[];
|
||||
/** Id of the parent category for a channel */
|
||||
parentId?: bigint;
|
||||
/** Whether the channel is nsfw */
|
||||
nsfw?: boolean;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import type { StageInstance } from "../../types/channels/stageInstance.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordStageInstance } from "../../types/discord.ts";
|
||||
|
||||
/** Creates a new Stage instance associated to a Stage channel. Requires the user to be a moderator of the Stage channel. */
|
||||
export async function createStageInstance(bot: Bot, channelId: bigint, topic: string) {
|
||||
const result = await bot.rest.runMethod<StageInstance>(bot.rest, "post", bot.constants.endpoints.STAGE_INSTANCES, {
|
||||
channel_id: channelId.toString(),
|
||||
topic,
|
||||
});
|
||||
const result = await bot.rest.runMethod<DiscordStageInstance>(
|
||||
bot.rest,
|
||||
"post",
|
||||
bot.constants.endpoints.STAGE_INSTANCES,
|
||||
{
|
||||
channel_id: channelId.toString(),
|
||||
topic,
|
||||
},
|
||||
);
|
||||
|
||||
return bot.transformers.stageInstance(bot, result);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordChannel } from "../../types/discord.ts";
|
||||
|
||||
/** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. Bot needs MANAGE_THREADS permissions in the server if deleting thread. */
|
||||
export async function deleteChannel(bot: Bot, channelId: bigint, reason?: string) {
|
||||
await bot.rest.runMethod<Channel>(
|
||||
await bot.rest.runMethod<DiscordChannel>(
|
||||
bot.rest,
|
||||
"delete",
|
||||
bot.constants.endpoints.CHANNEL_BASE(channelId),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { Channel } from "../../types/channels/channel.ts";
|
||||
import type { ModifyChannel } from "../../types/channels/modifyChannel.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordenoChannel } from "../../transformers/channel.ts";
|
||||
import { Channel } from "../../transformers/channel.ts";
|
||||
import { DiscordChannel } from "../../types/discord.ts";
|
||||
import { ChannelTypes, VideoQualityModes } from "../../types/shared.ts";
|
||||
import { OverwriteReadable } from "./editChannelOverwrite.ts";
|
||||
|
||||
/** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */
|
||||
export async function editChannel(bot: Bot, channelId: bigint, options: ModifyChannel, reason?: string) {
|
||||
@@ -21,7 +22,7 @@ export async function editChannel(bot: Bot, channelId: bigint, options: ModifyCh
|
||||
request.amount = 2;
|
||||
request.timestamp = Date.now() + 600000;
|
||||
} else {
|
||||
return new Promise<DiscordenoChannel>((resolve, reject) => {
|
||||
return new Promise<Channel>((resolve, reject) => {
|
||||
// 2 have already been used add to queue
|
||||
request.items.push({ channelId, options, resolve, reject });
|
||||
if (editChannelProcessing) return;
|
||||
@@ -31,30 +32,35 @@ export async function editChannel(bot: Bot, channelId: bigint, options: ModifyCh
|
||||
}
|
||||
}
|
||||
|
||||
const result = await bot.rest.runMethod<Channel>(bot.rest, "patch", bot.constants.endpoints.CHANNEL_BASE(channelId), {
|
||||
name: options.name,
|
||||
topic: options.topic,
|
||||
bitrate: options.bitrate,
|
||||
user_limit: options.userLimit,
|
||||
rate_limit_per_user: options.rateLimitPerUser,
|
||||
position: options.position,
|
||||
parent_id: options.parentId === null ? null : options.parentId?.toString(),
|
||||
nsfw: options.nsfw,
|
||||
type: options.type,
|
||||
archived: options.archived,
|
||||
auto_archive_duration: options.autoArchiveDuration,
|
||||
locked: options.locked,
|
||||
invitable: options.invitable,
|
||||
permission_overwrites: options.permissionOverwrites
|
||||
? options.permissionOverwrites?.map((overwrite) => ({
|
||||
id: overwrite.id.toString(),
|
||||
type: overwrite.type,
|
||||
allow: overwrite.allow ? bot.utils.calculateBits(overwrite.allow) : null,
|
||||
deny: overwrite.deny ? bot.utils.calculateBits(overwrite.deny) : null,
|
||||
}))
|
||||
: undefined,
|
||||
reason,
|
||||
});
|
||||
const result = await bot.rest.runMethod<DiscordChannel>(
|
||||
bot.rest,
|
||||
"patch",
|
||||
bot.constants.endpoints.CHANNEL_BASE(channelId),
|
||||
{
|
||||
name: options.name,
|
||||
topic: options.topic,
|
||||
bitrate: options.bitrate,
|
||||
user_limit: options.userLimit,
|
||||
rate_limit_per_user: options.rateLimitPerUser,
|
||||
position: options.position,
|
||||
parent_id: options.parentId === null ? null : options.parentId?.toString(),
|
||||
nsfw: options.nsfw,
|
||||
type: options.type,
|
||||
archived: options.archived,
|
||||
auto_archive_duration: options.autoArchiveDuration,
|
||||
locked: options.locked,
|
||||
invitable: options.invitable,
|
||||
permission_overwrites: options.permissionOverwrites
|
||||
? options.permissionOverwrites?.map((overwrite) => ({
|
||||
id: overwrite.id.toString(),
|
||||
type: overwrite.type,
|
||||
allow: overwrite.allow ? bot.utils.calculateBits(overwrite.allow) : null,
|
||||
deny: overwrite.deny ? bot.utils.calculateBits(overwrite.deny) : null,
|
||||
}))
|
||||
: undefined,
|
||||
reason,
|
||||
},
|
||||
);
|
||||
|
||||
return bot.transformers.channel(bot, { channel: result, guildId: bot.transformers.snowflake(result.guild_id!) });
|
||||
}
|
||||
@@ -66,7 +72,7 @@ interface EditChannelRequest {
|
||||
items: {
|
||||
channelId: bigint;
|
||||
options: ModifyChannel;
|
||||
resolve: (channel: DiscordenoChannel) => void;
|
||||
resolve: (channel: Channel) => void;
|
||||
// deno-lint-ignore no-explicit-any
|
||||
reject: (error: any) => void;
|
||||
}[];
|
||||
@@ -115,3 +121,38 @@ function processEditChannelQueue(bot: Bot) {
|
||||
editChannelProcessing = false;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ModifyChannel {
|
||||
/** 1-100 character channel name */
|
||||
name?: string;
|
||||
/** The type of channel; only conversion between text and news is supported and only in guilds with the "NEWS" feature */
|
||||
type?: ChannelTypes;
|
||||
/** The position of the channel in the left-hand listing */
|
||||
position?: number | null;
|
||||
/** 0-1024 character channel topic */
|
||||
topic?: string | null;
|
||||
/** Whether the channel is nsfw */
|
||||
nsfw?: boolean | null;
|
||||
/** Amount of seconds a user has to wait before sending another message (0-21600); bots, as well as users with the permission `manage_messages` or `manage_channel`, are unaffected */
|
||||
rateLimitPerUser?: number | null;
|
||||
/** The bitrate (in bits) of the voice channel; 8000 to 96000 (128000 for VIP servers) */
|
||||
bitrate?: number | null;
|
||||
/** The user limit of the voice channel; 0 refers to no limit, 1 to 99 refers to a user limit */
|
||||
userLimit?: number | null;
|
||||
/** Channel or category-specific permissions */
|
||||
permissionOverwrites?: OverwriteReadable[] | null;
|
||||
/** Id of the new parent category for a channel */
|
||||
parentId?: bigint | null;
|
||||
/** Voice region id for the voice channel, automatic when set to null */
|
||||
rtcRegion?: string | null;
|
||||
/** The camera video quality mode of the voice channel */
|
||||
videoQualityMode?: VideoQualityModes;
|
||||
/** Whether the thread is archived */
|
||||
archived?: boolean;
|
||||
/** Duration in minutes to automatically archive the thread after recent activity */
|
||||
autoArchiveDuration?: 60 | 1440 | 4320 | 10080;
|
||||
/** When a thread is locked, only users with `MANAGE_THREADS` can unarchive it */
|
||||
locked?: boolean;
|
||||
/** whether non-moderators can add other non-moderators to a thread; only available on private threads */
|
||||
invitable?: boolean;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,42 @@
|
||||
import type { Overwrite } from "../../types/channels/overwrite.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { OverwriteTypes, PermissionStrings } from "../../types/shared.ts";
|
||||
|
||||
/** Edit the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */
|
||||
export async function editChannelOverwrite(
|
||||
bot: Bot,
|
||||
channelId: bigint,
|
||||
overwriteId: bigint,
|
||||
options: Omit<Overwrite, "id">,
|
||||
overwrite: OverwriteReadable,
|
||||
) {
|
||||
await bot.rest.runMethod<undefined>(
|
||||
bot.rest,
|
||||
"put",
|
||||
bot.constants.endpoints.CHANNEL_OVERWRITE(channelId, overwriteId),
|
||||
bot.constants.endpoints.CHANNEL_OVERWRITE(channelId, overwrite.id),
|
||||
{
|
||||
allow: options.allow ? bot.utils.calculateBits(options.allow) : "0",
|
||||
deny: options.deny ? bot.utils.calculateBits(options.deny) : "0",
|
||||
type: options.type,
|
||||
allow: overwrite.allow ? bot.utils.calculateBits(overwrite.allow) : "0",
|
||||
deny: overwrite.deny ? bot.utils.calculateBits(overwrite.deny) : "0",
|
||||
type: overwrite.type,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export interface OverwriteReadable {
|
||||
/** Role or user id */
|
||||
id: bigint;
|
||||
/** Either 0 (role) or 1 (member) */
|
||||
type: OverwriteTypes;
|
||||
/** Permission bit set */
|
||||
allow?: PermissionStrings[];
|
||||
/** Permission bit set */
|
||||
deny?: PermissionStrings[];
|
||||
}
|
||||
|
||||
export interface Overwrite {
|
||||
/** Role or user id */
|
||||
id: bigint;
|
||||
/** Either 0 (role) or 1 (member) */
|
||||
type: OverwriteTypes;
|
||||
/** Permission bit set */
|
||||
allow?: bigint;
|
||||
/** Permission bit set */
|
||||
deny?: bigint;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { FollowedChannel } from "../../types/channels/followedChannel.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordFollowedChannel } from "../../types/discord.ts";
|
||||
|
||||
/** Follow a News Channel to send messages to a target channel. Requires the `MANAGE_WEBHOOKS` permission in the target channel. Returns the webhook id. */
|
||||
export async function followChannel(bot: Bot, sourceChannelId: bigint, targetChannelId: bigint) {
|
||||
const data = await bot.rest.runMethod<FollowedChannel>(
|
||||
const data = await bot.rest.runMethod<DiscordFollowedChannel>(
|
||||
bot.rest,
|
||||
"post",
|
||||
bot.constants.endpoints.CHANNEL_FOLLOW(sourceChannelId),
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { Channel } from "../../types/channels/channel.ts";
|
||||
import { DiscordChannel } from "../../types/discord.ts";
|
||||
|
||||
/** Fetches a single channel object from the api. */
|
||||
export async function getChannel(bot: Bot, channelId: bigint) {
|
||||
const result = await bot.rest.runMethod<Channel>(bot.rest, "get", bot.constants.endpoints.CHANNEL_BASE(channelId));
|
||||
const result = await bot.rest.runMethod<DiscordChannel>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.CHANNEL_BASE(channelId),
|
||||
);
|
||||
|
||||
return bot.transformers.channel(bot, {
|
||||
channel: result,
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import type { Webhook } from "../../types/webhooks/webhook.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordWebhook } from "../../types/discord.ts";
|
||||
|
||||
/** Gets the webhooks for this channel. Requires MANAGE_WEBHOOKS */
|
||||
export async function getChannelWebhooks(bot: Bot, channelId: bigint) {
|
||||
const result = await bot.rest.runMethod<Webhook[]>(
|
||||
const result = await bot.rest.runMethod<DiscordWebhook[]>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.CHANNEL_WEBHOOKS(channelId),
|
||||
);
|
||||
|
||||
return new Collection(result.map((webhook) => [webhook.id, webhook]));
|
||||
return new Collection(result.map((hook) => {
|
||||
const webhook = bot.transformers.webhook(bot, hook);
|
||||
return [webhook.id, webhook];
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import type { Channel } from "../../types/channels/channel.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordChannel } from "../../types/discord.ts";
|
||||
|
||||
/** Returns a list of guild channel objects. */
|
||||
export async function getChannels(bot: Bot, guildId: bigint) {
|
||||
const result = await bot.rest.runMethod<Channel[]>(bot.rest, "get", bot.constants.endpoints.GUILD_CHANNELS(guildId));
|
||||
const result = await bot.rest.runMethod<DiscordChannel[]>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.GUILD_CHANNELS(guildId),
|
||||
);
|
||||
|
||||
return new Collection(
|
||||
result.map((res) => bot.transformers.channel(bot, { channel: res, guildId })).map((c) => [c.id, c]),
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import type { Message } from "../../types/messages/message.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordMessage } from "../../types/discord.ts";
|
||||
|
||||
/** Get pinned messages in this channel. */
|
||||
export async function getPins(bot: Bot, channelId: bigint) {
|
||||
const result = await bot.rest.runMethod<Message[]>(bot.rest, "get", bot.constants.endpoints.CHANNEL_PINS(channelId));
|
||||
const result = await bot.rest.runMethod<DiscordMessage[]>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.CHANNEL_PINS(channelId),
|
||||
);
|
||||
|
||||
return result.map((msg) => bot.transformers.message(bot, msg));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { StageInstance } from "../../types/channels/stageInstance.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordStageInstance } from "../../types/discord.ts";
|
||||
|
||||
/** Gets the stage instance associated with the Stage channel, if it exists. */
|
||||
export async function getStageInstance(bot: Bot, channelId: bigint) {
|
||||
const result = await bot.rest.runMethod<StageInstance>(
|
||||
const result = await bot.rest.runMethod<DiscordStageInstance>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.STAGE_INSTANCE(channelId),
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { ModifyGuildChannelPositions } from "../../types/guilds/modifyGuildChannelPosition.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permission. Only channels to be modified are required. */
|
||||
@@ -21,3 +20,15 @@ export async function swapChannels(bot: Bot, guildId: bigint, channelPositions:
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/guild#modify-guild-channel-positions */
|
||||
export interface ModifyGuildChannelPositions {
|
||||
/** Channel id */
|
||||
id: string;
|
||||
/** Sorting position of the channel */
|
||||
position: number | null;
|
||||
/** Syncs the permission overwrites with the new parent, if moving to a new category */
|
||||
lockPositions?: boolean | null;
|
||||
/** The new parent ID for the channel that is moved */
|
||||
parentId?: string | null;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import type { ListActiveThreads } from "../../../types/channels/threads/listActiveThreads.ts";
|
||||
import { DiscordListActiveThreads } from "../../../types/discord.ts";
|
||||
import { Collection } from "../../../util/collection.ts";
|
||||
// import { channelToThread } from "../../../util/transformers/channel_to_thread.ts";
|
||||
|
||||
/** Returns all active threads in the guild, including public and private threads. Threads are ordered by their `id`, in descending order. */
|
||||
export async function getActiveThreads(bot: Bot, guildId: bigint) {
|
||||
const result = await bot.rest.runMethod<ListActiveThreads>(
|
||||
const result = await bot.rest.runMethod<DiscordListActiveThreads>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.THREAD_ACTIVE(guildId),
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { ListActiveThreads } from "../../../types/channels/threads/listActiveThreads.ts";
|
||||
import { ListPublicArchivedThreads } from "../../../types/channels/threads/listPublicArchivedThreads.ts";
|
||||
import { Collection } from "../../../util/collection.ts";
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { DiscordListActiveThreads } from "../../../types/discord.ts";
|
||||
|
||||
/** Get the archived threads for this channel, defaults to public */
|
||||
export async function getArchivedThreads(
|
||||
@@ -11,7 +10,7 @@ export async function getArchivedThreads(
|
||||
type?: "public" | "private" | "privateJoinedThreads";
|
||||
},
|
||||
) {
|
||||
const result = (await bot.rest.runMethod<ListActiveThreads>(
|
||||
const result = (await bot.rest.runMethod<DiscordListActiveThreads>(
|
||||
bot.rest,
|
||||
"get",
|
||||
options?.type === "privateJoinedThreads"
|
||||
@@ -43,3 +42,12 @@ export async function getArchivedThreads(
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: add docs link
|
||||
export interface ListPublicArchivedThreads {
|
||||
// TODO: convert unix to ISO9601 timestamp
|
||||
/** Returns threads before this timestamp. UNIX or ISO8601 timestamp */
|
||||
before?: number | string;
|
||||
/** Optional maximum number of threads to return */
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { ThreadMember } from "../../../types/channels/threads/threadMember.ts";
|
||||
import { DiscordThreadMember } from "../../../types/discord.ts";
|
||||
|
||||
/** Returns thread members objects that are members of the thread. */
|
||||
export async function getThreadMember(bot: Bot, threadId: bigint, userId: bigint) {
|
||||
const result = await bot.rest.runMethod<ThreadMember>(
|
||||
const result = await bot.rest.runMethod<DiscordThreadMember>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.THREAD_USER(threadId, userId),
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { ThreadMember } from "../../../types/channels/threads/threadMember.ts";
|
||||
import { DiscordThreadMember } from "../../../types/discord.ts";
|
||||
import { Collection } from "../../../util/collection.ts";
|
||||
|
||||
/** Returns thread members objects that are members of the thread. */
|
||||
export async function getThreadMembers(bot: Bot, threadId: bigint) {
|
||||
const result = await bot.rest.runMethod<ThreadMember[]>(
|
||||
const result = await bot.rest.runMethod<DiscordThreadMember[]>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.THREAD_MEMBERS(threadId),
|
||||
);
|
||||
return result;
|
||||
// return result;
|
||||
|
||||
// return new Collection(result.map((res) => [bot.transformers.snowflake(result.userId), {
|
||||
// id?: string;
|
||||
// /** The id of the user */
|
||||
// userId?: string;
|
||||
// /** The time the current user last joined the thread */
|
||||
// joinTimestamp: string;
|
||||
// }]));
|
||||
return new Collection(result.map((res) => {
|
||||
const member = bot.transformers.threadMember(bot, res);
|
||||
return [member.id, member];
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
import type { Channel } from "../../../types/channels/channel.ts";
|
||||
import type { StartThreadBase } from "../../../types/channels/threads/startThread.ts";
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { DiscordChannel } from "../../../types/discord.ts";
|
||||
|
||||
/** Creates a new public thread from an existing message. Returns a thread channel. */
|
||||
export async function startThreadWithMessage(
|
||||
bot: Bot,
|
||||
channelId: bigint,
|
||||
messageId: bigint,
|
||||
options: StartThreadBase,
|
||||
options: StartThreadWithMessage,
|
||||
) {
|
||||
const result = await bot.rest.runMethod<Channel>(
|
||||
const result = await bot.rest.runMethod<DiscordChannel>(
|
||||
bot.rest,
|
||||
"post",
|
||||
bot.constants.endpoints.THREAD_START_PUBLIC(channelId, messageId),
|
||||
@@ -21,3 +20,14 @@ export async function startThreadWithMessage(
|
||||
|
||||
return bot.transformers.channel(bot, { channel: result, guildId: bot.transformers.snowflake(result.guild_id!) });
|
||||
}
|
||||
|
||||
export interface StartThreadWithMessage {
|
||||
/** 1-100 character thread name */
|
||||
name: string;
|
||||
/** Duration in minutes to automatically archive the thread after recent activity */
|
||||
autoArchiveDuration: 60 | 1440 | 4320 | 10080;
|
||||
/** Amount of seconds a user has to wait before sending another message (0-21600) */
|
||||
rateLimitPerUser?: number | null;
|
||||
/** The reason you are creating the thread */
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { Channel } from "../../../types/channels/channel.ts";
|
||||
import type { StartThreadWithoutMessage } from "../../../types/channels/threads/startThread.ts";
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { DiscordChannel } from "../../../types/discord.ts";
|
||||
import { ChannelTypes } from "../../../types/shared.ts";
|
||||
|
||||
/** Creates a new private thread. Returns a thread channel. */
|
||||
export async function startThreadWithoutMessage(bot: Bot, channelId: bigint, options: StartThreadWithoutMessage) {
|
||||
const result = await bot.rest.runMethod<Channel>(
|
||||
const result = await bot.rest.runMethod<DiscordChannel>(
|
||||
bot.rest,
|
||||
"post",
|
||||
bot.constants.endpoints.THREAD_START_PRIVATE(channelId),
|
||||
@@ -19,3 +19,18 @@ export async function startThreadWithoutMessage(bot: Bot, channelId: bigint, opt
|
||||
guildId: result.guild_id ? bot.transformers.snowflake(result.guild_id) : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
export interface StartThreadWithoutMessage {
|
||||
/** 1-100 character thread name */
|
||||
name: string;
|
||||
/** Duration in minutes to automatically archive the thread after recent activity */
|
||||
autoArchiveDuration: 60 | 1440 | 4320 | 10080;
|
||||
/** Amount of seconds a user has to wait before sending another message (0-21600) */
|
||||
rateLimitPerUser?: number | null;
|
||||
/** The reason you are creating the thread */
|
||||
reason?: string;
|
||||
/** the type of thread to create */
|
||||
type: ChannelTypes.GuildNewsThread | ChannelTypes.GuildPublicThread | ChannelTypes.GuildPrivateThread;
|
||||
/** whether non-moderators can add other non-moderators to a thread; only available when creating a private thread */
|
||||
invitable?: boolean;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import type { StageInstance } from "../../types/channels/stageInstance.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { AtLeastOne } from "../../types/util.ts";
|
||||
import { DiscordStageInstance } from "../../types/discord.ts";
|
||||
import { AtLeastOne } from "../../types/shared.ts";
|
||||
|
||||
/** Updates fields of an existing Stage instance. Requires the user to be a moderator of the Stage channel. */
|
||||
export async function updateStageInstance(bot: Bot, channelId: bigint, data: AtLeastOne<Pick<StageInstance, "topic">>) {
|
||||
const result = await bot.rest.runMethod<StageInstance>(
|
||||
export async function updateStageInstance(
|
||||
bot: Bot,
|
||||
channelId: bigint,
|
||||
data: AtLeastOne<Pick<DiscordStageInstance, "topic">>,
|
||||
) {
|
||||
const result = await bot.rest.runMethod<DiscordStageInstance>(
|
||||
bot.rest,
|
||||
"patch",
|
||||
bot.constants.endpoints.STAGE_INSTANCE(channelId),
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import type { UpdateOthersVoiceState } from "../../types/guilds/updateOthersVoiceState.ts";
|
||||
import type { UpdateSelfVoiceState } from "../../types/guilds/updateSelfVoiceState.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/**
|
||||
@@ -45,3 +43,23 @@ export async function updateUserVoiceState(bot: Bot, guildId: bigint, options: U
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/guild#update-current-user-voice-state */
|
||||
export interface UpdateSelfVoiceState {
|
||||
/** The id of the channel the user is currently in */
|
||||
channelId: bigint;
|
||||
/** Toggles the user's suppress state */
|
||||
suppress?: boolean;
|
||||
/** Sets the user's request to speak */
|
||||
requestToSpeakTimestamp?: number | null;
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/guild#update-user-voice-state */
|
||||
export interface UpdateOthersVoiceState {
|
||||
/** The id of the channel the user is currently in */
|
||||
channelId: bigint;
|
||||
/** Toggles the user's suppress state */
|
||||
suppress?: boolean;
|
||||
/** The user id to target */
|
||||
userId: bigint;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { AddGuildDiscoverySubcategory } from "../../types/discovery/addGuildDiscoverySubcategory.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordAddGuildDiscoverySubcategory } from "../../types/discord.ts";
|
||||
|
||||
/** Add a discovery subcategory to the guild. Requires the `MANAGE_GUILD` permission. */
|
||||
export async function addDiscoverySubcategory(bot: Bot, guildId: bigint, categoryId: number) {
|
||||
await bot.rest.runMethod<AddGuildDiscoverySubcategory>(
|
||||
await bot.rest.runMethod<DiscordAddGuildDiscoverySubcategory>(
|
||||
bot.rest,
|
||||
"post",
|
||||
bot.constants.endpoints.DISCOVERY_SUBCATEGORY(guildId, categoryId),
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import type { DiscoveryMetadata } from "../../types/discovery/discoveryMetadata.ts";
|
||||
import type { ModifyGuildDiscoveryMetadata } from "../../types/discovery/modifyGuildDiscoveryMetadata.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordDiscoveryMetadata } from "../../types/discord.ts";
|
||||
|
||||
/** Modify the discovery metadata for the guild. Requires the MANAGE_GUILD permission. Returns the updated discovery metadata object on success. */
|
||||
export async function editDiscovery(bot: Bot, guildId: bigint, data: ModifyGuildDiscoveryMetadata) {
|
||||
const result = await bot.rest.runMethod<DiscoveryMetadata>(
|
||||
const result = await bot.rest.runMethod<DiscordDiscoveryMetadata>(
|
||||
bot.rest,
|
||||
"patch",
|
||||
bot.constants.endpoints.DISCOVERY_METADATA(guildId),
|
||||
@@ -29,3 +28,13 @@ export async function editDiscovery(bot: Bot, guildId: bigint, data: ModifyGuild
|
||||
categoryIds: result.category_ids,
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: add docs link
|
||||
export interface ModifyGuildDiscoveryMetadata {
|
||||
/** The id of the primary discovery category. Default: 0 */
|
||||
primaryCategoryId?: number | null;
|
||||
/** Up to 10 discovery search kekywords. Default: null */
|
||||
keywords?: string[] | null;
|
||||
/** Whether guild info is shown when custom emojis are clicked. Default: true */
|
||||
emojiDiscoverabilityEnabled?: boolean | null;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { DiscoveryMetadata } from "../../types/discovery/discoveryMetadata.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordDiscoveryMetadata } from "../../types/discord.ts";
|
||||
|
||||
/** Returns the discovery metadata object for the guild. Requires the `MANAGE_GUILD` permission. */
|
||||
export async function getDiscovery(bot: Bot, guildId: bigint) {
|
||||
const result = await bot.rest.runMethod<DiscoveryMetadata>(
|
||||
const result = await bot.rest.runMethod<DiscordDiscoveryMetadata>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.DISCOVERY_METADATA(guildId),
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import type { DiscoveryCategory } from "../../types/discovery/discoveryCategory.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
import { DiscordDiscoveryCategory } from "../../types/discord.ts";
|
||||
|
||||
/** Returns a Collection (mapped by Id of the discovery category object) of discovery category objects that can be used when editing guilds */
|
||||
export async function getDiscoveryCategories(bot: Bot) {
|
||||
const result = await bot.rest.runMethod<DiscoveryCategory[]>(
|
||||
const result = await bot.rest.runMethod<DiscordDiscoveryCategory[]>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.DISCOVERY_CATEGORIES,
|
||||
);
|
||||
|
||||
return new Collection<number, SnakeCasedPropertiesDeep<DiscoveryCategory>>(
|
||||
return new Collection<number, DiscordDiscoveryCategory>(
|
||||
result.map((category) => [category.id, category]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { ValidateDiscoverySearchTerm } from "../../types/discovery/validateDiscoverySearchTerm.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordValidateDiscoverySearchTerm } from "../../types/discord.ts";
|
||||
|
||||
export async function validDiscoveryTerm(bot: Bot, term: string) {
|
||||
const result = await bot.rest.runMethod<ValidateDiscoverySearchTerm>(
|
||||
const result = await bot.rest.runMethod<DiscordValidateDiscoverySearchTerm>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.DISCOVERY_VALID_TERM,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { CreateGuildEmoji } from "../../types/emojis/createGuildEmoji.ts";
|
||||
import type { Emoji } from "../../types/emojis/emoji.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordEmoji } from "../../types/discord.ts";
|
||||
|
||||
/** Create an emoji in the server. Emojis and animated emojis have a maximum file size of 256kb. Attempting to upload an emoji larger than this limit will fail and return 400 Bad Request and an error message, but not a JSON status code. If a URL is provided to the image parameter, Discordeno will automatically convert it to a base64 string internally. */
|
||||
export async function createEmoji(bot: Bot, guildId: bigint, options: CreateGuildEmoji) {
|
||||
@@ -8,15 +7,32 @@ export async function createEmoji(bot: Bot, guildId: bigint, options: CreateGuil
|
||||
options.image = await bot.utils.urlToBase64(options.image);
|
||||
}
|
||||
|
||||
const emoji = await bot.rest.runMethod<Emoji>(bot.rest, "post", bot.constants.endpoints.GUILD_EMOJIS(guildId), {
|
||||
name: options.name,
|
||||
image: options.image,
|
||||
roles: options.roles?.map((role) => role.toString()),
|
||||
reason: options.reason,
|
||||
});
|
||||
const emoji = await bot.rest.runMethod<DiscordEmoji>(
|
||||
bot.rest,
|
||||
"post",
|
||||
bot.constants.endpoints.GUILD_EMOJIS(guildId),
|
||||
{
|
||||
name: options.name,
|
||||
image: options.image,
|
||||
roles: options.roles?.map((role) => role.toString()),
|
||||
reason: options.reason,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...emoji,
|
||||
id: bot.transformers.snowflake(emoji.id!),
|
||||
};
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/emoji#create-guild-emoji */
|
||||
export interface CreateGuildEmoji {
|
||||
/** Name of the emoji */
|
||||
name: string;
|
||||
/** The 128x128 emoji image */
|
||||
image: string;
|
||||
/** Roles allowed to use this emoji */
|
||||
roles?: bigint[];
|
||||
/** The reason you are creating this emoji */
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,26 @@
|
||||
import type { Emoji } from "../../types/emojis/emoji.ts";
|
||||
import type { ModifyGuildEmoji } from "../../types/emojis/modifyGuildEmoji.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordEmoji } from "../../types/discord.ts";
|
||||
|
||||
/** Modify the given emoji. Requires the MANAGE_EMOJIS permission. */
|
||||
export async function editEmoji(bot: Bot, guildId: bigint, id: bigint, options: ModifyGuildEmoji) {
|
||||
const result = await bot.rest.runMethod<Emoji>(bot.rest, "patch", bot.constants.endpoints.GUILD_EMOJI(guildId, id), {
|
||||
name: options.name,
|
||||
roles: options.roles?.map((role) => role.toString()),
|
||||
});
|
||||
const result = await bot.rest.runMethod<DiscordEmoji>(
|
||||
bot.rest,
|
||||
"patch",
|
||||
bot.constants.endpoints.GUILD_EMOJI(guildId, id),
|
||||
{
|
||||
name: options.name,
|
||||
// NEED TERNARY TO SUPPORT NULL AS VALID
|
||||
roles: options.roles ? options.roles.map((role) => role.toString()) : options.roles,
|
||||
},
|
||||
);
|
||||
|
||||
return bot.transformers.emoji(bot, result);
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/emoji#modify-guild-emoji */
|
||||
export interface ModifyGuildEmoji {
|
||||
/** Name of the emoji */
|
||||
name?: string;
|
||||
/** Roles allowed to use this emoji */
|
||||
roles?: bigint[] | null;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { Emoji } from "../../types/emojis/emoji.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordEmoji } from "../../types/discord.ts";
|
||||
|
||||
/**
|
||||
* Returns an emoji for the given guild and emoji Id.
|
||||
*/
|
||||
export async function getEmoji(bot: Bot, guildId: bigint, emojiId: bigint) {
|
||||
const result = await bot.rest.runMethod<Emoji>(
|
||||
const result = await bot.rest.runMethod<DiscordEmoji>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.GUILD_EMOJI(guildId, emojiId),
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { Emoji } from "../../types/emojis/emoji.ts";
|
||||
import { DiscordEmoji } from "../../types/discord.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
|
||||
/**
|
||||
* Returns a list of emojis for the given guild.
|
||||
*/
|
||||
export async function getEmojis(bot: Bot, guildId: bigint) {
|
||||
const result = await bot.rest.runMethod<Emoji[]>(bot.rest, "get", bot.constants.endpoints.GUILD_EMOJIS(guildId));
|
||||
const result = await bot.rest.runMethod<DiscordEmoji[]>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.GUILD_EMOJIS(guildId),
|
||||
);
|
||||
|
||||
return new Collection(result.map((e) => [bot.transformers.snowflake(e.id!), bot.transformers.emoji(bot, e)]));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import type { CreateGuild } from "../../types/guilds/createGuild.ts";
|
||||
import type { Guild } from "../../types/guilds/guild.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { Channel } from "../../transformers/channel.ts";
|
||||
import { Role } from "../../transformers/role.ts";
|
||||
import { DiscordGuild } from "../../types/discord.ts";
|
||||
import {
|
||||
DefaultMessageNotificationLevels,
|
||||
ExplicitContentFilterLevels,
|
||||
SystemChannelFlags,
|
||||
VerificationLevels,
|
||||
} from "../../types/shared.ts";
|
||||
|
||||
/** Create a new guild. Returns a guild object on success. Fires a Guild Create Gateway event. This endpoint can be used only by bots in less than 10 guilds. */
|
||||
export async function createGuild(bot: Bot, options: CreateGuild) {
|
||||
const result = await bot.rest.runMethod<Guild>(bot.rest, "post", bot.constants.endpoints.GUILDS, {
|
||||
const result = await bot.rest.runMethod<DiscordGuild>(bot.rest, "post", bot.constants.endpoints.GUILDS, {
|
||||
name: options.name,
|
||||
afk_channel_id: options.afkChannelId,
|
||||
afk_timeout: options.afkTimeout,
|
||||
@@ -20,3 +27,29 @@ export async function createGuild(bot: Bot, options: CreateGuild) {
|
||||
|
||||
return bot.transformers.guild(bot, { guild: result, shardId: 0 });
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/guild#create-guild */
|
||||
export interface CreateGuild {
|
||||
/** Name of the guild (1-100 characters) */
|
||||
name: string;
|
||||
/** Base64 128x128 image for the guild icon */
|
||||
icon?: string;
|
||||
/** Verification level */
|
||||
verificationLevel?: VerificationLevels;
|
||||
/** Default message notification level */
|
||||
defaultMessageNotifications?: DefaultMessageNotificationLevels;
|
||||
/** Explicit content filter level */
|
||||
explicitContentFilter?: ExplicitContentFilterLevels;
|
||||
/** New guild roles (first role is the everyone role) */
|
||||
roles?: Role[];
|
||||
/** New guild's channels */
|
||||
channels?: Partial<Channel>[];
|
||||
/** Id for afk channel */
|
||||
afkChannelId?: string;
|
||||
/** Afk timeout in seconds */
|
||||
afkTimeout?: number;
|
||||
/** The id of the channel where guild notices such as welcome messages and boost events are posted */
|
||||
systemChannelId?: string;
|
||||
/** System channel flags */
|
||||
systemChannelFlags?: SystemChannelFlags;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { Guild } from "../../types/guilds/guild.ts";
|
||||
import type { ModifyGuild } from "../../types/guilds/modifyGuild.ts";
|
||||
import { DiscordGuild } from "../../types/discord.ts";
|
||||
import {
|
||||
DefaultMessageNotificationLevels,
|
||||
ExplicitContentFilterLevels,
|
||||
GuildFeatures,
|
||||
SystemChannelFlags,
|
||||
VerificationLevels,
|
||||
} from "../../types/shared.ts";
|
||||
|
||||
/** Modify a guilds settings. Requires the MANAGE_GUILD permission. */
|
||||
export async function editGuild(bot: Bot, guildId: bigint, options: ModifyGuild, shardId: number) {
|
||||
@@ -16,7 +22,7 @@ export async function editGuild(bot: Bot, guildId: bigint, options: ModifyGuild,
|
||||
options.splash = await bot.utils.urlToBase64(options.splash);
|
||||
}
|
||||
|
||||
const result = await bot.rest.runMethod<Guild>(
|
||||
const result = await bot.rest.runMethod<DiscordGuild>(
|
||||
bot.rest,
|
||||
"patch",
|
||||
bot.constants.endpoints.GUILDS_BASE(guildId),
|
||||
@@ -28,3 +34,43 @@ export async function editGuild(bot: Bot, guildId: bigint, options: ModifyGuild,
|
||||
shardId,
|
||||
});
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/guild#modify-guild */
|
||||
export interface ModifyGuild {
|
||||
/** Guild name */
|
||||
name?: string;
|
||||
/** Verification level */
|
||||
verificationLevel?: VerificationLevels | null;
|
||||
/** Default message notification filter level */
|
||||
defaultMessageNotifications?: DefaultMessageNotificationLevels | null;
|
||||
/** Explicit content filter level */
|
||||
explicitContentFilter?: ExplicitContentFilterLevels | null;
|
||||
/** Id for afk channel */
|
||||
afkChannelId?: bigint | null;
|
||||
/** Afk timeout in seconds */
|
||||
afkTimeout?: number;
|
||||
/** Base64 1024x1024 png/jpeg/gif image for the guild icon (can be animated gif when the server has the `ANIMATED_ICON` feature) */
|
||||
icon?: string | null;
|
||||
/** User id to transfer guild ownership to (must be owner) */
|
||||
ownerId?: bigint;
|
||||
/** Base64 16:9 png/jpeg image for the guild splash (when the server has `INVITE_SPLASH` feature) */
|
||||
splash?: string | null;
|
||||
/** Base64 16:9 png/jpeg image for the guild discovery spash (when the server has the `DISCOVERABLE` feature) */
|
||||
discoverySplash?: string | null;
|
||||
/** Base64 16:9 png/jpeg image for the guild banner (when the server has BANNER feature) */
|
||||
banner?: string | null;
|
||||
/** The id of the channel where guild notices such as welcome messages and boost events are posted */
|
||||
systemChannelId?: bigint | null;
|
||||
/** System channel flags */
|
||||
systemChannelFlags?: SystemChannelFlags;
|
||||
/** The id of the channel where Community guilds display rules and/or guidelines */
|
||||
rulesChannelId?: bigint | null;
|
||||
/** The id of the channel where admins and moderators of Community guilds receive notices from Discord */
|
||||
publicUpdatesChannelId?: bigint | null;
|
||||
/** The preferred locale of a Community guild used in server discovery and notices from Discord; defaults to "en-US" */
|
||||
preferredLocale?: string | null;
|
||||
/** Enabled guild features */
|
||||
features?: GuildFeatures[];
|
||||
/** Whether the guild's boost progress bar should be enabled */
|
||||
premiumProgressBarEnabled?: boolean;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import type { ModifyGuildWelcomeScreen } from "../../types/guilds/modifyGuildWelcomeScreen.ts";
|
||||
import type { WelcomeScreen } from "../../types/guilds/welcomeScreen.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordWelcomeScreen } from "../../types/discord.ts";
|
||||
|
||||
export async function editWelcomeScreen(bot: Bot, guildId: bigint, options: ModifyGuildWelcomeScreen) {
|
||||
const result = await bot.rest.runMethod<WelcomeScreen>(
|
||||
const result = await bot.rest.runMethod<DiscordWelcomeScreen>(
|
||||
bot.rest,
|
||||
"patch",
|
||||
bot.constants.endpoints.GUILD_WELCOME_SCREEN(guildId),
|
||||
@@ -21,3 +20,24 @@ export async function editWelcomeScreen(bot: Bot, guildId: bigint, options: Modi
|
||||
|
||||
return bot.transformers.welcomeScreen(bot, result);
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/guild#modify-guild-welcome-screen */
|
||||
export interface ModifyGuildWelcomeScreen {
|
||||
/** Whether the welcome screen is enabled */
|
||||
enabled?: boolean | null;
|
||||
/** Channels linked in the welcome screen and their display options */
|
||||
welcomeScreen?: WelcomeScreenChannel[] | null;
|
||||
/** The server description to show in the welcome screen */
|
||||
description?: string | null;
|
||||
}
|
||||
|
||||
export interface WelcomeScreenChannel {
|
||||
/** The channel's id */
|
||||
channelId: bigint;
|
||||
/** The emoji id, if the emoji is custom */
|
||||
emojiId?: bigint;
|
||||
/** The emoji name if custom, the unicode character if standard, or `null` if no emoji is set */
|
||||
emojiName?: string;
|
||||
/** The description shown for the channel */
|
||||
description: string;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { GuildWidget } from "../../types/guilds/guildWidget.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordGuildWidget } from "../../types/discord.ts";
|
||||
|
||||
/** Modify a guild widget object for the guild. Requires the MANAGE_GUILD permission. */
|
||||
export async function editWidget(bot: Bot, guildId: bigint, enabled: boolean, channelId?: string | null) {
|
||||
const result = await bot.rest.runMethod<GuildWidget>(
|
||||
const result = await bot.rest.runMethod<DiscordGuildWidget>(
|
||||
bot.rest,
|
||||
"patch",
|
||||
bot.constants.endpoints.GUILD_WIDGET(guildId),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { AuditLog } from "../../types/auditLog/auditLog.ts";
|
||||
import type { GetGuildAuditLog } from "../../types/auditLog/getGuildAuditLog.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordAuditLog } from "../../types/discord.ts";
|
||||
import { AuditLogEvents } from "../../types/shared.ts";
|
||||
|
||||
/** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */
|
||||
export async function getAuditLogs(bot: Bot, guildId: bigint, options?: GetGuildAuditLog) {
|
||||
@@ -8,7 +8,7 @@ export async function getAuditLogs(bot: Bot, guildId: bigint, options?: GetGuild
|
||||
if (options?.before) options.before = options.before.toString();
|
||||
if (options?.limit) options.limit = options.limit >= 1 && options.limit <= 100 ? options.limit : 50;
|
||||
|
||||
const auditlog = await bot.rest.runMethod<AuditLog>(
|
||||
const auditlog = await bot.rest.runMethod<DiscordAuditLog>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.GUILD_AUDIT_LOGS(guildId),
|
||||
@@ -52,3 +52,15 @@ export async function getAuditLogs(bot: Bot, guildId: bigint, options?: GetGuild
|
||||
scheduledEvents: auditlog.guild_scheduled_events?.map((event) => bot.transformers.scheduledEvent(bot, event)),
|
||||
};
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/audit-log#get-guild-audit-log-query-string-parameters */
|
||||
export interface GetGuildAuditLog {
|
||||
/** Filter the log for actions made by a user */
|
||||
userId?: bigint | string;
|
||||
/** The type of audit log event */
|
||||
actionType?: AuditLogEvents;
|
||||
/** Filter the log before a certain entry id */
|
||||
before?: bigint | string;
|
||||
/** How many entries are returned (default 50, minimum 1, maximum 100) */
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user