mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 01:10:07 +00:00
style: fix bot style
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
import { DiscordChannel, DiscordGatewayPayload } from '@discordeno/types'
|
||||
import type { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleChannelCreate (bot: Bot, payload: DiscordGatewayPayload) {
|
||||
const channel = bot.transformers.channel(bot, { channel: payload.d as DiscordChannel })
|
||||
export async function handleChannelCreate (
|
||||
bot: Bot,
|
||||
payload: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const channel = bot.transformers.channel(bot, {
|
||||
channel: payload.d as DiscordChannel
|
||||
})
|
||||
|
||||
bot.events.channelCreate(bot, channel)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { DiscordChannel, DiscordGatewayPayload } from '@discordeno/types'
|
||||
import type { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleChannelDelete (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleChannelDelete (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordChannel
|
||||
if (!payload.guild_id) return
|
||||
|
||||
@@ -9,7 +12,9 @@ export async function handleChannelDelete (bot: Bot, data: DiscordGatewayPayload
|
||||
bot,
|
||||
bot.transformers.channel(bot, {
|
||||
channel: payload,
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined
|
||||
guildId: payload.guild_id
|
||||
? bot.transformers.snowflake(payload.guild_id)
|
||||
: undefined
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
import { DiscordChannelPinsUpdate, DiscordGatewayPayload } from '@discordeno/types'
|
||||
import {
|
||||
DiscordChannelPinsUpdate,
|
||||
DiscordGatewayPayload
|
||||
} from '@discordeno/types'
|
||||
import type { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleChannelPinsUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleChannelPinsUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordChannelPinsUpdate
|
||||
|
||||
bot.events.channelPinsUpdate(bot, {
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
|
||||
guildId: payload.guild_id
|
||||
? bot.transformers.snowflake(payload.guild_id)
|
||||
: undefined,
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
lastPinTimestamp: payload.last_pin_timestamp ? Date.parse(payload.last_pin_timestamp) : undefined
|
||||
lastPinTimestamp: payload.last_pin_timestamp
|
||||
? Date.parse(payload.last_pin_timestamp)
|
||||
: undefined
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { DiscordChannel, DiscordGatewayPayload } from '@discordeno/types'
|
||||
import type { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleChannelUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleChannelUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordChannel
|
||||
const channel = bot.transformers.channel(bot, { channel: payload })
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { DiscordGatewayPayload, DiscordStageInstance } from '@discordeno/types'
|
||||
import type { Bot } from '../../bot.js'
|
||||
|
||||
export function handleStageInstanceCreate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export function handleStageInstanceCreate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
const payload = data.d as DiscordStageInstance
|
||||
|
||||
bot.events.stageInstanceCreate(bot, {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { DiscordGatewayPayload, DiscordStageInstance } from '@discordeno/types'
|
||||
import type { Bot } from '../../bot.js'
|
||||
|
||||
export function handleStageInstanceDelete (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export function handleStageInstanceDelete (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
const payload = data.d as DiscordStageInstance
|
||||
|
||||
bot.events.stageInstanceDelete(bot, {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { DiscordGatewayPayload, DiscordStageInstance } from '@discordeno/types'
|
||||
import type { Bot } from '../../bot.js'
|
||||
|
||||
export function handleStageInstanceUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export function handleStageInstanceUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
const payload = data.d as DiscordStageInstance
|
||||
|
||||
bot.events.stageInstanceUpdate(bot, {
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import { DiscordChannel, DiscordGatewayPayload } from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleThreadCreate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleThreadCreate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordChannel
|
||||
|
||||
bot.events.threadCreate(bot, bot.transformers.channel(bot, { channel: payload }))
|
||||
bot.events.threadCreate(
|
||||
bot,
|
||||
bot.transformers.channel(bot, { channel: payload })
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { DiscordChannel, DiscordGatewayPayload } from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleThreadDelete (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleThreadDelete (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordChannel
|
||||
bot.events.threadDelete(bot, bot.transformers.channel(bot, { channel: payload }))
|
||||
bot.events.threadDelete(
|
||||
bot,
|
||||
bot.transformers.channel(bot, { channel: payload })
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,17 +1,39 @@
|
||||
import { DiscordGatewayPayload, DiscordThreadListSync } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordThreadListSync
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
import { Channel } from '../../transformers/index.js'
|
||||
|
||||
export async function handleThreadListSync (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleThreadListSync (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<{
|
||||
guildId: bigint
|
||||
channelIds: bigint[] | undefined
|
||||
threads: Channel[]
|
||||
members: Array<{
|
||||
id: bigint | undefined
|
||||
userId: bigint | undefined
|
||||
joinTimestamp: number
|
||||
}>
|
||||
}> {
|
||||
const payload = data.d as DiscordThreadListSync
|
||||
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id)
|
||||
return {
|
||||
guildId,
|
||||
channelIds: payload.channel_ids?.map((id) => bot.transformers.snowflake(id)),
|
||||
threads: payload.threads.map((thread) => bot.transformers.channel(bot, { channel: thread, guildId })),
|
||||
channelIds: payload.channel_ids?.map((id) =>
|
||||
bot.transformers.snowflake(id)
|
||||
),
|
||||
threads: payload.threads.map((thread) =>
|
||||
bot.transformers.channel(bot, { channel: thread, guildId })
|
||||
),
|
||||
members: payload.members.map((member) => ({
|
||||
id: member.id ? bot.transformers.snowflake(member.id) : undefined,
|
||||
userId: member.user_id ? bot.transformers.snowflake(member.user_id) : undefined,
|
||||
userId: member.user_id
|
||||
? bot.transformers.snowflake(member.user_id)
|
||||
: undefined,
|
||||
joinTimestamp: Date.parse(member.join_timestamp)
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
import { DiscordGatewayPayload, DiscordThreadMembersUpdate } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordThreadMembersUpdate
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleThreadMembersUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleThreadMembersUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordThreadMembersUpdate
|
||||
bot.events.threadMembersUpdate(bot, {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
addedMembers: payload.added_members?.map((member) => bot.transformers.threadMember(bot, member)),
|
||||
removedMemberIds: payload.removed_member_ids?.map((id) => bot.transformers.snowflake(id))
|
||||
addedMembers: payload.added_members?.map((member) =>
|
||||
bot.transformers.threadMember(bot, member)
|
||||
),
|
||||
removedMemberIds: payload.removed_member_ids?.map((id) =>
|
||||
bot.transformers.snowflake(id)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { DiscordGatewayPayload, DiscordThreadMemberUpdate } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordThreadMemberUpdate
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleThreadMemberUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleThreadMemberUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordThreadMemberUpdate
|
||||
|
||||
bot.events.threadMemberUpdate(bot, {
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import { DiscordChannel, DiscordGatewayPayload } from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleThreadUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleThreadUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordChannel
|
||||
|
||||
bot.events.threadUpdate(bot, bot.transformers.channel(bot, { channel: payload }))
|
||||
bot.events.threadUpdate(
|
||||
bot,
|
||||
bot.transformers.channel(bot, { channel: payload })
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,23 @@
|
||||
import { DiscordGatewayPayload, DiscordGuildEmojisUpdate } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildEmojisUpdate
|
||||
} from '@discordeno/types'
|
||||
import { Collection } from '@discordeno/utils'
|
||||
import type { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleGuildEmojisUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleGuildEmojisUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildEmojisUpdate
|
||||
|
||||
bot.events.guildEmojisUpdate(bot, {
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
emojis: new Collection(payload.emojis.map((emoji) => [bot.transformers.snowflake(emoji.id!), emoji]))
|
||||
emojis: new Collection(
|
||||
payload.emojis.map((emoji) => [
|
||||
bot.transformers.snowflake(emoji.id!),
|
||||
emoji
|
||||
])
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
import { DiscordGatewayPayload, DiscordGuildBanAddRemove } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildBanAddRemove
|
||||
} from '@discordeno/types'
|
||||
import type { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleGuildBanAdd (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleGuildBanAdd (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildBanAddRemove
|
||||
bot.events.guildBanAdd(bot, bot.transformers.user(bot, payload.user), bot.transformers.snowflake(payload.guild_id))
|
||||
bot.events.guildBanAdd(
|
||||
bot,
|
||||
bot.transformers.user(bot, payload.user),
|
||||
bot.transformers.snowflake(payload.guild_id)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { DiscordGatewayPayload, DiscordGuildBanAddRemove } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildBanAddRemove
|
||||
} from '@discordeno/types'
|
||||
import type { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleGuildBanRemove (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleGuildBanRemove (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildBanAddRemove
|
||||
|
||||
await bot.events.guildBanRemove(
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
import { DiscordGatewayPayload, DiscordGuild } from '@discordeno/types'
|
||||
import type { Bot } from '../../bot.js'
|
||||
|
||||
export function handleGuildCreate (bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
export function handleGuildCreate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number
|
||||
): void {
|
||||
const payload = data.d as DiscordGuild
|
||||
bot.events.guildCreate(bot, bot.transformers.guild(bot, { guild: payload, shardId }))
|
||||
bot.events.guildCreate(
|
||||
bot,
|
||||
bot.transformers.guild(bot, { guild: payload, shardId })
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
import { DiscordGatewayPayload, DiscordUnavailableGuild } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordUnavailableGuild
|
||||
} from '@discordeno/types'
|
||||
import type { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleGuildDelete (bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
export async function handleGuildDelete (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordUnavailableGuild
|
||||
bot.events.guildDelete(bot, bot.transformers.snowflake(payload.id), shardId)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
import { DiscordGatewayPayload, DiscordGuildIntegrationsUpdate } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildIntegrationsUpdate
|
||||
} from '@discordeno/types'
|
||||
import type { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleGuildIntegrationsUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleGuildIntegrationsUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildIntegrationsUpdate
|
||||
|
||||
bot.events.integrationUpdate(bot, { guildId: bot.transformers.snowflake(payload.guild_id) })
|
||||
bot.events.integrationUpdate(bot, {
|
||||
guildId: bot.transformers.snowflake(payload.guild_id)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
import { DiscordGatewayPayload, DiscordGuild } from '@discordeno/types'
|
||||
import type { Bot } from '../../bot.js'
|
||||
|
||||
export function handleGuildUpdate (bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
export function handleGuildUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number
|
||||
): void {
|
||||
const payload = data.d as DiscordGuild
|
||||
|
||||
bot.events.guildUpdate(bot, bot.transformers.guild(bot, { guild: payload, shardId }))
|
||||
bot.events.guildUpdate(
|
||||
bot,
|
||||
bot.transformers.guild(bot, { guild: payload, shardId })
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
import { DiscordGatewayPayload, DiscordScheduledEvent } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordScheduledEvent
|
||||
} from '@discordeno/types'
|
||||
import type { Bot } from '../../../bot.js'
|
||||
|
||||
export function handleGuildScheduledEventCreate (bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
export function handleGuildScheduledEventCreate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number
|
||||
): void {
|
||||
const payload = data.d as DiscordScheduledEvent
|
||||
bot.events.scheduledEventCreate(bot, bot.transformers.scheduledEvent(bot, payload))
|
||||
bot.events.scheduledEventCreate(
|
||||
bot,
|
||||
bot.transformers.scheduledEvent(bot, payload)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
import { DiscordGatewayPayload, DiscordScheduledEvent } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordScheduledEvent
|
||||
} from '@discordeno/types'
|
||||
import type { Bot } from '../../../bot.js'
|
||||
|
||||
export function handleGuildScheduledEventDelete (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export function handleGuildScheduledEventDelete (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
const payload = data.d as DiscordScheduledEvent
|
||||
bot.events.scheduledEventDelete(bot, bot.transformers.scheduledEvent(bot, payload))
|
||||
bot.events.scheduledEventDelete(
|
||||
bot,
|
||||
bot.transformers.scheduledEvent(bot, payload)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
import { DiscordGatewayPayload, DiscordScheduledEvent } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordScheduledEvent
|
||||
} from '@discordeno/types'
|
||||
import type { Bot } from '../../../bot.js'
|
||||
|
||||
export function handleGuildScheduledEventUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export function handleGuildScheduledEventUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
const payload = data.d as DiscordScheduledEvent
|
||||
bot.events.scheduledEventUpdate(bot, bot.transformers.scheduledEvent(bot, payload))
|
||||
bot.events.scheduledEventUpdate(
|
||||
bot,
|
||||
bot.transformers.scheduledEvent(bot, payload)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
import { DiscordGatewayPayload, DiscordScheduledEventUserAdd } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordScheduledEventUserAdd
|
||||
} from '@discordeno/types'
|
||||
import type { Bot } from '../../../bot.js'
|
||||
|
||||
export function handleGuildScheduledEventUserAdd (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export function handleGuildScheduledEventUserAdd (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): unknown {
|
||||
const payload = data.d as DiscordScheduledEventUserAdd
|
||||
|
||||
return bot.events.scheduledEventUserAdd(bot, {
|
||||
guildScheduledEventId: bot.transformers.snowflake(payload.guild_scheduled_event_id),
|
||||
guildScheduledEventId: bot.transformers.snowflake(
|
||||
payload.guild_scheduled_event_id
|
||||
),
|
||||
userId: bot.transformers.snowflake(payload.user_id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id)
|
||||
})
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
import { DiscordGatewayPayload, DiscordScheduledEventUserRemove } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordScheduledEventUserRemove
|
||||
} from '@discordeno/types'
|
||||
import type { Bot } from '../../../bot.js'
|
||||
|
||||
export function handleGuildScheduledEventUserRemove (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export function handleGuildScheduledEventUserRemove (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): unknown {
|
||||
const payload = data.d as DiscordScheduledEventUserRemove
|
||||
|
||||
return bot.events.scheduledEventUserRemove(bot, {
|
||||
guildScheduledEventId: bot.transformers.snowflake(payload.guild_scheduled_event_id),
|
||||
guildScheduledEventId: bot.transformers.snowflake(
|
||||
payload.guild_scheduled_event_id
|
||||
),
|
||||
userId: bot.transformers.snowflake(payload.user_id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id)
|
||||
})
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { DiscordGatewayPayload, DiscordIntegrationCreateUpdate } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordIntegrationCreateUpdate
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export function handleIntegrationCreate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export function handleIntegrationCreate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
bot.events.integrationCreate(
|
||||
bot,
|
||||
bot.transformers.integration(bot, data.d as DiscordIntegrationCreateUpdate)
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
import { DiscordGatewayPayload, DiscordIntegrationDelete } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordIntegrationDelete
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export function handleIntegrationDelete (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export function handleIntegrationDelete (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
const payload = data.d as DiscordIntegrationDelete
|
||||
|
||||
bot.events.integrationDelete(bot, {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
applicationId: payload.application_id ? bot.transformers.snowflake(payload.application_id) : undefined
|
||||
applicationId: payload.application_id
|
||||
? bot.transformers.snowflake(payload.application_id)
|
||||
: undefined
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { DiscordGatewayPayload, DiscordIntegrationCreateUpdate } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordIntegrationCreateUpdate
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export function handleIntegrationUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export function handleIntegrationUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
bot.events.integrationUpdate(
|
||||
bot,
|
||||
bot.transformers.integration(bot, data.d as DiscordIntegrationCreateUpdate)
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
import { DiscordGatewayPayload, DiscordInteraction } from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleInteractionCreate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
bot.cache.unrepliedInteractions.add(bot.transformers.snowflake((data.d as DiscordInteraction).id))
|
||||
bot.events.interactionCreate(bot, bot.transformers.interaction(bot, data.d as DiscordInteraction))
|
||||
export async function handleInteractionCreate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
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,6 +1,12 @@
|
||||
import { DiscordGatewayPayload, DiscordInviteCreate } from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export function handleInviteCreate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
bot.events.inviteCreate(bot, bot.transformers.invite(bot, data.d as DiscordInviteCreate))
|
||||
export function handleInviteCreate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
bot.events.inviteCreate(
|
||||
bot,
|
||||
bot.transformers.invite(bot, data.d as DiscordInviteCreate)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
import { DiscordGatewayPayload, DiscordInviteDelete } from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export function handleInviteDelete (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export function handleInviteDelete (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
const payload = data.d as DiscordInviteDelete
|
||||
|
||||
bot.events.inviteDelete(bot, {
|
||||
/** The channel of the invite */
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
/** The guild of the invite */
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
|
||||
guildId: payload.guild_id
|
||||
? bot.transformers.snowflake(payload.guild_id)
|
||||
: undefined,
|
||||
/** The unique invite code */
|
||||
code: payload.code
|
||||
})
|
||||
|
||||
@@ -1,7 +1,35 @@
|
||||
import { DiscordGatewayPayload, DiscordGuildMembersChunk, PresenceStatus } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildMembersChunk,
|
||||
PresenceStatus
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
import { Activity, Member, User } from '../../transformers/index.js'
|
||||
|
||||
export async function handleGuildMembersChunk (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleGuildMembersChunk (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<{
|
||||
guildId: bigint
|
||||
members: Member[]
|
||||
chunkIndex: number
|
||||
chunkCount: number
|
||||
notFound: bigint[] | undefined
|
||||
presences:
|
||||
| Array<{
|
||||
user: User
|
||||
guildId: bigint
|
||||
status: PresenceStatus
|
||||
activities: Activity[]
|
||||
clientStatus: {
|
||||
desktop?: string
|
||||
mobile?: string
|
||||
web?: string
|
||||
}
|
||||
}>
|
||||
| undefined
|
||||
nonce: string | undefined
|
||||
}> {
|
||||
const payload = data.d as DiscordGuildMembersChunk
|
||||
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id)
|
||||
@@ -15,7 +43,12 @@ export async function handleGuildMembersChunk (bot: Bot, data: DiscordGatewayPay
|
||||
return {
|
||||
guildId,
|
||||
members: payload.members.map((m) =>
|
||||
bot.transformers.member(bot, m, guildId, bot.transformers.snowflake(m.user.id))
|
||||
bot.transformers.member(
|
||||
bot,
|
||||
m,
|
||||
guildId,
|
||||
bot.transformers.snowflake(m.user.id)
|
||||
)
|
||||
),
|
||||
chunkIndex: payload.chunk_index,
|
||||
chunkCount: payload.chunk_count,
|
||||
@@ -24,7 +57,9 @@ export async function handleGuildMembersChunk (bot: Bot, data: DiscordGatewayPay
|
||||
user: bot.transformers.user(bot, presence.user),
|
||||
guildId,
|
||||
status: PresenceStatus[presence.status],
|
||||
activities: presence.activities.map((activity) => bot.transformers.activity(bot, activity)),
|
||||
activities: presence.activities.map((activity) =>
|
||||
bot.transformers.activity(bot, activity)
|
||||
),
|
||||
clientStatus: {
|
||||
desktop: presence.client_status.desktop,
|
||||
mobile: presence.client_status.mobile,
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { DiscordGatewayPayload, DiscordGuildMemberAdd } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildMemberAdd
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleGuildMemberAdd (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleGuildMemberAdd (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildMemberAdd
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id)
|
||||
const user = bot.transformers.user(bot, payload.user)
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { DiscordGatewayPayload, DiscordGuildMemberRemove } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildMemberRemove
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleGuildMemberRemove (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleGuildMemberRemove (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildMemberRemove
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id)
|
||||
const user = bot.transformers.user(bot, payload.user)
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
import { DiscordGatewayPayload, DiscordGuildMemberUpdate } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildMemberUpdate
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleGuildMemberUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleGuildMemberUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildMemberUpdate
|
||||
|
||||
const user = bot.transformers.user(bot, payload.user)
|
||||
bot.events.guildMemberUpdate(
|
||||
bot,
|
||||
bot.transformers.member(bot, payload, bot.transformers.snowflake(payload.guild_id), user.id),
|
||||
bot.transformers.member(
|
||||
bot,
|
||||
payload,
|
||||
bot.transformers.snowflake(payload.guild_id),
|
||||
user.id
|
||||
),
|
||||
user
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { DiscordGatewayPayload, DiscordMessage } from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleMessageCreate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleMessageCreate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordMessage
|
||||
|
||||
bot.events.messageCreate(bot, bot.transformers.message(bot, payload))
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import { DiscordGatewayPayload, DiscordMessageDelete } from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleMessageDelete (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleMessageDelete (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordMessageDelete
|
||||
|
||||
bot.events.messageDelete(bot, {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined
|
||||
guildId: payload.guild_id
|
||||
? bot.transformers.snowflake(payload.guild_id)
|
||||
: undefined
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
import { DiscordGatewayPayload, DiscordMessageDeleteBulk } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordMessageDeleteBulk
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleMessageDeleteBulk (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleMessageDeleteBulk (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordMessageDeleteBulk
|
||||
|
||||
const channelId = bot.transformers.snowflake(payload.channel_id)
|
||||
const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined
|
||||
const guildId = payload.guild_id
|
||||
? bot.transformers.snowflake(payload.guild_id)
|
||||
: undefined
|
||||
|
||||
bot.events.messageDeleteBulk(bot, {
|
||||
ids: payload.ids.map((id) => bot.transformers.snowflake(id)),
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined
|
||||
channelId,
|
||||
guildId
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,18 +1,31 @@
|
||||
import { DiscordGatewayPayload, DiscordMessageReactionAdd } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordMessageReactionAdd
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleMessageReactionAdd (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleMessageReactionAdd (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordMessageReactionAdd
|
||||
|
||||
const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined
|
||||
const guildId = payload.guild_id
|
||||
? bot.transformers.snowflake(payload.guild_id)
|
||||
: undefined
|
||||
const userId = bot.transformers.snowflake(payload.user_id)
|
||||
bot.events.reactionAdd(bot, {
|
||||
userId,
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
messageId: bot.transformers.snowflake(payload.message_id),
|
||||
guildId,
|
||||
member: (payload.member) && guildId ? bot.transformers.member(bot, payload.member, guildId, userId) : undefined,
|
||||
user: (payload.member) ? bot.transformers.user(bot, payload.member.user) : undefined,
|
||||
member:
|
||||
payload.member && guildId
|
||||
? bot.transformers.member(bot, payload.member, guildId, userId)
|
||||
: undefined,
|
||||
user: payload.member
|
||||
? bot.transformers.user(bot, payload.member.user)
|
||||
: undefined,
|
||||
emoji: bot.transformers.emoji(bot, payload.emoji)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
import { DiscordGatewayPayload, DiscordMessageReactionRemove } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordMessageReactionRemove
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleMessageReactionRemove (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleMessageReactionRemove (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordMessageReactionRemove
|
||||
|
||||
bot.events.reactionRemove(bot, {
|
||||
userId: bot.transformers.snowflake(payload.user_id),
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
messageId: bot.transformers.snowflake(payload.message_id),
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
|
||||
guildId: payload.guild_id
|
||||
? bot.transformers.snowflake(payload.guild_id)
|
||||
: undefined,
|
||||
emoji: bot.transformers.emoji(bot, payload.emoji)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
import { DiscordGatewayPayload, DiscordMessageReactionRemoveAll } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordMessageReactionRemoveAll
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleMessageReactionRemoveAll (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleMessageReactionRemoveAll (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordMessageReactionRemoveAll
|
||||
|
||||
bot.events.reactionRemoveAll(bot, {
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
messageId: bot.transformers.snowflake(payload.message_id),
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined
|
||||
guildId: payload.guild_id
|
||||
? bot.transformers.snowflake(payload.guild_id)
|
||||
: undefined
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
import { DiscordGatewayPayload, DiscordMessageReactionRemoveEmoji } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordMessageReactionRemoveEmoji
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleMessageReactionRemoveEmoji (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleMessageReactionRemoveEmoji (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordMessageReactionRemoveEmoji
|
||||
|
||||
bot.events.reactionRemoveEmoji(bot, {
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
messageId: bot.transformers.snowflake(payload.message_id),
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
|
||||
guildId: payload.guild_id
|
||||
? bot.transformers.snowflake(payload.guild_id)
|
||||
: undefined,
|
||||
emoji: bot.transformers.emoji(bot, payload.emoji)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { DiscordGatewayPayload, DiscordMessage } from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleMessageUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleMessageUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordMessage
|
||||
if (!payload.edited_timestamp) return
|
||||
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
import { DiscordGatewayPayload, DiscordPresenceUpdate } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordPresenceUpdate
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handlePresenceUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
bot.events.presenceUpdate(bot, bot.transformers.presence(bot, data.d as DiscordPresenceUpdate))
|
||||
export async function handlePresenceUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
bot.events.presenceUpdate(
|
||||
bot,
|
||||
bot.transformers.presence(bot, data.d as DiscordPresenceUpdate)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { DiscordGatewayPayload, DiscordReady } from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export function handleReady (bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
export function handleReady (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number
|
||||
): void {
|
||||
const payload = data.d as DiscordReady
|
||||
// Triggered on each shard
|
||||
bot.events.ready(
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { DiscordGatewayPayload, DiscordTypingStart } from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export function handleTypingStart (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export function handleTypingStart (bot: Bot, data: DiscordGatewayPayload): void {
|
||||
const payload = data.d as DiscordTypingStart
|
||||
|
||||
const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined
|
||||
const guildId = payload.guild_id
|
||||
? bot.transformers.snowflake(payload.guild_id)
|
||||
: undefined
|
||||
const userId = bot.transformers.snowflake(payload.user_id)
|
||||
|
||||
bot.events.typingStart(bot, {
|
||||
@@ -12,6 +14,9 @@ export function handleTypingStart (bot: Bot, data: DiscordGatewayPayload) {
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
userId,
|
||||
timestamp: payload.timestamp,
|
||||
member: (payload.member) && guildId ? bot.transformers.member(bot, payload.member, guildId, userId) : undefined
|
||||
member:
|
||||
payload.member && guildId
|
||||
? bot.transformers.member(bot, payload.member, guildId, userId)
|
||||
: undefined
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { DiscordGatewayPayload, DiscordUser } from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleUserUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleUserUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordUser
|
||||
bot.events.botUpdate(bot, bot.transformers.user(bot, payload))
|
||||
}
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
import { DiscordGatewayPayload, DiscordGuildRoleCreate } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildRoleCreate
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleGuildRoleCreate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleGuildRoleCreate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildRoleCreate
|
||||
bot.events.roleCreate(
|
||||
bot,
|
||||
bot.transformers.role(bot, { role: payload.role, guildId: bot.transformers.snowflake(payload.guild_id) })
|
||||
bot.transformers.role(bot, {
|
||||
role: payload.role,
|
||||
guildId: bot.transformers.snowflake(payload.guild_id)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { DiscordGatewayPayload, DiscordGuildRoleDelete } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildRoleDelete
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleGuildRoleDelete (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleGuildRoleDelete (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildRoleDelete
|
||||
bot.events.roleDelete(bot, {
|
||||
roleId: bot.transformers.snowflake(payload.role_id),
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
import { DiscordGatewayPayload, DiscordGuildRoleUpdate } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordGuildRoleUpdate
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleGuildRoleUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleGuildRoleUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordGuildRoleUpdate
|
||||
|
||||
bot.events.roleUpdate(
|
||||
bot,
|
||||
bot.transformers.role(bot, { role: payload.role, guildId: bot.transformers.snowflake(payload.guild_id) })
|
||||
bot.transformers.role(bot, {
|
||||
role: payload.role,
|
||||
guildId: bot.transformers.snowflake(payload.guild_id)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { DiscordGatewayPayload, DiscordVoiceServerUpdate } from '@discordeno/types'
|
||||
import {
|
||||
DiscordGatewayPayload,
|
||||
DiscordVoiceServerUpdate
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleVoiceServerUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleVoiceServerUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordVoiceServerUpdate
|
||||
|
||||
bot.events.voiceServerUpdate(bot, {
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import { DiscordGatewayPayload, DiscordVoiceState } from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export async function handleVoiceStateUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export async function handleVoiceStateUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): Promise<void> {
|
||||
const payload = data.d as DiscordVoiceState
|
||||
if (!payload.guild_id) return
|
||||
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id)
|
||||
|
||||
bot.events.voiceStateUpdate(bot, bot.transformers.voiceState(bot, { voiceState: payload, guildId }))
|
||||
bot.events.voiceStateUpdate(
|
||||
bot,
|
||||
bot.transformers.voiceState(bot, { voiceState: payload, guildId })
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { DiscordGatewayPayload, DiscordWebhookUpdate } from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
|
||||
export function handleWebhooksUpdate (bot: Bot, data: DiscordGatewayPayload) {
|
||||
export function handleWebhooksUpdate (
|
||||
bot: Bot,
|
||||
data: DiscordGatewayPayload
|
||||
): void {
|
||||
const payload = data.d as DiscordWebhookUpdate
|
||||
bot.events.webhooksUpdate(bot, {
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import { BigString, ChannelTypes, DiscordChannel, OverwriteReadable, SortOrderTypes } from '@discordeno/types'
|
||||
import {
|
||||
BigString,
|
||||
ChannelTypes,
|
||||
DiscordChannel,
|
||||
OverwriteReadable,
|
||||
SortOrderTypes
|
||||
} from '@discordeno/types'
|
||||
import type { Bot } from '../../bot.js'
|
||||
import { WithReason } from '../../index.js'
|
||||
import { Channel } from '../../transformers/channel.js'
|
||||
@@ -22,7 +28,11 @@ import { Channel } from '../../transformers/channel.js'
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/guild#create-guild-channel}
|
||||
*/
|
||||
export async function createChannel (bot: Bot, guildId: BigString, options: CreateGuildChannel): Promise<Channel> {
|
||||
export async function createChannel (
|
||||
bot: Bot,
|
||||
guildId: BigString,
|
||||
options: CreateGuildChannel
|
||||
): Promise<Channel> {
|
||||
// BITRATE IS IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000
|
||||
if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000
|
||||
|
||||
@@ -40,39 +50,52 @@ export async function createChannel (bot: Bot, guildId: BigString, options: Crea
|
||||
position: options.position,
|
||||
parent_id: options.parentId?.toString(),
|
||||
nsfw: options.nsfw,
|
||||
permission_overwrites: 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
|
||||
})),
|
||||
type: options?.type || ChannelTypes.GuildText,
|
||||
permission_overwrites: 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
|
||||
})
|
||||
),
|
||||
type: options?.type ?? ChannelTypes.GuildText,
|
||||
default_sort_order: options.defaultSortOrder,
|
||||
reason: options.reason,
|
||||
default_auto_archive_duration: options?.defaultAutoArchiveDuration,
|
||||
default_reaction_emoji: (options.defaultReactionEmoji)
|
||||
default_reaction_emoji: options.defaultReactionEmoji
|
||||
? {
|
||||
emoji_id: options.defaultReactionEmoji.emojiId
|
||||
? bot.transformers.reverse.snowflake(options.defaultReactionEmoji.emojiId)
|
||||
? bot.transformers.reverse.snowflake(
|
||||
options.defaultReactionEmoji.emojiId
|
||||
)
|
||||
: options.defaultReactionEmoji.emojiId,
|
||||
emoji_name: options.defaultReactionEmoji.emojiName
|
||||
}
|
||||
: undefined,
|
||||
|
||||
available_tags: (options.availableTags)
|
||||
available_tags: options.availableTags
|
||||
? options.availableTags.map((availableTag) => ({
|
||||
id: bot.transformers.reverse.snowflake(availableTag.id),
|
||||
name: availableTag.name,
|
||||
moderated: availableTag.moderated,
|
||||
emoji_name: availableTag.emojiName,
|
||||
emoji_id: availableTag.emojiId ? bot.transformers.reverse.snowflake(availableTag.emojiId) : undefined
|
||||
emoji_id: availableTag.emojiId
|
||||
? bot.transformers.reverse.snowflake(availableTag.emojiId)
|
||||
: undefined
|
||||
}))
|
||||
: undefined
|
||||
}
|
||||
: {}
|
||||
)
|
||||
|
||||
return bot.transformers.channel(bot, { channel: result, guildId: bot.transformers.snowflake(guildId) })
|
||||
return bot.transformers.channel(bot, {
|
||||
channel: result,
|
||||
guildId: bot.transformers.snowflake(guildId)
|
||||
})
|
||||
}
|
||||
|
||||
export interface CreateGuildChannel extends WithReason {
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
import { BigString, ChannelTypes, DiscordChannel, OverwriteReadable, SortOrderTypes, VideoQualityModes } from '@discordeno/types'
|
||||
import {
|
||||
BigString,
|
||||
ChannelTypes,
|
||||
DiscordChannel,
|
||||
OverwriteReadable,
|
||||
SortOrderTypes,
|
||||
VideoQualityModes
|
||||
} from '@discordeno/types'
|
||||
import type { Bot } from '../../bot.js'
|
||||
import { WithReason } from '../../index.js'
|
||||
import { Channel } from '../../transformers/channel.js'
|
||||
@@ -33,8 +40,12 @@ import { Channel } from '../../transformers/channel.js'
|
||||
* - Otherwise:
|
||||
* - Fires a _Channel Update_ gateway event.
|
||||
*/
|
||||
export async function editChannel (bot: Bot, channelId: BigString, options: ModifyChannel): Promise<Channel> {
|
||||
if (options.name || options.topic) {
|
||||
export async function editChannel (
|
||||
bot: Bot,
|
||||
channelId: BigString,
|
||||
options: ModifyChannel
|
||||
): Promise<Channel> {
|
||||
if (options.name ?? options.topic) {
|
||||
const request = editChannelNameTopicQueue.get(channelId)
|
||||
if (request == null) {
|
||||
// If this hasn't been done before simply add 1 for it
|
||||
@@ -71,22 +82,27 @@ export async function editChannel (bot: Bot, channelId: BigString, options: Modi
|
||||
user_limit: options.userLimit,
|
||||
rate_limit_per_user: options.rateLimitPerUser,
|
||||
position: options.position,
|
||||
parent_id: options.parentId === null ? null : options.parentId?.toString(),
|
||||
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)
|
||||
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
|
||||
allow: overwrite.allow
|
||||
? bot.utils.calculateBits(overwrite.allow)
|
||||
: null,
|
||||
deny: overwrite.deny
|
||||
? bot.utils.calculateBits(overwrite.deny)
|
||||
: null
|
||||
}))
|
||||
: undefined,
|
||||
available_tags: (options.availableTags)
|
||||
available_tags: options.availableTags
|
||||
? options.availableTags.map((availableTag) => ({
|
||||
id: availableTag.id,
|
||||
name: availableTag.name,
|
||||
@@ -95,8 +111,10 @@ export async function editChannel (bot: Bot, channelId: BigString, options: Modi
|
||||
emoji_name: availableTag.emojiName
|
||||
}))
|
||||
: undefined,
|
||||
applied_tags: options.appliedTags?.map((appliedTag) => appliedTag.toString()),
|
||||
default_reaction_emoji: (options.defaultReactionEmoji)
|
||||
applied_tags: options.appliedTags?.map((appliedTag) =>
|
||||
appliedTag.toString()
|
||||
),
|
||||
default_reaction_emoji: options.defaultReactionEmoji
|
||||
? {
|
||||
emoji_id: options.defaultReactionEmoji.emojiId,
|
||||
emoji_name: options.defaultReactionEmoji.emojiName
|
||||
@@ -107,7 +125,10 @@ export async function editChannel (bot: Bot, channelId: BigString, options: Modi
|
||||
}
|
||||
)
|
||||
|
||||
return bot.transformers.channel(bot, { channel: result, guildId: bot.transformers.snowflake(result.guild_id!) })
|
||||
return bot.transformers.channel(bot, {
|
||||
channel: result,
|
||||
guildId: bot.transformers.snowflake(result.guild_id!)
|
||||
})
|
||||
}
|
||||
|
||||
interface EditChannelRequest {
|
||||
@@ -130,30 +151,33 @@ function processEditChannelQueue (bot: Bot): void {
|
||||
if (!editChannelProcessing) return
|
||||
|
||||
const now = Date.now()
|
||||
editChannelNameTopicQueue.forEach(async (request) => {
|
||||
bot.events.debug('Running forEach loop in edit_channel file.')
|
||||
if (now < request.timestamp) return
|
||||
// 10 minutes have passed so we can reset this channel again
|
||||
if (request.items.length === 0) {
|
||||
return editChannelNameTopicQueue.delete(request.channelId)
|
||||
}
|
||||
request.amount = 0
|
||||
// There are items to process for this request
|
||||
const details = request.items.shift()
|
||||
editChannelNameTopicQueue.forEach((request) => {
|
||||
(async () => {
|
||||
bot.events.debug('Running forEach loop in edit_channel file.')
|
||||
if (now < request.timestamp) return
|
||||
// 10 minutes have passed so we can reset this channel again
|
||||
if (request.items.length === 0) {
|
||||
editChannelNameTopicQueue.delete(request.channelId)
|
||||
return
|
||||
}
|
||||
request.amount = 0
|
||||
// There are items to process for this request
|
||||
const details = request.items.shift()
|
||||
|
||||
if (details == null) return
|
||||
if (details == null) return
|
||||
|
||||
await bot.helpers
|
||||
.editChannel(details.channelId, details.options)
|
||||
.then((result) => details.resolve(result))
|
||||
.catch(details.reject)
|
||||
const secondDetails = request.items.shift()
|
||||
if (secondDetails == null) return
|
||||
await bot.helpers
|
||||
.editChannel(details.channelId, details.options)
|
||||
.then((result) => details.resolve(result))
|
||||
.catch(details.reject)
|
||||
const secondDetails = request.items.shift()
|
||||
if (secondDetails == null) return
|
||||
|
||||
await bot.helpers
|
||||
.editChannel(secondDetails.channelId, secondDetails.options)
|
||||
.then((result) => secondDetails.resolve(result))
|
||||
.catch(secondDetails.reject)
|
||||
await bot.helpers
|
||||
.editChannel(secondDetails.channelId, secondDetails.options)
|
||||
.then((result) => secondDetails.resolve(result))
|
||||
.catch(secondDetails.reject)
|
||||
})()
|
||||
})
|
||||
|
||||
if (editChannelNameTopicQueue.size) {
|
||||
|
||||
@@ -2,7 +2,12 @@ import type { BigString, MfaLevels } from '@discordeno/types'
|
||||
import type { Bot } from '../../index.js'
|
||||
|
||||
/** Modify a guild's MFA level. Requires guild ownership. */
|
||||
export async function editGuildMfaLevel (bot: Bot, guildId: BigString, mfaLevel: MfaLevels, reason?: string) {
|
||||
export async function editGuildMfaLevel (
|
||||
bot: Bot,
|
||||
guildId: BigString,
|
||||
mfaLevel: MfaLevels,
|
||||
reason?: string
|
||||
): Promise<void> {
|
||||
return await bot.rest.runMethod<void>(
|
||||
bot.rest,
|
||||
'POST',
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { BigString, DiscordScheduledEvent, ScheduledEventEntityType, ScheduledEventPrivacyLevel } from '@discordeno/types'
|
||||
import {
|
||||
BigString,
|
||||
DiscordScheduledEvent,
|
||||
ScheduledEventEntityType,
|
||||
ScheduledEventPrivacyLevel
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../../../bot.js'
|
||||
import { WithReason } from '../../../index.js'
|
||||
import { ScheduledEvent } from '../../../transformers/scheduledEvent.js'
|
||||
@@ -28,7 +33,10 @@ export async function createScheduledEvent (
|
||||
if (!bot.utils.validateLength(options.name, { min: 1, max: 100 })) {
|
||||
throw new Error('Name must be between 1-100 characters.')
|
||||
}
|
||||
if (options.description && !bot.utils.validateLength(options.description, { max: 1000 })) {
|
||||
if (
|
||||
options.description &&
|
||||
!bot.utils.validateLength(options.description, { max: 1000 })
|
||||
) {
|
||||
throw new Error('Description must be below 1000 characters.')
|
||||
}
|
||||
if (options.location) {
|
||||
@@ -40,10 +48,18 @@ export async function createScheduledEvent (
|
||||
}
|
||||
}
|
||||
if (options.entityType === ScheduledEventEntityType.External) {
|
||||
if (!options.scheduledEndTime) throw new Error('A scheduled end time is required when making an External event.')
|
||||
if (!options.location) throw new Error('A location is required when making an External event.')
|
||||
if (!options.scheduledEndTime) {
|
||||
throw new Error(
|
||||
'A scheduled end time is required when making an External event.'
|
||||
)
|
||||
}
|
||||
if (!options.location) { throw new Error('A location is required when making an External event.') }
|
||||
}
|
||||
if (options.scheduledStartTime && options.scheduledEndTime && options.scheduledStartTime > options.scheduledEndTime) {
|
||||
if (
|
||||
options.scheduledStartTime &&
|
||||
options.scheduledEndTime &&
|
||||
options.scheduledStartTime > options.scheduledEndTime
|
||||
) {
|
||||
throw new Error('Cannot schedule event to end before starting.')
|
||||
}
|
||||
|
||||
@@ -53,12 +69,17 @@ export async function createScheduledEvent (
|
||||
bot.constants.routes.GUILD_SCHEDULED_EVENTS(guildId),
|
||||
{
|
||||
channel_id: options.channelId?.toString(),
|
||||
entity_metadata: options.location ? { location: options.location } : undefined,
|
||||
entity_metadata: options.location
|
||||
? { location: options.location }
|
||||
: undefined,
|
||||
name: options.name,
|
||||
description: options.description,
|
||||
scheduled_start_time: new Date(options.scheduledStartTime).toISOString(),
|
||||
scheduled_end_time: options.scheduledEndTime ? new Date(options.scheduledEndTime).toISOString() : undefined,
|
||||
privacy_level: options.privacyLevel || ScheduledEventPrivacyLevel.GuildOnly,
|
||||
scheduled_end_time: options.scheduledEndTime
|
||||
? new Date(options.scheduledEndTime).toISOString()
|
||||
: undefined,
|
||||
privacy_level:
|
||||
options.privacyLevel ?? ScheduledEventPrivacyLevel.GuildOnly,
|
||||
entity_type: options.entityType,
|
||||
reason: options.reason
|
||||
}
|
||||
|
||||
@@ -26,13 +26,13 @@ export async function getScheduledEventUsers (
|
||||
bot: Bot,
|
||||
guildId: BigString,
|
||||
eventId: BigString,
|
||||
options?: GetScheduledEventUsers & { withMember?: false },
|
||||
options?: GetScheduledEventUsers & { withMember?: false }
|
||||
): Promise<Collection<bigint, User>>
|
||||
export async function getScheduledEventUsers (
|
||||
bot: Bot,
|
||||
guildId: BigString,
|
||||
eventId: BigString,
|
||||
options?: GetScheduledEventUsers & { withMember: true },
|
||||
options?: GetScheduledEventUsers & { withMember: true }
|
||||
): Promise<Collection<bigint, { user: User, member: Member }>>
|
||||
export async function getScheduledEventUsers (
|
||||
bot: Bot,
|
||||
@@ -42,22 +42,24 @@ export async function getScheduledEventUsers (
|
||||
): Promise<
|
||||
Collection<bigint, User> | Collection<bigint, { user: User, member: Member }>
|
||||
> {
|
||||
let url = bot.constants.routes.GUILD_SCHEDULED_EVENT_USERS(guildId, eventId, options)
|
||||
let url = bot.constants.routes.GUILD_SCHEDULED_EVENT_USERS(
|
||||
guildId,
|
||||
eventId,
|
||||
options
|
||||
)
|
||||
|
||||
if (options != null) {
|
||||
url = '?'
|
||||
|
||||
if (options.limit) url += `limit=${options.limit}`
|
||||
if (options.withMember) url += `&with_member=${options.withMember}`
|
||||
if (options.withMember !== undefined) { url += `&with_member=${options.withMember.toString()}` }
|
||||
if (options.after) url += `&after=${options.after}`
|
||||
if (options.before) url += `&before=${options.before}`
|
||||
}
|
||||
|
||||
const results = await bot.rest.runMethod<Array<{ user: DiscordUser, member?: DiscordMember }>>(
|
||||
bot.rest,
|
||||
'GET',
|
||||
url
|
||||
)
|
||||
const results = await bot.rest.runMethod<
|
||||
Array<{ user: DiscordUser, member?: DiscordMember }>
|
||||
>(bot.rest, 'GET', url)
|
||||
|
||||
if (!options?.withMember) {
|
||||
return new Collection(
|
||||
|
||||
@@ -25,9 +25,11 @@ export function getGuildBannerURL (
|
||||
? bot.utils.formatImageURL(
|
||||
bot.constants.routes.GUILD_BANNER(
|
||||
guildId,
|
||||
typeof options.banner === 'string' ? options.banner : bot.utils.iconBigintToHash(options.banner)
|
||||
typeof options.banner === 'string'
|
||||
? options.banner
|
||||
: bot.utils.iconBigintToHash(options.banner)
|
||||
),
|
||||
options.size || 128,
|
||||
options.size ?? 128,
|
||||
options.format
|
||||
)
|
||||
: undefined
|
||||
|
||||
@@ -23,9 +23,11 @@ export function getGuildIconURL (
|
||||
? bot.utils.formatImageURL(
|
||||
bot.constants.routes.GUILD_ICON(
|
||||
guildId,
|
||||
typeof imageHash === 'string' ? imageHash : bot.utils.iconBigintToHash(imageHash)
|
||||
typeof imageHash === 'string'
|
||||
? imageHash
|
||||
: bot.utils.iconBigintToHash(imageHash)
|
||||
),
|
||||
options?.size || 128,
|
||||
options?.size ?? 128,
|
||||
options?.format
|
||||
)
|
||||
: undefined
|
||||
|
||||
@@ -24,9 +24,11 @@ export function getGuildSplashURL (
|
||||
? bot.utils.formatImageURL(
|
||||
bot.constants.routes.GUILD_SPLASH(
|
||||
guildId,
|
||||
typeof imageHash === 'string' ? imageHash : bot.utils.iconBigintToHash(imageHash)
|
||||
typeof imageHash === 'string'
|
||||
? imageHash
|
||||
: bot.utils.iconBigintToHash(imageHash)
|
||||
),
|
||||
options?.size || 128,
|
||||
options?.size ?? 128,
|
||||
options?.format
|
||||
)
|
||||
: undefined
|
||||
|
||||
@@ -33,7 +33,11 @@ export async function fetchMembers (
|
||||
): Promise<void> {
|
||||
// You can request 1 member without the intent
|
||||
// Check if intents is not 0 as proxy ws won't set intents in other instances
|
||||
if (bot.intents && (!options?.limit || options.limit > 1) && !(bot.intents & GatewayIntents.GuildMembers)) {
|
||||
if (
|
||||
bot.intents &&
|
||||
(!options?.limit || options.limit > 1) &&
|
||||
!(bot.intents & GatewayIntents.GuildMembers)
|
||||
) {
|
||||
throw new Error(bot.constants.Errors.MISSING_INTENT_GUILD_MEMBERS)
|
||||
}
|
||||
|
||||
@@ -41,7 +45,10 @@ export async function fetchMembers (
|
||||
options.limit = options.userIds.length
|
||||
}
|
||||
|
||||
const shardId = calculateShardId(bot.gateway, bot.transformers.snowflake(guildId))
|
||||
const shardId = calculateShardId(
|
||||
bot.gateway,
|
||||
bot.transformers.snowflake(guildId)
|
||||
)
|
||||
|
||||
return await new Promise((resolve) => {
|
||||
const nonce = `${guildId}-${Date.now()}`
|
||||
@@ -57,9 +64,9 @@ export async function fetchMembers (
|
||||
d: {
|
||||
guild_id: guildId.toString(),
|
||||
// If a query is provided use it, OR if a limit is NOT provided use ""
|
||||
query: options?.query || (options?.limit ? undefined : ''),
|
||||
limit: options?.limit || 0,
|
||||
presences: options?.presences || false,
|
||||
query: options?.query ?? (options?.limit ? undefined : ''),
|
||||
limit: options?.limit ?? 0,
|
||||
presences: options?.presences ?? false,
|
||||
user_ids: options?.userIds?.map((id) => id.toString()),
|
||||
nonce
|
||||
}
|
||||
|
||||
@@ -24,9 +24,11 @@ export function getAvatarURL (
|
||||
? bot.utils.formatImageURL(
|
||||
bot.constants.routes.USER_AVATAR(
|
||||
userId,
|
||||
typeof options?.avatar === 'string' ? options.avatar : bot.utils.iconBigintToHash(options?.avatar)
|
||||
typeof options?.avatar === 'string'
|
||||
? options.avatar
|
||||
: bot.utils.iconBigintToHash(options?.avatar)
|
||||
),
|
||||
options?.size || 128,
|
||||
options?.size ?? 128,
|
||||
options?.format
|
||||
)
|
||||
: bot.constants.routes.USER_DEFAULT_AVATAR(Number(discriminator) % 5)
|
||||
|
||||
@@ -30,7 +30,13 @@ export async function addReactions (
|
||||
ordered = false
|
||||
): Promise<void> {
|
||||
if (!ordered) {
|
||||
return void await Promise.all(reactions.map(async (reaction) => await bot.helpers.addReaction(channelId, messageId, reaction)))
|
||||
await Promise.all(
|
||||
reactions.map(
|
||||
async (reaction) =>
|
||||
await bot.helpers.addReaction(channelId, messageId, reaction)
|
||||
)
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
for (const reaction of reactions) {
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import { Bot } from '../../bot.js'
|
||||
import { StatusUpdate } from './editShardStatus.js'
|
||||
|
||||
export async function editBotStatus (bot: Bot, data: StatusUpdate): Promise<void> {
|
||||
return void await Promise.all(bot.gateway.manager.shards.map(async (shard) => await bot.helpers.editShardStatus(shard.id, data)))
|
||||
export async function editBotStatus (
|
||||
bot: Bot,
|
||||
data: StatusUpdate
|
||||
): Promise<void> {
|
||||
await Promise.all(
|
||||
bot.gateway.manager.shards.map(
|
||||
async (shard) => await bot.helpers.editShardStatus(shard.id, data)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,11 @@ import { GatewayOpcodes, PresenceStatus } from '@discordeno/types'
|
||||
import type { Bot } from '../../bot.js'
|
||||
import { Activity } from '../../transformers/activity.js'
|
||||
|
||||
export async function editShardStatus (bot: Bot, shardId: number, data: StatusUpdate): Promise<void> {
|
||||
export async function editShardStatus (
|
||||
bot: Bot,
|
||||
shardId: number,
|
||||
data: StatusUpdate
|
||||
): Promise<void> {
|
||||
const shard = bot.gateway.manager.shards.get(shardId)
|
||||
if (shard == null) {
|
||||
throw new Error(`Shard (id: ${shardId}) not found.`)
|
||||
@@ -18,16 +22,17 @@ export async function editShardStatus (bot: Bot, shardId: number, data: StatusUp
|
||||
type: activity.type,
|
||||
url: activity.url,
|
||||
created_at: activity.createdAt,
|
||||
timestamps: activity.startedAt || activity.endedAt
|
||||
? {
|
||||
start: activity.startedAt,
|
||||
end: activity.endedAt
|
||||
}
|
||||
: undefined,
|
||||
timestamps:
|
||||
activity.startedAt ?? activity.endedAt
|
||||
? {
|
||||
start: activity.startedAt,
|
||||
end: activity.endedAt
|
||||
}
|
||||
: undefined,
|
||||
application_id: activity.applicationId?.toString(),
|
||||
details: activity.details,
|
||||
state: activity.state,
|
||||
emoji: (activity.emoji)
|
||||
emoji: activity.emoji
|
||||
? {
|
||||
name: activity.emoji.name,
|
||||
id: activity.emoji.id?.toString(),
|
||||
@@ -40,21 +45,26 @@ export async function editShardStatus (bot: Bot, shardId: number, data: StatusUp
|
||||
size: activity.partyMaxSize
|
||||
}
|
||||
: undefined,
|
||||
assets: activity.largeImage || activity.largeText || activity.smallImage || activity.smallText
|
||||
? {
|
||||
large_image: activity.largeImage,
|
||||
large_text: activity.largeText,
|
||||
small_image: activity.smallImage,
|
||||
small_text: activity.smallText
|
||||
}
|
||||
: undefined,
|
||||
secrets: activity.join || activity.spectate || activity.match
|
||||
? {
|
||||
join: activity.join,
|
||||
spectate: activity.spectate,
|
||||
match: activity.match
|
||||
}
|
||||
: undefined,
|
||||
assets:
|
||||
activity.largeImage ??
|
||||
activity.largeText ??
|
||||
activity.smallImage ??
|
||||
activity.smallText
|
||||
? {
|
||||
large_image: activity.largeImage,
|
||||
large_text: activity.largeText,
|
||||
small_image: activity.smallImage,
|
||||
small_text: activity.smallText
|
||||
}
|
||||
: undefined,
|
||||
secrets:
|
||||
activity.join ?? activity.spectate ?? activity.match
|
||||
? {
|
||||
join: activity.join,
|
||||
spectate: activity.spectate,
|
||||
match: activity.match
|
||||
}
|
||||
: undefined,
|
||||
instance: activity.instance,
|
||||
flags: activity.flags,
|
||||
buttons: activity.buttons
|
||||
|
||||
@@ -16,7 +16,13 @@ import type { Bot } from '../../bot.js'
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/guild#remove-guild-member-role}
|
||||
*/
|
||||
export async function removeRole (bot: Bot, guildId: BigString, userId: BigString, roleId: BigString, reason?: string) {
|
||||
export async function removeRole (
|
||||
bot: Bot,
|
||||
guildId: BigString,
|
||||
userId: BigString,
|
||||
roleId: BigString,
|
||||
reason?: string
|
||||
): Promise<void> {
|
||||
return await bot.rest.runMethod<void>(
|
||||
bot.rest,
|
||||
'DELETE',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Bot } from '../../bot.js'
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { Sticker } from '../../transformers/sticker.js'
|
||||
|
||||
/**
|
||||
@@ -16,7 +17,12 @@ import { Sticker } from '../../transformers/sticker.js'
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/sticker#delete-guild-sticker}
|
||||
*/
|
||||
export async function deleteGuildSticker (bot: Bot, guildId: bigint, stickerId: bigint, reason?: string): Promise<void> {
|
||||
export async function deleteGuildSticker (
|
||||
bot: Bot,
|
||||
guildId: bigint,
|
||||
stickerId: bigint,
|
||||
reason?: string
|
||||
): Promise<void> {
|
||||
return await bot.rest.runMethod<void>(
|
||||
bot.rest,
|
||||
'DELETE',
|
||||
|
||||
@@ -3,7 +3,12 @@ import { Bot } from '../bot.js'
|
||||
|
||||
const Mask = (1n << 64n) - 1n
|
||||
|
||||
export function packOverwrites (allow: string, deny: string, id: string, type: number): bigint {
|
||||
export function packOverwrites (
|
||||
allow: string,
|
||||
deny: string,
|
||||
id: string,
|
||||
type: number
|
||||
): bigint {
|
||||
return pack64(allow, 0) | pack64(deny, 1) | pack64(id, 2) | pack64(type, 3)
|
||||
}
|
||||
function unpack64 (v: bigint, shift: number): bigint {
|
||||
@@ -11,15 +16,25 @@ function unpack64 (v: bigint, shift: number): bigint {
|
||||
}
|
||||
function pack64 (v: string | number, shift: number): bigint {
|
||||
const b = BigInt(v)
|
||||
if (b < 0 || b > Mask) throw new Error(`should have been a 64 bit unsigned integer: ${v}`)
|
||||
if (b < 0 || b > Mask) { throw new Error(`should have been a 64 bit unsigned integer: ${v}`) }
|
||||
return b << BigInt(shift * 64)
|
||||
}
|
||||
export function separateOverwrites (v: bigint): [number, bigint, bigint, bigint] {
|
||||
return [Number(unpack64(v, 3)), unpack64(v, 2), unpack64(v, 0), unpack64(v, 1)] as [number, bigint, bigint, bigint]
|
||||
export function separateOverwrites (
|
||||
v: bigint
|
||||
): [number, bigint, bigint, bigint] {
|
||||
return [
|
||||
Number(unpack64(v, 3)),
|
||||
unpack64(v, 2),
|
||||
unpack64(v, 0),
|
||||
unpack64(v, 1)
|
||||
] as [number, bigint, bigint, bigint]
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformChannel (bot: Bot, payload: { channel: DiscordChannel } & { guildId?: bigint }) {
|
||||
export function transformChannel (
|
||||
bot: Bot,
|
||||
payload: { channel: DiscordChannel } & { guildId?: bigint }
|
||||
) {
|
||||
const channel = {
|
||||
// UNTRANSFORMED STUFF HERE
|
||||
type: payload.channel.type,
|
||||
@@ -33,22 +48,36 @@ export function transformChannel (bot: Bot, payload: { channel: DiscordChannel }
|
||||
// recipients: payload.channel.recipients?.map((r) => bot.transformers.user(bot, r)),
|
||||
rtcRegion: payload.channel.rtc_region ?? undefined,
|
||||
videoQualityMode: payload.channel.video_quality_mode,
|
||||
guildId: payload.guildId || (payload.channel.guild_id ? bot.transformers.snowflake(payload.channel.guild_id) : 0n),
|
||||
lastPinTimestamp: payload.channel.last_pin_timestamp ? Date.parse(payload.channel.last_pin_timestamp) : undefined,
|
||||
permissionOverwrites: (payload.channel.permission_overwrites)
|
||||
? payload.channel.permission_overwrites.map((o) => packOverwrites(o.allow || '0', o.deny || '0', o.id, o.type))
|
||||
guildId:
|
||||
payload.guildId ??
|
||||
(payload.channel.guild_id
|
||||
? bot.transformers.snowflake(payload.channel.guild_id)
|
||||
: 0n),
|
||||
lastPinTimestamp: payload.channel.last_pin_timestamp
|
||||
? Date.parse(payload.channel.last_pin_timestamp)
|
||||
: undefined,
|
||||
permissionOverwrites: payload.channel.permission_overwrites
|
||||
? payload.channel.permission_overwrites.map((o) =>
|
||||
packOverwrites(o.allow ?? '0', o.deny ?? '0', o.id, o.type)
|
||||
)
|
||||
: [],
|
||||
|
||||
id: bot.transformers.snowflake(payload.channel.id),
|
||||
permissions: payload.channel.permissions ? bot.transformers.snowflake(payload.channel.permissions) : undefined,
|
||||
permissions: payload.channel.permissions
|
||||
? bot.transformers.snowflake(payload.channel.permissions)
|
||||
: undefined,
|
||||
lastMessageId: payload.channel.last_message_id
|
||||
? bot.transformers.snowflake(payload.channel.last_message_id)
|
||||
: undefined,
|
||||
ownerId: payload.channel.owner_id ? bot.transformers.snowflake(payload.channel.owner_id) : undefined,
|
||||
ownerId: payload.channel.owner_id
|
||||
? bot.transformers.snowflake(payload.channel.owner_id)
|
||||
: undefined,
|
||||
applicationId: payload.channel.application_id
|
||||
? bot.transformers.snowflake(payload.channel.application_id)
|
||||
: undefined,
|
||||
parentId: payload.channel.parent_id ? bot.transformers.snowflake(payload.channel.parent_id) : undefined,
|
||||
parentId: payload.channel.parent_id
|
||||
? bot.transformers.snowflake(payload.channel.parent_id)
|
||||
: undefined,
|
||||
memberCount: payload.channel.member_count,
|
||||
messageCount: payload.channel.message_count,
|
||||
archiveTimestamp: payload.channel.thread_metadata?.archive_timestamp
|
||||
@@ -69,4 +98,4 @@ export function transformChannel (bot: Bot, payload: { channel: DiscordChannel }
|
||||
return channel as Optionalize<typeof channel>
|
||||
}
|
||||
|
||||
export interface Channel extends ReturnType<typeof transformChannel> { }
|
||||
export interface Channel extends ReturnType<typeof transformChannel> {}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { DiscordEmbed, Optionalize } from '@discordeno/types'
|
||||
import { Bot } from '../bot.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformEmbed (bot: Bot, payload: DiscordEmbed) {
|
||||
const embed = {
|
||||
title: payload.title,
|
||||
@@ -9,14 +10,14 @@ export function transformEmbed (bot: Bot, payload: DiscordEmbed) {
|
||||
url: payload.url,
|
||||
timestamp: payload.timestamp ? Date.parse(payload.timestamp) : undefined,
|
||||
color: payload.color,
|
||||
footer: (payload.footer)
|
||||
footer: payload.footer
|
||||
? {
|
||||
text: payload.footer.text,
|
||||
iconUrl: payload.footer.icon_url,
|
||||
proxyIconUrl: payload.footer.proxy_icon_url
|
||||
}
|
||||
: undefined,
|
||||
image: (payload.image)
|
||||
image: payload.image
|
||||
? {
|
||||
url: payload.image.url,
|
||||
proxyUrl: payload.image.proxy_url,
|
||||
@@ -24,7 +25,7 @@ export function transformEmbed (bot: Bot, payload: DiscordEmbed) {
|
||||
width: payload.image.width
|
||||
}
|
||||
: undefined,
|
||||
thumbnail: (payload.thumbnail)
|
||||
thumbnail: payload.thumbnail
|
||||
? {
|
||||
url: payload.thumbnail.url,
|
||||
proxyUrl: payload.thumbnail.proxy_url,
|
||||
@@ -32,7 +33,7 @@ export function transformEmbed (bot: Bot, payload: DiscordEmbed) {
|
||||
width: payload.thumbnail.width
|
||||
}
|
||||
: undefined,
|
||||
video: (payload.video)
|
||||
video: payload.video
|
||||
? {
|
||||
url: payload.video.url,
|
||||
proxyUrl: payload.video.proxy_url,
|
||||
@@ -41,7 +42,7 @@ export function transformEmbed (bot: Bot, payload: DiscordEmbed) {
|
||||
}
|
||||
: undefined,
|
||||
provider: payload.provider,
|
||||
author: (payload.author)
|
||||
author: payload.author
|
||||
? {
|
||||
name: payload.author.name,
|
||||
url: payload.author.url,
|
||||
@@ -55,4 +56,4 @@ export function transformEmbed (bot: Bot, payload: DiscordEmbed) {
|
||||
return embed as Optionalize<typeof embed>
|
||||
}
|
||||
|
||||
export interface Embed extends ReturnType<typeof transformEmbed> { }
|
||||
export interface Embed extends ReturnType<typeof transformEmbed> {}
|
||||
|
||||
@@ -2,16 +2,17 @@ import { DiscordEmoji, Optionalize } from '@discordeno/types'
|
||||
import { Bot } from '../bot.js'
|
||||
import { EmojiToggles } from './toggles/emoji.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformEmoji (bot: Bot, payload: DiscordEmoji) {
|
||||
const emoji = {
|
||||
id: payload.id ? bot.transformers.snowflake(payload.id) : undefined,
|
||||
name: payload.name || undefined,
|
||||
name: payload.name,
|
||||
roles: payload.roles?.map((id) => bot.transformers.snowflake(id)),
|
||||
user: (payload.user) ? bot.transformers.user(bot, payload.user) : undefined,
|
||||
user: payload.user ? bot.transformers.user(bot, payload.user) : undefined,
|
||||
toggles: new EmojiToggles(payload)
|
||||
}
|
||||
|
||||
return emoji as Optionalize<typeof emoji>
|
||||
}
|
||||
|
||||
export interface Emoji extends ReturnType<typeof transformEmoji> { }
|
||||
export interface Emoji extends ReturnType<typeof transformEmoji> {}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { DiscordIntegrationCreateUpdate, Optionalize } from '@discordeno/types'
|
||||
import { Bot } from '../bot.js'
|
||||
|
||||
export function transformIntegration (bot: Bot, payload: DiscordIntegrationCreateUpdate) {
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformIntegration (
|
||||
bot: Bot,
|
||||
payload: DiscordIntegrationCreateUpdate
|
||||
) {
|
||||
const integration = {
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
@@ -9,11 +13,13 @@ export function transformIntegration (bot: Bot, payload: DiscordIntegrationCreat
|
||||
type: payload.type,
|
||||
enabled: payload.enabled,
|
||||
syncing: payload.syncing,
|
||||
roleId: payload.role_id ? bot.transformers.snowflake(payload.role_id) : undefined,
|
||||
roleId: payload.role_id
|
||||
? bot.transformers.snowflake(payload.role_id)
|
||||
: undefined,
|
||||
enableEmoticons: payload.enable_emoticons,
|
||||
expireBehavior: payload.expire_behavior,
|
||||
expireGracePeriod: payload.expire_grace_period,
|
||||
user: (payload.user) ? bot.transformers.user(bot, payload.user) : undefined,
|
||||
user: payload.user ? bot.transformers.user(bot, payload.user) : undefined,
|
||||
account: {
|
||||
id: bot.transformers.snowflake(payload.account.id),
|
||||
name: payload.account.name
|
||||
@@ -21,13 +27,17 @@ export function transformIntegration (bot: Bot, payload: DiscordIntegrationCreat
|
||||
syncedAt: payload.synced_at ? Date.parse(payload.synced_at) : undefined,
|
||||
subscriberCount: payload.subscriber_count,
|
||||
revoked: payload.revoked,
|
||||
application: (payload.application)
|
||||
application: payload.application
|
||||
? {
|
||||
id: bot.transformers.snowflake(payload.application.id),
|
||||
name: payload.application.name,
|
||||
icon: payload.application.icon ? bot.utils.iconHashToBigInt(payload.application.icon) : undefined,
|
||||
icon: payload.application.icon
|
||||
? bot.utils.iconHashToBigInt(payload.application.icon)
|
||||
: undefined,
|
||||
description: payload.application.description,
|
||||
bot: (payload.application.bot) ? bot.transformers.user(bot, payload.application.bot) : undefined
|
||||
bot: payload.application.bot
|
||||
? bot.transformers.user(bot, payload.application.bot)
|
||||
: undefined
|
||||
}
|
||||
: undefined,
|
||||
scopes: payload.scopes
|
||||
@@ -36,4 +46,4 @@ export function transformIntegration (bot: Bot, payload: DiscordIntegrationCreat
|
||||
return integration as Optionalize<typeof integration>
|
||||
}
|
||||
|
||||
export interface Integration extends ReturnType<typeof transformIntegration> { }
|
||||
export interface Integration extends ReturnType<typeof transformIntegration> {}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { DiscordInviteCreate, Optionalize } from '@discordeno/types'
|
||||
import { Bot } from '../bot.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformInvite (bot: Bot, invite: DiscordInviteCreate) {
|
||||
const transformedInvite = {
|
||||
/** The channel the invite is for */
|
||||
@@ -10,9 +11,13 @@ export function transformInvite (bot: Bot, invite: DiscordInviteCreate) {
|
||||
/** The time at which the invite was created */
|
||||
createdAt: Date.parse(invite.created_at),
|
||||
/** The guild of the invite */
|
||||
guildId: invite.guild_id ? bot.transformers.snowflake(invite.guild_id) : undefined,
|
||||
guildId: invite.guild_id
|
||||
? bot.transformers.snowflake(invite.guild_id)
|
||||
: undefined,
|
||||
/** The user that created the invite */
|
||||
inviter: (invite.inviter) ? bot.transformers.user(bot, invite.inviter) : undefined,
|
||||
inviter: invite.inviter
|
||||
? bot.transformers.user(bot, invite.inviter)
|
||||
: undefined,
|
||||
/** How long the invite is valid for (in seconds) */
|
||||
maxAge: invite.max_age,
|
||||
/** The maximum number of times the invite can be used */
|
||||
@@ -20,10 +25,12 @@ export function transformInvite (bot: Bot, invite: DiscordInviteCreate) {
|
||||
/** The type of target for this voice channel invite */
|
||||
targetType: invite.target_type,
|
||||
/** The target user for this invite */
|
||||
targetUser: (invite.target_user) ? bot.transformers.user(bot, invite.target_user) : undefined,
|
||||
targetUser: invite.target_user
|
||||
? bot.transformers.user(bot, invite.target_user)
|
||||
: undefined,
|
||||
/** The embedded application to open for this voice channel embedded application invite */
|
||||
targetApplication: (invite.target_application)
|
||||
// @ts-expect-error should not break anything even though its partial. if it does blame wolf :)
|
||||
// @ts-expect-error should not break anything even though its partial. if it does blame wolf :)
|
||||
targetApplication: invite.target_application
|
||||
? bot.transformers.application(bot, invite.target_application)
|
||||
: undefined,
|
||||
/** Whether or not the invite is temporary (invited users will be kicked on disconnect unless they're assigned a role) */
|
||||
@@ -35,4 +42,4 @@ export function transformInvite (bot: Bot, invite: DiscordInviteCreate) {
|
||||
return transformedInvite as Optionalize<typeof transformedInvite>
|
||||
}
|
||||
|
||||
export interface Invite extends ReturnType<typeof transformInvite> { }
|
||||
export interface Invite extends ReturnType<typeof transformInvite> {}
|
||||
|
||||
@@ -3,12 +3,15 @@ import type { Bot } from '../bot.js'
|
||||
import { MemberToggles } from './toggles/member.js'
|
||||
import { UserToggles } from './toggles/user.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformUser (bot: Bot, payload: DiscordUser) {
|
||||
const user = {
|
||||
id: bot.transformers.snowflake(payload.id || ''),
|
||||
username: payload.username,
|
||||
discriminator: payload.discriminator,
|
||||
avatar: payload.avatar ? bot.utils.iconHashToBigInt(payload.avatar) : undefined,
|
||||
avatar: payload.avatar
|
||||
? bot.utils.iconHashToBigInt(payload.avatar)
|
||||
: undefined,
|
||||
locale: payload.locale,
|
||||
email: payload.email ?? undefined,
|
||||
flags: payload.flags,
|
||||
@@ -20,17 +23,29 @@ export function transformUser (bot: Bot, payload: DiscordUser) {
|
||||
return user as Optionalize<typeof user>
|
||||
}
|
||||
|
||||
export function transformMember (bot: Bot, payload: DiscordMember, guildId: bigint, userId: bigint) {
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformMember (
|
||||
bot: Bot,
|
||||
payload: DiscordMember,
|
||||
guildId: bigint,
|
||||
userId: bigint
|
||||
) {
|
||||
const member = {
|
||||
id: userId,
|
||||
guildId,
|
||||
user: (payload.user) ? bot.transformers.user(bot, payload.user) : undefined,
|
||||
user: payload.user ? bot.transformers.user(bot, payload.user) : undefined,
|
||||
nick: payload.nick ?? undefined,
|
||||
roles: payload.roles.map((id) => bot.transformers.snowflake(id)),
|
||||
joinedAt: Date.parse(payload.joined_at),
|
||||
premiumSince: payload.premium_since ? Date.parse(payload.premium_since) : undefined,
|
||||
avatar: payload.avatar ? bot.utils.iconHashToBigInt(payload.avatar) : undefined,
|
||||
permissions: payload.permissions ? bot.transformers.snowflake(payload.permissions) : undefined,
|
||||
premiumSince: payload.premium_since
|
||||
? Date.parse(payload.premium_since)
|
||||
: undefined,
|
||||
avatar: payload.avatar
|
||||
? bot.utils.iconHashToBigInt(payload.avatar)
|
||||
: undefined,
|
||||
permissions: payload.permissions
|
||||
? bot.transformers.snowflake(payload.permissions)
|
||||
: undefined,
|
||||
communicationDisabledUntil: payload.communication_disabled_until
|
||||
? Date.parse(payload.communication_disabled_until)
|
||||
: undefined,
|
||||
@@ -40,5 +55,5 @@ export function transformMember (bot: Bot, payload: DiscordMember, guildId: bigi
|
||||
return member as Optionalize<typeof member>
|
||||
}
|
||||
|
||||
export interface Member extends ReturnType<typeof transformMember> { }
|
||||
export interface User extends ReturnType<typeof transformUser> { }
|
||||
export interface Member extends ReturnType<typeof transformMember> {}
|
||||
export interface User extends ReturnType<typeof transformUser> {}
|
||||
|
||||
@@ -5,18 +5,27 @@ import { MemberToggles } from './toggles/member.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformMessage (bot: Bot, payload: DiscordMessage) {
|
||||
const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined
|
||||
const guildId = payload.guild_id
|
||||
? bot.transformers.snowflake(payload.guild_id)
|
||||
: undefined
|
||||
const userId = bot.transformers.snowflake(payload.author.id)
|
||||
|
||||
const message = {
|
||||
// UNTRANSFORMED STUFF HERE
|
||||
content: payload.content || '',
|
||||
isFromBot: payload.author.bot || false,
|
||||
content: payload.content ?? '',
|
||||
isFromBot: payload.author.bot ?? false,
|
||||
tag: `${payload.author.username}#${payload.author.discriminator}`,
|
||||
timestamp: Date.parse(payload.timestamp),
|
||||
editedTimestamp: payload.edited_timestamp ? Date.parse(payload.edited_timestamp) : undefined,
|
||||
bitfield: (payload.tts ? 1n : 0n) | (payload.mention_everyone ? 2n : 0n) | (payload.pinned ? 4n : 0n),
|
||||
attachments: payload.attachments?.map((attachment) => bot.transformers.attachment(bot, attachment)),
|
||||
editedTimestamp: payload.edited_timestamp
|
||||
? Date.parse(payload.edited_timestamp)
|
||||
: undefined,
|
||||
bitfield:
|
||||
(payload.tts ? 1n : 0n) |
|
||||
(payload.mention_everyone ? 2n : 0n) |
|
||||
(payload.pinned ? 4n : 0n),
|
||||
attachments: payload.attachments?.map((attachment) =>
|
||||
bot.transformers.attachment(bot, attachment)
|
||||
),
|
||||
embeds: payload.embeds?.map((embed) => bot.transformers.embed(bot, embed)),
|
||||
reactions: payload.reactions?.map((reaction) => ({
|
||||
me: reaction.me,
|
||||
@@ -24,7 +33,7 @@ export function transformMessage (bot: Bot, payload: DiscordMessage) {
|
||||
emoji: bot.transformers.emoji(bot, reaction.emoji)
|
||||
})),
|
||||
type: payload.type,
|
||||
activity: (payload.activity)
|
||||
activity: payload.activity
|
||||
? {
|
||||
type: payload.activity.type,
|
||||
partyId: payload.activity.party_id
|
||||
@@ -32,18 +41,20 @@ export function transformMessage (bot: Bot, payload: DiscordMessage) {
|
||||
: undefined,
|
||||
application: payload.application,
|
||||
flags: payload.flags,
|
||||
interaction: (payload.interaction)
|
||||
interaction: payload.interaction
|
||||
? {
|
||||
id: bot.transformers.snowflake(payload.interaction.id),
|
||||
type: payload.interaction.type,
|
||||
name: payload.interaction.name,
|
||||
user: bot.transformers.user(bot, payload.interaction.user),
|
||||
member: (payload.interaction.member)
|
||||
member: payload.interaction.member
|
||||
? {
|
||||
id: userId,
|
||||
guildId,
|
||||
nick: payload.interaction.member.nick ?? undefined,
|
||||
roles: payload.interaction.member.roles?.map((id) => bot.transformers.snowflake(id)),
|
||||
roles: payload.interaction.member.roles?.map((id) =>
|
||||
bot.transformers.snowflake(id)
|
||||
),
|
||||
joinedAt: payload.interaction.member.joined_at
|
||||
? Date.parse(payload.interaction.member.joined_at)
|
||||
: undefined,
|
||||
@@ -52,20 +63,31 @@ export function transformMessage (bot: Bot, payload: DiscordMessage) {
|
||||
: undefined,
|
||||
toggles: new MemberToggles(payload.interaction.member),
|
||||
avatar: payload.interaction.member.avatar
|
||||
? bot.utils.iconHashToBigInt(payload.interaction.member.avatar)
|
||||
? bot.utils.iconHashToBigInt(
|
||||
payload.interaction.member.avatar
|
||||
)
|
||||
: undefined,
|
||||
permissions: payload.interaction.member.permissions
|
||||
? bot.transformers.snowflake(payload.interaction.member.permissions)
|
||||
? bot.transformers.snowflake(
|
||||
payload.interaction.member.permissions
|
||||
)
|
||||
: undefined,
|
||||
communicationDisabledUntil: payload.interaction.member.communication_disabled_until
|
||||
? Date.parse(payload.interaction.member.communication_disabled_until)
|
||||
communicationDisabledUntil: payload.interaction.member
|
||||
.communication_disabled_until
|
||||
? Date.parse(
|
||||
payload.interaction.member.communication_disabled_until
|
||||
)
|
||||
: undefined
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
: undefined,
|
||||
thread: (payload.thread) ? bot.transformers.channel(bot, { channel: payload.thread, guildId }) : undefined,
|
||||
components: payload.components?.map((component) => bot.transformers.component(bot, component)),
|
||||
thread: payload.thread
|
||||
? bot.transformers.channel(bot, { channel: payload.thread, guildId })
|
||||
: undefined,
|
||||
components: payload.components?.map((component) =>
|
||||
bot.transformers.component(bot, component)
|
||||
),
|
||||
stickerItems: payload.sticker_items?.map((sticker) => ({
|
||||
id: bot.transformers.snowflake(sticker.id),
|
||||
name: sticker.name,
|
||||
@@ -76,10 +98,14 @@ export function transformMessage (bot: Bot, payload: DiscordMessage) {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
guildId,
|
||||
channelId: bot.transformers.snowflake(payload.channel_id),
|
||||
webhookId: payload.webhook_id ? bot.transformers.snowflake(payload.webhook_id) : undefined,
|
||||
webhookId: payload.webhook_id
|
||||
? bot.transformers.snowflake(payload.webhook_id)
|
||||
: undefined,
|
||||
authorId: userId,
|
||||
applicationId: payload.application_id ? bot.transformers.snowflake(payload.application_id) : undefined,
|
||||
messageReference: (payload.message_reference)
|
||||
applicationId: payload.application_id
|
||||
? bot.transformers.snowflake(payload.application_id)
|
||||
: undefined,
|
||||
messageReference: payload.message_reference
|
||||
? {
|
||||
messageId: payload.message_reference.message_id
|
||||
? bot.transformers.snowflake(payload.message_reference.message_id)
|
||||
@@ -92,22 +118,31 @@ export function transformMessage (bot: Bot, payload: DiscordMessage) {
|
||||
: undefined
|
||||
}
|
||||
: undefined,
|
||||
mentionedUserIds: (payload.mentions) ? payload.mentions.map((m) => bot.transformers.snowflake(m.id)) : [],
|
||||
mentionedRoleIds: (payload.mention_roles) ? payload.mention_roles.map((id) => bot.transformers.snowflake(id)) : [],
|
||||
mentionedUserIds: payload.mentions
|
||||
? payload.mentions.map((m) => bot.transformers.snowflake(m.id))
|
||||
: [],
|
||||
mentionedRoleIds: payload.mention_roles
|
||||
? payload.mention_roles.map((id) => bot.transformers.snowflake(id))
|
||||
: [],
|
||||
mentionedChannelIds: [
|
||||
// Keep any ids tht discord sends
|
||||
...(payload.mention_channels ?? []).map((m) => bot.transformers.snowflake(m.id)),
|
||||
...(payload.mention_channels ?? []).map((m) =>
|
||||
bot.transformers.snowflake(m.id)
|
||||
),
|
||||
// Add any other ids that can be validated in a channel mention format
|
||||
...(payload.content?.match(CHANNEL_MENTION_REGEX) ?? []).map((text) =>
|
||||
// converts the <#123> into 123
|
||||
bot.transformers.snowflake(text.substring(2, text.length - 1))
|
||||
)
|
||||
],
|
||||
member: (payload.member) && guildId ? bot.transformers.member(bot, payload.member, guildId, userId) : undefined,
|
||||
member:
|
||||
payload.member && guildId
|
||||
? bot.transformers.member(bot, payload.member, guildId, userId)
|
||||
: undefined,
|
||||
nonce: payload.nonce
|
||||
}
|
||||
|
||||
return message as Optionalize<typeof message>
|
||||
}
|
||||
|
||||
export interface Message extends ReturnType<typeof transformMessage> { }
|
||||
export interface Message extends ReturnType<typeof transformMessage> {}
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
import { DiscordPresenceUpdate, Optionalize, PresenceStatus } from '@discordeno/types'
|
||||
import {
|
||||
DiscordPresenceUpdate,
|
||||
Optionalize,
|
||||
PresenceStatus
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../bot.js'
|
||||
import { UserToggles } from './toggles/user.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformPresence (bot: Bot, payload: DiscordPresenceUpdate) {
|
||||
const presence = {
|
||||
user: {
|
||||
id: bot.transformers.snowflake(payload.user.id || ''),
|
||||
username: payload.user.username ?? undefined,
|
||||
discriminator: payload.user.discriminator ?? undefined,
|
||||
avatar: payload.user.avatar ? bot.utils.iconHashToBigInt(payload.user.avatar) : undefined,
|
||||
avatar: payload.user.avatar
|
||||
? bot.utils.iconHashToBigInt(payload.user.avatar)
|
||||
: undefined,
|
||||
locale: payload.user.locale ?? undefined,
|
||||
email: payload.user.email ?? undefined,
|
||||
flags: payload.user.flags ?? undefined,
|
||||
@@ -18,7 +25,9 @@ export function transformPresence (bot: Bot, payload: DiscordPresenceUpdate) {
|
||||
},
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
status: PresenceStatus[payload.status],
|
||||
activities: payload.activities.map((activity) => bot.transformers.activity(bot, activity)),
|
||||
activities: payload.activities.map((activity) =>
|
||||
bot.transformers.activity(bot, activity)
|
||||
),
|
||||
desktop: payload.client_status.desktop,
|
||||
mobile: payload.client_status.mobile,
|
||||
web: payload.client_status.web
|
||||
@@ -27,4 +36,4 @@ export function transformPresence (bot: Bot, payload: DiscordPresenceUpdate) {
|
||||
return presence as Optionalize<typeof presence>
|
||||
}
|
||||
|
||||
export interface PresenceUpdate extends ReturnType<typeof transformPresence> { }
|
||||
export interface PresenceUpdate extends ReturnType<typeof transformPresence> {}
|
||||
|
||||
@@ -2,12 +2,17 @@ import { DiscordEmoji } from '@discordeno/types'
|
||||
import { Bot } from '../../bot.js'
|
||||
import { Emoji } from '../emoji.js'
|
||||
|
||||
export function transformEmojiToDiscordEmoji (bot: Bot, payload: Emoji): DiscordEmoji {
|
||||
export function transformEmojiToDiscordEmoji (
|
||||
bot: Bot,
|
||||
payload: Emoji
|
||||
): DiscordEmoji {
|
||||
return {
|
||||
id: payload.id ? bot.transformers.reverse.snowflake(payload.id) : undefined,
|
||||
name: payload.name || undefined,
|
||||
name: payload.name,
|
||||
roles: payload.roles?.map((id) => bot.transformers.reverse.snowflake(id)),
|
||||
user: (payload.user) ? bot.transformers.reverse.user(bot, payload.user) : undefined,
|
||||
user: payload.user
|
||||
? bot.transformers.reverse.user(bot, payload.user)
|
||||
: undefined,
|
||||
require_colons: payload.toggles.requireColons,
|
||||
managed: payload.toggles.managed,
|
||||
animated: payload.toggles.animated,
|
||||
|
||||
@@ -2,7 +2,11 @@ import { DiscordRole, Optionalize } from '@discordeno/types'
|
||||
import { Bot } from '../bot.js'
|
||||
import { RoleToggles } from './toggles/role.js'
|
||||
|
||||
export function transformRole (bot: Bot, payload: { role: DiscordRole } & { guildId: bigint }) {
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformRole (
|
||||
bot: Bot,
|
||||
payload: { role: DiscordRole } & { guildId: bigint }
|
||||
) {
|
||||
const role = {
|
||||
name: payload.role.name,
|
||||
guildId: payload.guildId,
|
||||
@@ -11,16 +15,20 @@ export function transformRole (bot: Bot, payload: { role: DiscordRole } & { guil
|
||||
toggles: new RoleToggles(payload.role),
|
||||
|
||||
id: bot.transformers.snowflake(payload.role.id),
|
||||
botId: payload.role.tags?.bot_id ? bot.transformers.snowflake(payload.role.tags.bot_id) : undefined,
|
||||
botId: payload.role.tags?.bot_id
|
||||
? bot.transformers.snowflake(payload.role.tags.bot_id)
|
||||
: undefined,
|
||||
integrationId: payload.role.tags?.integration_id
|
||||
? bot.transformers.snowflake(payload.role.tags.integration_id)
|
||||
: undefined,
|
||||
permissions: bot.transformers.snowflake(payload.role.permissions),
|
||||
icon: payload.role.icon ? bot.utils.iconHashToBigInt(payload.role.icon) : undefined,
|
||||
icon: payload.role.icon
|
||||
? bot.utils.iconHashToBigInt(payload.role.icon)
|
||||
: undefined,
|
||||
unicodeEmoji: payload.role.unicode_emoji
|
||||
}
|
||||
|
||||
return role as Optionalize<typeof role>
|
||||
}
|
||||
|
||||
export interface Role extends ReturnType<typeof transformRole> { }
|
||||
export interface Role extends ReturnType<typeof transformRole> {}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { DiscordScheduledEvent, Optionalize } from '@discordeno/types'
|
||||
import { Bot } from '../bot.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformScheduledEvent (
|
||||
bot: Bot,
|
||||
payload: DiscordScheduledEvent
|
||||
@@ -8,24 +9,37 @@ export function transformScheduledEvent (
|
||||
const scheduledEvent = {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
channelId: payload.channel_id ? bot.transformers.snowflake(payload.channel_id) : undefined,
|
||||
creatorId: payload.creator_id ? bot.transformers.snowflake(payload.creator_id) : 0n,
|
||||
channelId: payload.channel_id
|
||||
? bot.transformers.snowflake(payload.channel_id)
|
||||
: undefined,
|
||||
creatorId: payload.creator_id
|
||||
? bot.transformers.snowflake(payload.creator_id)
|
||||
: 0n,
|
||||
scheduledStartTime: Date.parse(payload.scheduled_start_time),
|
||||
scheduledEndTime: payload.scheduled_end_time ? Date.parse(payload.scheduled_end_time) : undefined,
|
||||
entityId: payload.entity_id ? bot.transformers.snowflake(payload.entity_id) : undefined,
|
||||
creator: (payload.creator) ? bot.transformers.user(bot, payload.creator) : undefined,
|
||||
scheduledEndTime: payload.scheduled_end_time
|
||||
? Date.parse(payload.scheduled_end_time)
|
||||
: undefined,
|
||||
entityId: payload.entity_id
|
||||
? bot.transformers.snowflake(payload.entity_id)
|
||||
: undefined,
|
||||
creator: payload.creator
|
||||
? bot.transformers.user(bot, payload.creator)
|
||||
: undefined,
|
||||
|
||||
name: payload.name,
|
||||
description: payload.description,
|
||||
privacyLevel: payload.privacy_level,
|
||||
status: payload.status,
|
||||
entityType: payload.entity_type,
|
||||
userCount: payload.user_count || 0,
|
||||
userCount: payload.user_count ?? 0,
|
||||
location: payload.entity_metadata?.location,
|
||||
image: payload.image ? bot.utils.iconHashToBigInt(payload.image) : undefined
|
||||
image: payload.image
|
||||
? bot.utils.iconHashToBigInt(payload.image)
|
||||
: undefined
|
||||
}
|
||||
|
||||
return scheduledEvent as Optionalize<typeof scheduledEvent>
|
||||
}
|
||||
|
||||
export interface ScheduledEvent extends ReturnType<typeof transformScheduledEvent> { }
|
||||
export interface ScheduledEvent
|
||||
extends ReturnType<typeof transformScheduledEvent> {}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { DiscordStageInstance, Optionalize } from '@discordeno/types'
|
||||
import { Bot } from '../bot.js'
|
||||
|
||||
export function transformStageInstance (bot: Bot, payload: DiscordStageInstance) {
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformStageInstance (
|
||||
bot: Bot,
|
||||
payload: DiscordStageInstance
|
||||
) {
|
||||
const stageInstance = {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
@@ -15,4 +19,5 @@ export function transformStageInstance (bot: Bot, payload: DiscordStageInstance)
|
||||
return stageInstance as Optionalize<typeof stageInstance>
|
||||
}
|
||||
|
||||
export interface StageInstance extends ReturnType<typeof transformStageInstance> { }
|
||||
export interface StageInstance
|
||||
extends ReturnType<typeof transformStageInstance> {}
|
||||
|
||||
@@ -1,37 +1,53 @@
|
||||
import { DiscordSticker, DiscordStickerPack, Optionalize } from '@discordeno/types'
|
||||
import {
|
||||
DiscordSticker,
|
||||
DiscordStickerPack,
|
||||
Optionalize
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../bot.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformSticker (bot: Bot, payload: DiscordSticker) {
|
||||
const sticker = {
|
||||
id: bot.utils.snowflakeToBigint(payload.id),
|
||||
packId: payload.pack_id ? bot.utils.snowflakeToBigint(payload.pack_id) : undefined,
|
||||
packId: payload.pack_id
|
||||
? bot.utils.snowflakeToBigint(payload.pack_id)
|
||||
: undefined,
|
||||
name: payload.name,
|
||||
description: payload.description,
|
||||
tags: payload.tags,
|
||||
type: payload.type,
|
||||
formatType: payload.format_type,
|
||||
available: payload.available,
|
||||
guildId: payload.guild_id ? bot.utils.snowflakeToBigint(payload.guild_id) : undefined,
|
||||
user: (payload.user) ? bot.transformers.user(bot, payload.user) : undefined,
|
||||
guildId: payload.guild_id
|
||||
? bot.utils.snowflakeToBigint(payload.guild_id)
|
||||
: undefined,
|
||||
user: payload.user ? bot.transformers.user(bot, payload.user) : undefined,
|
||||
sortValue: payload.sort_value
|
||||
}
|
||||
|
||||
return sticker as Optionalize<typeof sticker>
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformStickerPack (bot: Bot, payload: DiscordStickerPack) {
|
||||
const pack = {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
stickers: payload.stickers.map((sticker) => bot.transformers.sticker(bot, sticker)),
|
||||
stickers: payload.stickers.map((sticker) =>
|
||||
bot.transformers.sticker(bot, sticker)
|
||||
),
|
||||
name: payload.name,
|
||||
skuId: bot.transformers.snowflake(payload.sku_id),
|
||||
coverStickerId: payload.cover_sticker_id ? bot.transformers.snowflake(payload.cover_sticker_id) : undefined,
|
||||
coverStickerId: payload.cover_sticker_id
|
||||
? bot.transformers.snowflake(payload.cover_sticker_id)
|
||||
: undefined,
|
||||
description: payload.description,
|
||||
bannerAssetId: payload.banner_asset_id ? bot.transformers.snowflake(payload.banner_asset_id) : undefined
|
||||
bannerAssetId: payload.banner_asset_id
|
||||
? bot.transformers.snowflake(payload.banner_asset_id)
|
||||
: undefined
|
||||
}
|
||||
|
||||
return pack as Optionalize<typeof pack>
|
||||
}
|
||||
|
||||
export interface Sticker extends ReturnType<typeof transformSticker> { }
|
||||
export interface StickerPack extends ReturnType<typeof transformStickerPack> { }
|
||||
export interface Sticker extends ReturnType<typeof transformSticker> {}
|
||||
export interface StickerPack extends ReturnType<typeof transformStickerPack> {}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { DiscordTeam, Optionalize } from '@discordeno/types'
|
||||
import { Bot } from '../bot.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformTeam (bot: Bot, payload: DiscordTeam) {
|
||||
const id = bot.transformers.snowflake(payload.id)
|
||||
|
||||
@@ -21,4 +22,4 @@ export function transformTeam (bot: Bot, payload: DiscordTeam) {
|
||||
return team as Optionalize<typeof team>
|
||||
}
|
||||
|
||||
export interface Team extends ReturnType<typeof transformTeam> { }
|
||||
export interface Team extends ReturnType<typeof transformTeam> {}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { DiscordTemplate, Optionalize } from '@discordeno/types'
|
||||
import { Bot } from '../bot.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformTemplate (bot: Bot, payload: DiscordTemplate) {
|
||||
const template = {
|
||||
code: payload.code,
|
||||
@@ -19,4 +20,4 @@ export function transformTemplate (bot: Bot, payload: DiscordTemplate) {
|
||||
return template as Optionalize<typeof template>
|
||||
}
|
||||
|
||||
export interface Template extends ReturnType<typeof transformTemplate> { }
|
||||
export interface Template extends ReturnType<typeof transformTemplate> {}
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import { DiscordThreadMember, DiscordThreadMemberGuildCreate, Optionalize } from '@discordeno/types'
|
||||
import {
|
||||
DiscordThreadMember,
|
||||
DiscordThreadMemberGuildCreate,
|
||||
Optionalize
|
||||
} from '@discordeno/types'
|
||||
import { Bot } from '../bot.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformThreadMember (bot: Bot, payload: DiscordThreadMember) {
|
||||
const threadMember = {
|
||||
id: payload.id ? bot.transformers.snowflake(payload.id) : undefined,
|
||||
userId: payload.user_id ? bot.transformers.snowflake(payload.user_id) : undefined,
|
||||
userId: payload.user_id
|
||||
? bot.transformers.snowflake(payload.user_id)
|
||||
: undefined,
|
||||
joinTimestamp: Date.parse(payload.join_timestamp),
|
||||
flags: payload.flags
|
||||
}
|
||||
@@ -12,7 +19,11 @@ export function transformThreadMember (bot: Bot, payload: DiscordThreadMember) {
|
||||
return threadMember as Optionalize<typeof threadMember>
|
||||
}
|
||||
|
||||
export function transformThreadMemberGuildCreate (bot: Bot, payload: DiscordThreadMemberGuildCreate) {
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformThreadMemberGuildCreate (
|
||||
bot: Bot,
|
||||
payload: DiscordThreadMemberGuildCreate
|
||||
) {
|
||||
const threadMember = {
|
||||
joinTimestamp: Date.parse(payload.join_timestamp)
|
||||
}
|
||||
@@ -20,5 +31,7 @@ export function transformThreadMemberGuildCreate (bot: Bot, payload: DiscordThre
|
||||
return threadMember as Optionalize<typeof threadMember>
|
||||
}
|
||||
|
||||
export interface ThreadMember extends ReturnType<typeof transformThreadMember> { }
|
||||
export interface ThreadMemberGuildCreate extends ReturnType<typeof transformThreadMemberGuildCreate> { }
|
||||
export interface ThreadMember
|
||||
extends ReturnType<typeof transformThreadMember> {}
|
||||
export interface ThreadMemberGuildCreate
|
||||
extends ReturnType<typeof transformThreadMemberGuildCreate> {}
|
||||
|
||||
@@ -6,18 +6,18 @@ export class ToggleBitfield {
|
||||
}
|
||||
|
||||
/** Tests whether or not this bitfield has the permission requested. */
|
||||
contains (bits: number) {
|
||||
contains (bits: number): boolean {
|
||||
return Boolean(this.bitfield & bits)
|
||||
}
|
||||
|
||||
/** Adds some bits to the bitfield. */
|
||||
add (bits: number) {
|
||||
add (bits: number): this {
|
||||
this.bitfield |= bits
|
||||
return this
|
||||
}
|
||||
|
||||
/** Removes some bits from the bitfield. */
|
||||
remove (bits: number) {
|
||||
remove (bits: number): this {
|
||||
this.bitfield &= ~bits
|
||||
return this
|
||||
}
|
||||
@@ -31,18 +31,18 @@ export class ToggleBitfieldBigint {
|
||||
}
|
||||
|
||||
/** Tests whether or not this bitfield has the permission requested. */
|
||||
contains (bits: bigint) {
|
||||
contains (bits: bigint): boolean {
|
||||
return Boolean(this.bitfield & bits)
|
||||
}
|
||||
|
||||
/** Adds some bits to the bitfield. */
|
||||
add (bits: bigint) {
|
||||
add (bits: bigint): this {
|
||||
this.bitfield |= bits
|
||||
return this
|
||||
}
|
||||
|
||||
/** Removes some bits from the bitfield. */
|
||||
remove (bits: bigint) {
|
||||
remove (bits: bigint): this {
|
||||
this.bitfield &= ~bits
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -28,40 +28,42 @@ export class EmojiToggles extends ToggleBitfield {
|
||||
}
|
||||
|
||||
/** Whether this emoji must be wrapped in colons */
|
||||
get requireColons () {
|
||||
get requireColons (): boolean {
|
||||
return this.has('requireColons')
|
||||
}
|
||||
|
||||
/** Whether this emoji is managed */
|
||||
get managed () {
|
||||
get managed (): boolean {
|
||||
return this.has('managed')
|
||||
}
|
||||
|
||||
/** Whether this emoji is animated */
|
||||
get animated () {
|
||||
get animated (): boolean {
|
||||
return this.has('animated')
|
||||
}
|
||||
|
||||
/** Whether this emoji can be used, may be false due to loss of Server Boosts */
|
||||
get available () {
|
||||
get available (): boolean {
|
||||
return this.has('available')
|
||||
}
|
||||
|
||||
/** Checks whether or not the permissions exist in this */
|
||||
has (permissions: EmojiToggleKeys | EmojiToggleKeys[]) {
|
||||
if (!Array.isArray(permissions)) return super.contains(EmojiToggle[permissions])
|
||||
has (permissions: EmojiToggleKeys | EmojiToggleKeys[]): boolean {
|
||||
if (!Array.isArray(permissions)) { return super.contains(EmojiToggle[permissions]) }
|
||||
|
||||
return super.contains(permissions.reduce((a, b) => (a |= EmojiToggle[b]), 0))
|
||||
return super.contains(
|
||||
permissions.reduce((a, b) => (a |= EmojiToggle[b]), 0)
|
||||
)
|
||||
}
|
||||
|
||||
/** Lists all the toggles for the role and whether or not each is true or false. */
|
||||
list () {
|
||||
list (): Record<EmojiToggleKeys, boolean> {
|
||||
const json: Record<string, boolean> = {}
|
||||
for (const [key, value] of Object.entries(EmojiToggle)) {
|
||||
json[key] = super.contains(value)
|
||||
}
|
||||
|
||||
return json as Record<EmojiToggleKeys, boolean>
|
||||
return json
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,45 +93,46 @@ export class GuildToggles extends ToggleBitfieldBigint {
|
||||
constructor (guildOrTogglesBigint: DiscordGuild | bigint) {
|
||||
super()
|
||||
|
||||
if (typeof guildOrTogglesBigint === 'bigint') this.bitfield = guildOrTogglesBigint
|
||||
else {
|
||||
if (typeof guildOrTogglesBigint === 'bigint') { this.bitfield = guildOrTogglesBigint } else {
|
||||
const guild = guildOrTogglesBigint
|
||||
|
||||
if (guild.owner) this.add(GuildToggle.owner)
|
||||
if (guild.widget_enabled) this.add(GuildToggle.widgetEnabled)
|
||||
if (guild.large) this.add(GuildToggle.large)
|
||||
if (guild.unavailable) this.add(GuildToggle.unavailable)
|
||||
if (guild.premium_progress_bar_enabled) this.add(GuildToggle.premiumProgressBarEnabled)
|
||||
if (guild.premium_progress_bar_enabled) { this.add(GuildToggle.premiumProgressBarEnabled) }
|
||||
|
||||
if (guild.features.includes(GuildFeatures.InviteSplash)) this.add(GuildToggle.inviteSplash)
|
||||
if (guild.features.includes(GuildFeatures.VipRegions)) this.add(GuildToggle.vipRegions)
|
||||
if (guild.features.includes(GuildFeatures.VanityUrl)) this.add(GuildToggle.vanityUrl)
|
||||
if (guild.features.includes(GuildFeatures.Verified)) this.add(GuildToggle.verified)
|
||||
if (guild.features.includes(GuildFeatures.Partnered)) this.add(GuildToggle.partnered)
|
||||
if (guild.features.includes(GuildFeatures.Community)) this.add(GuildToggle.community)
|
||||
if (guild.features.includes(GuildFeatures.DeveloperSupportServer)) this.add(GuildToggle.developerSupportServer)
|
||||
if (guild.features.includes(GuildFeatures.AnimatedBanner)) this.add(GuildToggle.animatedBanner)
|
||||
if (guild.features.includes(GuildFeatures.News)) this.add(GuildToggle.news)
|
||||
if (guild.features.includes(GuildFeatures.Discoverable)) this.add(GuildToggle.discoverable)
|
||||
if (guild.features.includes(GuildFeatures.Featurable)) this.add(GuildToggle.featurable)
|
||||
if (guild.features.includes(GuildFeatures.AnimatedIcon)) this.add(GuildToggle.animatedIcon)
|
||||
if (guild.features.includes(GuildFeatures.Banner)) this.add(GuildToggle.banner)
|
||||
if (guild.features.includes(GuildFeatures.WelcomeScreenEnabled)) this.add(GuildToggle.welcomeScreenEnabled)
|
||||
if (guild.features.includes(GuildFeatures.MemberVerificationGateEnabled)) {
|
||||
if (guild.features.includes(GuildFeatures.InviteSplash)) { this.add(GuildToggle.inviteSplash) }
|
||||
if (guild.features.includes(GuildFeatures.VipRegions)) { this.add(GuildToggle.vipRegions) }
|
||||
if (guild.features.includes(GuildFeatures.VanityUrl)) { this.add(GuildToggle.vanityUrl) }
|
||||
if (guild.features.includes(GuildFeatures.Verified)) { this.add(GuildToggle.verified) }
|
||||
if (guild.features.includes(GuildFeatures.Partnered)) { this.add(GuildToggle.partnered) }
|
||||
if (guild.features.includes(GuildFeatures.Community)) { this.add(GuildToggle.community) }
|
||||
if (guild.features.includes(GuildFeatures.DeveloperSupportServer)) { this.add(GuildToggle.developerSupportServer) }
|
||||
if (guild.features.includes(GuildFeatures.AnimatedBanner)) { this.add(GuildToggle.animatedBanner) }
|
||||
if (guild.features.includes(GuildFeatures.News)) { this.add(GuildToggle.news) }
|
||||
if (guild.features.includes(GuildFeatures.Discoverable)) { this.add(GuildToggle.discoverable) }
|
||||
if (guild.features.includes(GuildFeatures.Featurable)) { this.add(GuildToggle.featurable) }
|
||||
if (guild.features.includes(GuildFeatures.AnimatedIcon)) { this.add(GuildToggle.animatedIcon) }
|
||||
if (guild.features.includes(GuildFeatures.Banner)) { this.add(GuildToggle.banner) }
|
||||
if (guild.features.includes(GuildFeatures.WelcomeScreenEnabled)) { this.add(GuildToggle.welcomeScreenEnabled) }
|
||||
if (
|
||||
guild.features.includes(GuildFeatures.MemberVerificationGateEnabled)
|
||||
) {
|
||||
this.add(GuildToggle.memberVerificationGateEnabled)
|
||||
}
|
||||
if (guild.features.includes(GuildFeatures.PreviewEnabled)) this.add(GuildToggle.previewEnabled)
|
||||
if (guild.features.includes(GuildFeatures.TicketedEventsEnabled)) this.add(GuildToggle.ticketedEventsEnabled)
|
||||
if (guild.features.includes(GuildFeatures.MonetizationEnabled)) this.add(GuildToggle.monetizationEnabled)
|
||||
if (guild.features.includes(GuildFeatures.MoreStickers)) this.add(GuildToggle.moreStickers)
|
||||
if (guild.features.includes(GuildFeatures.PrivateThreads)) this.add(GuildToggle.privateThreads)
|
||||
if (guild.features.includes(GuildFeatures.RoleIcons)) this.add(GuildToggle.roleIcons)
|
||||
if (guild.features.includes(GuildFeatures.AutoModeration)) this.add(GuildToggle.autoModeration)
|
||||
if (guild.features.includes(GuildFeatures.InvitesDisabled)) this.add(GuildToggle.invitesDisabled)
|
||||
if (guild.features.includes(GuildFeatures.PreviewEnabled)) { this.add(GuildToggle.previewEnabled) }
|
||||
if (guild.features.includes(GuildFeatures.TicketedEventsEnabled)) { this.add(GuildToggle.ticketedEventsEnabled) }
|
||||
if (guild.features.includes(GuildFeatures.MonetizationEnabled)) { this.add(GuildToggle.monetizationEnabled) }
|
||||
if (guild.features.includes(GuildFeatures.MoreStickers)) { this.add(GuildToggle.moreStickers) }
|
||||
if (guild.features.includes(GuildFeatures.PrivateThreads)) { this.add(GuildToggle.privateThreads) }
|
||||
if (guild.features.includes(GuildFeatures.RoleIcons)) { this.add(GuildToggle.roleIcons) }
|
||||
if (guild.features.includes(GuildFeatures.AutoModeration)) { this.add(GuildToggle.autoModeration) }
|
||||
if (guild.features.includes(GuildFeatures.InvitesDisabled)) { this.add(GuildToggle.invitesDisabled) }
|
||||
}
|
||||
}
|
||||
|
||||
get features () {
|
||||
get features (): GuildToggleKeys[] {
|
||||
const features: GuildToggleKeys[] = []
|
||||
for (const key of Object.keys(GuildToggle)) {
|
||||
if (!featureNames.includes(key)) continue
|
||||
@@ -144,160 +145,162 @@ export class GuildToggles extends ToggleBitfieldBigint {
|
||||
}
|
||||
|
||||
/** Whether the bot is the owner of the guild */
|
||||
get owner () {
|
||||
get owner (): boolean {
|
||||
return this.has('owner')
|
||||
}
|
||||
|
||||
/** Whether the server widget is enabled */
|
||||
get widgetEnabled () {
|
||||
get widgetEnabled (): boolean {
|
||||
return this.has('widgetEnabled')
|
||||
}
|
||||
|
||||
/** Whether this is considered a large guild */
|
||||
get large () {
|
||||
get large (): boolean {
|
||||
return this.has('large')
|
||||
}
|
||||
|
||||
/** Whether this guild is unavailable due to an outage */
|
||||
get unavailable () {
|
||||
get unavailable (): boolean {
|
||||
return this.has('unavailable')
|
||||
}
|
||||
|
||||
/** Whether the guild has the boost progress bar enabled */
|
||||
get premiumProgressBarEnabled () {
|
||||
get premiumProgressBarEnabled (): boolean {
|
||||
return this.has('premiumProgressBarEnabled')
|
||||
}
|
||||
|
||||
/** Whether the guild has access to set an invite splash background */
|
||||
get inviteSplash () {
|
||||
get inviteSplash (): boolean {
|
||||
return this.has('inviteSplash')
|
||||
}
|
||||
|
||||
/** Whether the guild has access to set 384 kbps bitrate in voice (previously VIP voice servers) */
|
||||
get vipRegions () {
|
||||
get vipRegions (): boolean {
|
||||
return this.has('vipRegions')
|
||||
}
|
||||
|
||||
/** Whether the guild has access to set a vanity URL */
|
||||
get vanityUrl () {
|
||||
get vanityUrl (): boolean {
|
||||
return this.has('vanityUrl')
|
||||
}
|
||||
|
||||
/** Whether the guild is verified */
|
||||
get verified () {
|
||||
get verified (): boolean {
|
||||
return this.has('verified')
|
||||
}
|
||||
|
||||
/** Whether the guild is partnered */
|
||||
get partnered () {
|
||||
get partnered (): boolean {
|
||||
return this.has('partnered')
|
||||
}
|
||||
|
||||
/** Whether the guild can enable welcome screen, Membership Screening, stage channels and discovery, and receives community updates */
|
||||
get community () {
|
||||
get community (): boolean {
|
||||
return this.has('community')
|
||||
}
|
||||
|
||||
/** Whether the Guild has been set as a support server on the App Directory */
|
||||
get developerSupportServer () {
|
||||
get developerSupportServer (): boolean {
|
||||
return this.has('developerSupportServer')
|
||||
}
|
||||
|
||||
/** Whether the guild has access to set an animated guild banner image */
|
||||
get animatedBanner () {
|
||||
get animatedBanner (): boolean {
|
||||
return this.has('animatedBanner')
|
||||
}
|
||||
|
||||
/** Whether the guild has access to create news channels */
|
||||
get news () {
|
||||
get news (): boolean {
|
||||
return this.has('news')
|
||||
}
|
||||
|
||||
/** Whether the guild is able to be discovered in the directory */
|
||||
get discoverable () {
|
||||
get discoverable (): boolean {
|
||||
return this.has('discoverable')
|
||||
}
|
||||
|
||||
/** Whether the guild is able to be featured in the directory */
|
||||
get featurable () {
|
||||
get featurable (): boolean {
|
||||
return this.has('featurable')
|
||||
}
|
||||
|
||||
/** Whether the guild has access to set an animated guild icon */
|
||||
get animatedIcon () {
|
||||
get animatedIcon (): boolean {
|
||||
return this.has('animatedIcon')
|
||||
}
|
||||
|
||||
/** Whether the guild has access to set a guild banner image */
|
||||
get banner () {
|
||||
get banner (): boolean {
|
||||
return this.has('banner')
|
||||
}
|
||||
|
||||
/** Whether the guild has enabled the welcome screen */
|
||||
get welcomeScreenEnabled () {
|
||||
get welcomeScreenEnabled (): boolean {
|
||||
return this.has('welcomeScreenEnabled')
|
||||
}
|
||||
|
||||
/** Whether the guild has enabled [Membership Screening](https://discord.com/developers/docs/resources/guild#membership-screening-object) */
|
||||
get memberVerificationGateEnabled () {
|
||||
get memberVerificationGateEnabled (): boolean {
|
||||
return this.has('memberVerificationGateEnabled')
|
||||
}
|
||||
|
||||
/** Whether the guild can be previewed before joining via Membership Screening or the directory */
|
||||
get previewEnabled () {
|
||||
get previewEnabled (): boolean {
|
||||
return this.has('previewEnabled')
|
||||
}
|
||||
|
||||
/** Whether the guild has enabled ticketed events */
|
||||
get ticketedEventsEnabled () {
|
||||
get ticketedEventsEnabled (): boolean {
|
||||
return this.has('ticketedEventsEnabled')
|
||||
}
|
||||
|
||||
/** Whether the guild has enabled monetization */
|
||||
get monetizationEnabled () {
|
||||
get monetizationEnabled (): boolean {
|
||||
return this.has('monetizationEnabled')
|
||||
}
|
||||
|
||||
/** Whether the guild has increased custom sticker slots */
|
||||
get moreStickers () {
|
||||
get moreStickers (): boolean {
|
||||
return this.has('moreStickers')
|
||||
}
|
||||
|
||||
/** Whether the guild has access to create private threads */
|
||||
get privateThreads () {
|
||||
get privateThreads (): boolean {
|
||||
return this.has('privateThreads')
|
||||
}
|
||||
|
||||
/** Whether the guild is able to set role icons */
|
||||
get roleIcons () {
|
||||
get roleIcons (): boolean {
|
||||
return this.has('roleIcons')
|
||||
}
|
||||
|
||||
/** Whether the guild has set up auto moderation rules */
|
||||
get autoModeration () {
|
||||
get autoModeration (): boolean {
|
||||
return this.has('autoModeration')
|
||||
}
|
||||
|
||||
/** Whether the guild has paused invites, preventing new users from joining */
|
||||
get invitesDisabled () {
|
||||
get invitesDisabled (): boolean {
|
||||
return this.has('invitesDisabled')
|
||||
}
|
||||
|
||||
/** Checks whether or not the permissions exist in this */
|
||||
has (permissions: GuildToggleKeys | GuildToggleKeys[]) {
|
||||
if (!Array.isArray(permissions)) return super.contains(GuildToggle[permissions])
|
||||
has (permissions: GuildToggleKeys | GuildToggleKeys[]): boolean {
|
||||
if (!Array.isArray(permissions)) { return super.contains(GuildToggle[permissions]) }
|
||||
|
||||
return super.contains(permissions.reduce((a, b) => (a |= GuildToggle[b]), 0n))
|
||||
return super.contains(
|
||||
permissions.reduce((a, b) => (a |= GuildToggle[b]), 0n)
|
||||
)
|
||||
}
|
||||
|
||||
/** Lists all the toggles for the role and whether or not each is true or false. */
|
||||
list () {
|
||||
list (): Record<GuildToggleKeys, boolean> {
|
||||
const json: Record<string, boolean> = {}
|
||||
for (const [key, value] of Object.entries(GuildToggle)) {
|
||||
json[key] = super.contains(value)
|
||||
}
|
||||
|
||||
return json as Record<GuildToggleKeys, boolean>
|
||||
return json
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,7 @@ export class MemberToggles extends ToggleBitfield {
|
||||
constructor (memberOrTogglesInt: Partial<DiscordMember> | number) {
|
||||
super()
|
||||
|
||||
if (typeof memberOrTogglesInt === 'number') this.bitfield = memberOrTogglesInt
|
||||
else {
|
||||
if (typeof memberOrTogglesInt === 'number') { this.bitfield = memberOrTogglesInt } else {
|
||||
const member = memberOrTogglesInt
|
||||
|
||||
if (member.deaf) this.add(MemberToggle.deaf)
|
||||
@@ -25,35 +24,37 @@ export class MemberToggles extends ToggleBitfield {
|
||||
}
|
||||
|
||||
/** Whether the user belongs to an OAuth2 application */
|
||||
get deaf () {
|
||||
get deaf (): boolean {
|
||||
return this.has('deaf')
|
||||
}
|
||||
|
||||
/** Whether the user is muted in voice channels */
|
||||
get mute () {
|
||||
get mute (): boolean {
|
||||
return this.has('mute')
|
||||
}
|
||||
|
||||
/** Whether the user has not yet passed the guild's Membership Screening requirements */
|
||||
get pending () {
|
||||
get pending (): boolean {
|
||||
return this.has('pending')
|
||||
}
|
||||
|
||||
/** Checks whether or not the permissions exist in this */
|
||||
has (permissions: MemberToggleKeys | MemberToggleKeys[]) {
|
||||
if (!Array.isArray(permissions)) return super.contains(MemberToggle[permissions])
|
||||
has (permissions: MemberToggleKeys | MemberToggleKeys[]): boolean {
|
||||
if (!Array.isArray(permissions)) { return super.contains(MemberToggle[permissions]) }
|
||||
|
||||
return super.contains(permissions.reduce((a, b) => (a |= MemberToggle[b]), 0))
|
||||
return super.contains(
|
||||
permissions.reduce((a, b) => (a |= MemberToggle[b]), 0)
|
||||
)
|
||||
}
|
||||
|
||||
/** Lists all the toggles for the role and whether or not each is true or false. */
|
||||
list () {
|
||||
list (): Record<MemberToggleKeys, boolean> {
|
||||
const json: Record<string, boolean> = {}
|
||||
for (const [key, value] of Object.entries(MemberToggle)) {
|
||||
json[key] = super.contains(value)
|
||||
}
|
||||
|
||||
return json as Record<MemberToggleKeys, boolean>
|
||||
return json
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,45 +23,47 @@ export class RoleToggles extends ToggleBitfield {
|
||||
if (role.hoist) this.add(RoleToggle.hoist)
|
||||
if (role.managed) this.add(RoleToggle.managed)
|
||||
if (role.mentionable) this.add(RoleToggle.mentionable)
|
||||
if (role.tags?.premium_subscriber === null) this.add(RoleToggle.premiumSubscriber)
|
||||
if (role.tags?.premium_subscriber === null) { this.add(RoleToggle.premiumSubscriber) }
|
||||
}
|
||||
}
|
||||
|
||||
/** If this role is showed separately in the user listing */
|
||||
get hoist () {
|
||||
get hoist (): boolean {
|
||||
return this.has('hoist')
|
||||
}
|
||||
|
||||
/** Whether this role is managed by an integration */
|
||||
get managed () {
|
||||
get managed (): boolean {
|
||||
return this.has('managed')
|
||||
}
|
||||
|
||||
/** Whether this role is mentionable */
|
||||
get mentionable () {
|
||||
get mentionable (): boolean {
|
||||
return this.has('mentionable')
|
||||
}
|
||||
|
||||
/** Whether this is the guilds premium subscriber role */
|
||||
get premiumSubscriber () {
|
||||
get premiumSubscriber (): boolean {
|
||||
return this.has('premiumSubscriber')
|
||||
}
|
||||
|
||||
/** Checks whether or not the permissions exist in this */
|
||||
has (permissions: RoleToggleKeys | RoleToggleKeys[]) {
|
||||
if (!Array.isArray(permissions)) return super.contains(RoleToggle[permissions])
|
||||
has (permissions: RoleToggleKeys | RoleToggleKeys[]): boolean {
|
||||
if (!Array.isArray(permissions)) { return super.contains(RoleToggle[permissions]) }
|
||||
|
||||
return super.contains(permissions.reduce((a, b) => (a |= RoleToggle[b]), 0))
|
||||
return super.contains(
|
||||
permissions.reduce((a, b) => (a |= RoleToggle[b]), 0)
|
||||
)
|
||||
}
|
||||
|
||||
/** Lists all the toggles for the role and whether or not each is true or false. */
|
||||
list () {
|
||||
list (): Record<RoleToggleKeys, boolean> {
|
||||
const json: Record<string, boolean> = {}
|
||||
for (const [key, value] of Object.entries(RoleToggle)) {
|
||||
json[key] = super.contains(value)
|
||||
}
|
||||
|
||||
return json as Record<RoleToggleKeys, boolean>
|
||||
return json
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,40 +28,42 @@ export class UserToggles extends ToggleBitfield {
|
||||
}
|
||||
|
||||
/** Whether the user belongs to an OAuth2 application */
|
||||
get bot () {
|
||||
get bot (): boolean {
|
||||
return this.has('bot')
|
||||
}
|
||||
|
||||
/** Whether the user is an Official Discord System user (part of the urgent message system) */
|
||||
get system () {
|
||||
get system (): boolean {
|
||||
return this.has('system')
|
||||
}
|
||||
|
||||
/** Whether the user has two factor enabled on their account */
|
||||
get mfaEnabled () {
|
||||
get mfaEnabled (): boolean {
|
||||
return this.has('mfaEnabled')
|
||||
}
|
||||
|
||||
/** Whether the email on this account has been verified */
|
||||
get verified () {
|
||||
get verified (): boolean {
|
||||
return this.has('verified')
|
||||
}
|
||||
|
||||
/** Checks whether or not the permissions exist in this */
|
||||
has (permissions: UserToggleKeys | UserToggleKeys[]) {
|
||||
if (!Array.isArray(permissions)) return super.contains(UserToggle[permissions])
|
||||
has (permissions: UserToggleKeys | UserToggleKeys[]): boolean {
|
||||
if (!Array.isArray(permissions)) { return super.contains(UserToggle[permissions]) }
|
||||
|
||||
return super.contains(permissions.reduce((a, b) => (a |= UserToggle[b]), 0))
|
||||
return super.contains(
|
||||
permissions.reduce((a, b) => (a |= UserToggle[b]), 0)
|
||||
)
|
||||
}
|
||||
|
||||
/** Lists all the toggles for the role and whether or not each is true or false. */
|
||||
list () {
|
||||
list (): Record<UserToggleKeys, boolean> {
|
||||
const json: Record<string, boolean> = {}
|
||||
for (const [key, value] of Object.entries(UserToggle)) {
|
||||
json[key] = super.contains(value)
|
||||
}
|
||||
|
||||
return json as Record<UserToggleKeys, boolean>
|
||||
return json
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,7 @@ export class VoiceStateToggles extends ToggleBitfield {
|
||||
constructor (voiceOrTogglesInt: DiscordVoiceState | number) {
|
||||
super()
|
||||
|
||||
if (typeof voiceOrTogglesInt === 'number') this.bitfield = voiceOrTogglesInt
|
||||
else {
|
||||
if (typeof voiceOrTogglesInt === 'number') { this.bitfield = voiceOrTogglesInt } else {
|
||||
const voice = voiceOrTogglesInt
|
||||
|
||||
if (voice.deaf) this.add(VoiceStateToggle.deaf)
|
||||
@@ -37,55 +36,57 @@ export class VoiceStateToggles extends ToggleBitfield {
|
||||
}
|
||||
|
||||
/** Whether this user is deafened by the server */
|
||||
get deaf () {
|
||||
get deaf (): boolean {
|
||||
return this.has('deaf')
|
||||
}
|
||||
|
||||
/** Whether this user is muted by the server */
|
||||
get mute () {
|
||||
get mute (): boolean {
|
||||
return this.has('mute')
|
||||
}
|
||||
|
||||
/** Whether this user is locally deafened */
|
||||
get selfDeaf () {
|
||||
get selfDeaf (): boolean {
|
||||
return this.has('selfDeaf')
|
||||
}
|
||||
|
||||
/** Whether this user is locally muted */
|
||||
get selfMute () {
|
||||
get selfMute (): boolean {
|
||||
return this.has('selfMute')
|
||||
}
|
||||
|
||||
/** Whether this user is streaming using "Go Live" */
|
||||
get selfStream () {
|
||||
get selfStream (): boolean {
|
||||
return this.has('selfStream')
|
||||
}
|
||||
|
||||
/** Whether this user's camera is enabled */
|
||||
get selfVideo () {
|
||||
get selfVideo (): boolean {
|
||||
return this.has('selfVideo')
|
||||
}
|
||||
|
||||
/** Whether this user is muted by the current user */
|
||||
get suppress () {
|
||||
get suppress (): boolean {
|
||||
return this.has('suppress')
|
||||
}
|
||||
|
||||
/** Checks whether or not the permissions exist in this */
|
||||
has (permissions: VoiceStateToggleKeys | VoiceStateToggleKeys[]) {
|
||||
if (!Array.isArray(permissions)) return super.contains(VoiceStateToggle[permissions])
|
||||
has (permissions: VoiceStateToggleKeys | VoiceStateToggleKeys[]): boolean {
|
||||
if (!Array.isArray(permissions)) { return super.contains(VoiceStateToggle[permissions]) }
|
||||
|
||||
return super.contains(permissions.reduce((a, b) => (a |= VoiceStateToggle[b]), 0))
|
||||
return super.contains(
|
||||
permissions.reduce((a, b) => (a |= VoiceStateToggle[b]), 0)
|
||||
)
|
||||
}
|
||||
|
||||
/** Lists all the toggles for the role and whether or not each is true or false. */
|
||||
list () {
|
||||
list (): Record<VoiceStateToggleKeys, boolean> {
|
||||
const json: Record<string, boolean> = {}
|
||||
for (const [key, value] of Object.entries(VoiceStateToggle)) {
|
||||
json[key] = super.contains(value)
|
||||
}
|
||||
|
||||
return json as Record<VoiceStateToggleKeys, boolean>
|
||||
return json
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Bot } from '../bot.js'
|
||||
|
||||
// TODO: Rename `VoiceRegions` to `VoiceRegion`.
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformVoiceRegion (bot: Bot, payload: DiscordVoiceRegion) {
|
||||
const voiceRegion = {
|
||||
id: payload.id,
|
||||
@@ -15,4 +16,4 @@ export function transformVoiceRegion (bot: Bot, payload: DiscordVoiceRegion) {
|
||||
return voiceRegion as Optionalize<typeof voiceRegion>
|
||||
}
|
||||
|
||||
export interface VoiceRegions extends ReturnType<typeof transformVoiceRegion> { }
|
||||
export interface VoiceRegions extends ReturnType<typeof transformVoiceRegion> {}
|
||||
|
||||
@@ -2,7 +2,11 @@ import { DiscordVoiceState, Optionalize } from '@discordeno/types'
|
||||
import { Bot } from '../bot.js'
|
||||
import { VoiceStateToggles } from './toggles/voice.js'
|
||||
|
||||
export function transformVoiceState (bot: Bot, payload: { voiceState: DiscordVoiceState } & { guildId: bigint }) {
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformVoiceState (
|
||||
bot: Bot,
|
||||
payload: { voiceState: DiscordVoiceState } & { guildId: bigint }
|
||||
) {
|
||||
const voiceState = {
|
||||
toggles: new VoiceStateToggles(payload.voiceState),
|
||||
|
||||
@@ -11,13 +15,20 @@ export function transformVoiceState (bot: Bot, payload: { voiceState: DiscordVoi
|
||||
: undefined,
|
||||
sessionId: payload.voiceState.session_id,
|
||||
|
||||
channelId: payload.voiceState.channel_id ? bot.transformers.snowflake(payload.voiceState.channel_id) : undefined,
|
||||
guildId: payload.guildId ||
|
||||
(payload.voiceState.guild_id ? bot.transformers.snowflake(payload.voiceState.guild_id) : 0n),
|
||||
userId: payload.voiceState.user_id ? bot.transformers.snowflake(payload.voiceState.user_id) : 0n
|
||||
channelId: payload.voiceState.channel_id
|
||||
? bot.transformers.snowflake(payload.voiceState.channel_id)
|
||||
: undefined,
|
||||
guildId:
|
||||
payload.guildId ||
|
||||
(payload.voiceState.guild_id
|
||||
? bot.transformers.snowflake(payload.voiceState.guild_id)
|
||||
: 0n),
|
||||
userId: payload.voiceState.user_id
|
||||
? bot.transformers.snowflake(payload.voiceState.user_id)
|
||||
: 0n
|
||||
}
|
||||
|
||||
return voiceState as Optionalize<typeof voiceState>
|
||||
}
|
||||
|
||||
export interface VoiceState extends ReturnType<typeof transformVoiceState> { }
|
||||
export interface VoiceState extends ReturnType<typeof transformVoiceState> {}
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
import { DiscordWelcomeScreen, Optionalize } from '@discordeno/types'
|
||||
import { Bot } from '../bot.js'
|
||||
|
||||
export function transformWelcomeScreen (bot: Bot, payload: DiscordWelcomeScreen) {
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformWelcomeScreen (
|
||||
bot: Bot,
|
||||
payload: DiscordWelcomeScreen
|
||||
) {
|
||||
const welcomeScreen = {
|
||||
description: payload.description ?? undefined,
|
||||
welcomeChannels: payload.welcome_channels.map((channel) => ({
|
||||
channelId: bot.transformers.snowflake(channel.channel_id),
|
||||
description: channel.description,
|
||||
emojiId: channel.emoji_id ? bot.transformers.snowflake(channel.emoji_id) : undefined,
|
||||
emojiId: channel.emoji_id
|
||||
? bot.transformers.snowflake(channel.emoji_id)
|
||||
: undefined,
|
||||
emojiName: channel.emoji_name ?? undefined
|
||||
}))
|
||||
}
|
||||
@@ -15,4 +21,5 @@ export function transformWelcomeScreen (bot: Bot, payload: DiscordWelcomeScreen)
|
||||
return welcomeScreen as Optionalize<typeof welcomeScreen>
|
||||
}
|
||||
|
||||
export interface WelcomeScreen extends ReturnType<typeof transformWelcomeScreen> { }
|
||||
export interface WelcomeScreen
|
||||
extends ReturnType<typeof transformWelcomeScreen> {}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { DiscordGuildWidget, Optionalize } from '@discordeno/types'
|
||||
import { Bot } from '../bot.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformWidget (bot: Bot, payload: DiscordGuildWidget) {
|
||||
const widget = {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
@@ -15,7 +16,9 @@ export function transformWidget (bot: Bot, payload: DiscordGuildWidget) {
|
||||
id: bot.transformers.snowflake(member.id),
|
||||
username: member.username,
|
||||
discriminator: member.discriminator,
|
||||
avatar: member.avatar ? bot.utils.iconHashToBigInt(member.avatar) : undefined,
|
||||
avatar: member.avatar
|
||||
? bot.utils.iconHashToBigInt(member.avatar)
|
||||
: undefined,
|
||||
status: member.status,
|
||||
avatarUrl: member.avatar_url
|
||||
})),
|
||||
@@ -25,4 +28,4 @@ export function transformWidget (bot: Bot, payload: DiscordGuildWidget) {
|
||||
return widget as Optionalize<typeof widget>
|
||||
}
|
||||
|
||||
export interface GuildWidget extends ReturnType<typeof transformWidget> { }
|
||||
export interface GuildWidget extends ReturnType<typeof transformWidget> {}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { DiscordGuildWidgetSettings, Optionalize } from '@discordeno/types'
|
||||
import { Bot } from '../bot.js'
|
||||
|
||||
export function transformWidgetSettings (bot: Bot, payload: DiscordGuildWidgetSettings) {
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformWidgetSettings (
|
||||
bot: Bot,
|
||||
payload: DiscordGuildWidgetSettings
|
||||
) {
|
||||
const widget = {
|
||||
enabled: payload.enabled,
|
||||
channelId: payload.channel_id ?? undefined
|
||||
@@ -10,4 +14,5 @@ export function transformWidgetSettings (bot: Bot, payload: DiscordGuildWidgetSe
|
||||
return widget as Optionalize<typeof widget>
|
||||
}
|
||||
|
||||
export interface GuildWidgetSettings extends ReturnType<typeof transformWidgetSettings> { }
|
||||
export interface GuildWidgetSettings
|
||||
extends ReturnType<typeof transformWidgetSettings> {}
|
||||
|
||||
@@ -40,10 +40,10 @@ export const routes = {
|
||||
let url = `/channels/${channelId}/messages?`
|
||||
|
||||
if (options) {
|
||||
if (isGetMessagesAfter(options) && options.after) url += `after=${options.after}`
|
||||
if (isGetMessagesBefore(options) && options.before) url += `&before=${options.before}`
|
||||
if (isGetMessagesAround(options) && options.around) url += `&around=${options.around}`
|
||||
if (isGetMessagesLimit(options) && options.limit) url += `&limit=${options.limit}`
|
||||
if (isGetMessagesAfter(options) && options.after) { url += `after=${options.after}` }
|
||||
if (isGetMessagesBefore(options) && options.before) { url += `&before=${options.before}` }
|
||||
if (isGetMessagesAround(options) && options.around) { url += `&around=${options.around}` }
|
||||
if (isGetMessagesLimit(options) && options.limit) { url += `&limit=${options.limit}` }
|
||||
}
|
||||
|
||||
return url
|
||||
@@ -63,17 +63,37 @@ export const routes = {
|
||||
CHANNEL_WEBHOOKS: (channelId: BigString) => {
|
||||
return `/channels/${channelId}/webhooks`
|
||||
},
|
||||
CHANNEL_MESSAGE_REACTION_ME: (channelId: BigString, messageId: BigString, emoji: string) => {
|
||||
return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/@me`
|
||||
CHANNEL_MESSAGE_REACTION_ME: (
|
||||
channelId: BigString,
|
||||
messageId: BigString,
|
||||
emoji: string
|
||||
) => {
|
||||
return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(
|
||||
emoji
|
||||
)}/@me`
|
||||
},
|
||||
CHANNEL_MESSAGE_REACTION_USER: (channelId: BigString, messageId: BigString, emoji: string, userId: BigString) => {
|
||||
return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/${userId}`
|
||||
CHANNEL_MESSAGE_REACTION_USER: (
|
||||
channelId: BigString,
|
||||
messageId: BigString,
|
||||
emoji: string,
|
||||
userId: BigString
|
||||
) => {
|
||||
return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(
|
||||
emoji
|
||||
)}/${userId}`
|
||||
},
|
||||
CHANNEL_MESSAGE_REACTIONS: (channelId: BigString, messageId: BigString) => {
|
||||
return `/channels/${channelId}/messages/${messageId}/reactions`
|
||||
},
|
||||
CHANNEL_MESSAGE_REACTION: (channelId: BigString, messageId: BigString, emoji: string, options?: GetReactions) => {
|
||||
let url = `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}?`
|
||||
CHANNEL_MESSAGE_REACTION: (
|
||||
channelId: BigString,
|
||||
messageId: BigString,
|
||||
emoji: string,
|
||||
options?: GetReactions
|
||||
) => {
|
||||
let url = `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(
|
||||
emoji
|
||||
)}?`
|
||||
|
||||
if (options) {
|
||||
if (options.after) url += `after=${options.after}`
|
||||
@@ -118,31 +138,40 @@ export const routes = {
|
||||
THREAD_ARCHIVED: (channelId: BigString) => {
|
||||
return `/channels/${channelId}/threads/archived`
|
||||
},
|
||||
THREAD_ARCHIVED_PUBLIC: (channelId: BigString, options?: ListArchivedThreads) => {
|
||||
THREAD_ARCHIVED_PUBLIC: (
|
||||
channelId: BigString,
|
||||
options?: ListArchivedThreads
|
||||
) => {
|
||||
let url = `/channels/${channelId}/threads/archived/public?`
|
||||
|
||||
if (options) {
|
||||
if (options.before) url += `before=${new Date(options.before).toISOString()}`
|
||||
if (options.before) { url += `before=${new Date(options.before).toISOString()}` }
|
||||
if (options.limit) url += `&limit=${options.limit}`
|
||||
}
|
||||
|
||||
return url
|
||||
},
|
||||
THREAD_ARCHIVED_PRIVATE: (channelId: BigString, options?: ListArchivedThreads) => {
|
||||
THREAD_ARCHIVED_PRIVATE: (
|
||||
channelId: BigString,
|
||||
options?: ListArchivedThreads
|
||||
) => {
|
||||
let url = `/channels/${channelId}/threads/archived/private?`
|
||||
|
||||
if (options) {
|
||||
if (options.before) url += `before=${new Date(options.before).toISOString()}`
|
||||
if (options.before) { url += `before=${new Date(options.before).toISOString()}` }
|
||||
if (options.limit) url += `&limit=${options.limit}`
|
||||
}
|
||||
|
||||
return url
|
||||
},
|
||||
THREAD_ARCHIVED_PRIVATE_JOINED: (channelId: BigString, options?: ListArchivedThreads) => {
|
||||
THREAD_ARCHIVED_PRIVATE_JOINED: (
|
||||
channelId: BigString,
|
||||
options?: ListArchivedThreads
|
||||
) => {
|
||||
let url = `/channels/${channelId}/users/@me/threads/archived/private?`
|
||||
|
||||
if (options) {
|
||||
if (options.before) url += `before=${new Date(options.before).toISOString()}`
|
||||
if (options.before) { url += `before=${new Date(options.before).toISOString()}` }
|
||||
if (options.limit) url += `&limit=${options.limit}`
|
||||
}
|
||||
|
||||
@@ -159,13 +188,13 @@ export const routes = {
|
||||
let url = `/guilds/${guildId}?`
|
||||
|
||||
if (withCounts !== undefined) {
|
||||
url += `with_counts=${withCounts}`
|
||||
url += `with_counts=${withCounts.toString()}`
|
||||
}
|
||||
|
||||
return url
|
||||
},
|
||||
GUILDS: () => {
|
||||
return `/guilds`
|
||||
return '/guilds'
|
||||
},
|
||||
GUILD_AUDIT_LOGS: (guildId: BigString, options?: GetGuildAuditLog) => {
|
||||
let url = `/guilds/${guildId}/audit-logs?`
|
||||
@@ -208,12 +237,7 @@ export const routes = {
|
||||
},
|
||||
GUILD_WIDGET_IMAGE: (
|
||||
guildId: BigString,
|
||||
style?:
|
||||
| 'shield'
|
||||
| 'banner1'
|
||||
| 'banner2'
|
||||
| 'banner3'
|
||||
| 'banner4'
|
||||
style?: 'shield' | 'banner1' | 'banner2' | 'banner3' | 'banner4'
|
||||
) => {
|
||||
let url = `/guilds/${guildId}/widget.png?`
|
||||
|
||||
@@ -261,11 +285,21 @@ export const routes = {
|
||||
|
||||
return url
|
||||
},
|
||||
GUILD_MEMBER_ROLE: (guildId: BigString, memberId: BigString, roleId: BigString) => {
|
||||
GUILD_MEMBER_ROLE: (
|
||||
guildId: BigString,
|
||||
memberId: BigString,
|
||||
roleId: BigString
|
||||
) => {
|
||||
return `/guilds/${guildId}/members/${memberId}/roles/${roleId}`
|
||||
},
|
||||
GUILD_MEMBERS_SEARCH: (guildId: BigString, query: string, options?: { limit?: number }) => {
|
||||
let url = `/guilds/${guildId}/members/search?query=${encodeURIComponent(query)}`
|
||||
GUILD_MEMBERS_SEARCH: (
|
||||
guildId: BigString,
|
||||
query: string,
|
||||
options?: { limit?: number }
|
||||
) => {
|
||||
let url = `/guilds/${guildId}/members/search?query=${encodeURIComponent(
|
||||
query
|
||||
)}`
|
||||
|
||||
if (options) {
|
||||
if (options.limit !== undefined) url += `&limit=${options.limit}`
|
||||
@@ -278,7 +312,11 @@ export const routes = {
|
||||
|
||||
if (options) {
|
||||
if (options.days) url += `days=${options.days}`
|
||||
if (options.includeRoles) url += `&include_roles=${options.includeRoles}`
|
||||
if (Array.isArray(options.includeRoles)) {
|
||||
url += `&include_roles=${options.includeRoles.join(',')}`
|
||||
} else if (options.includeRoles) {
|
||||
url += `&include_roles=${options.includeRoles}`
|
||||
}
|
||||
}
|
||||
|
||||
return url
|
||||
@@ -324,27 +362,35 @@ export const routes = {
|
||||
let url = `/guilds/${guildId}/scheduled-events?`
|
||||
|
||||
if (withUserCount !== undefined) {
|
||||
url += `with_user_count=${withUserCount}`
|
||||
url += `with_user_count=${withUserCount.toString()}`
|
||||
}
|
||||
return url
|
||||
},
|
||||
GUILD_SCHEDULED_EVENT: (guildId: BigString, eventId: BigString, withUserCount?: boolean) => {
|
||||
GUILD_SCHEDULED_EVENT: (
|
||||
guildId: BigString,
|
||||
eventId: BigString,
|
||||
withUserCount?: boolean
|
||||
) => {
|
||||
let url = `/guilds/${guildId}/scheduled-events/${eventId}`
|
||||
|
||||
if (withUserCount !== undefined) {
|
||||
url += `with_user_count=${withUserCount}`
|
||||
url += `with_user_count=${withUserCount.toString()}`
|
||||
}
|
||||
|
||||
return url
|
||||
},
|
||||
GUILD_SCHEDULED_EVENT_USERS: (guildId: BigString, eventId: BigString, options?: GetScheduledEventUsers) => {
|
||||
GUILD_SCHEDULED_EVENT_USERS: (
|
||||
guildId: BigString,
|
||||
eventId: BigString,
|
||||
options?: GetScheduledEventUsers
|
||||
) => {
|
||||
let url = `/guilds/${guildId}/scheduled-events/${eventId}/users?`
|
||||
|
||||
if (options) {
|
||||
if (options.limit) url += `limit=${options.limit}`
|
||||
if (options.withMember) url += `&with_member=${options.withMember}`
|
||||
if (options.after) url += `&after=${options.after}`
|
||||
if (options.before) url += `&before=${options.before}`
|
||||
if (options.limit !== undefined) url += `limit=${options.limit}`
|
||||
if (options.withMember !== undefined) { url += `&with_member=${options.withMember.toString()}` }
|
||||
if (options.after !== undefined) url += `&after=${options.after}`
|
||||
if (options.before !== undefined) url += `&before=${options.before}`
|
||||
}
|
||||
|
||||
return url
|
||||
@@ -352,26 +398,30 @@ export const routes = {
|
||||
GUILD_MFA_LEVEL: (guildId: BigString) => `/guilds/${guildId}/mfa`,
|
||||
// Voice
|
||||
VOICE_REGIONS: () => {
|
||||
return `/voice/regions`
|
||||
return '/voice/regions'
|
||||
},
|
||||
|
||||
INVITE: (inviteCode: string, options?: GetInvite) => {
|
||||
let url = `/invites/${inviteCode}?`
|
||||
|
||||
if (options) {
|
||||
if (options.withCounts) url += `with_counts=${options.withCounts}`
|
||||
if (options.withExpiration) url += `&with_expiration=${options.withExpiration}`
|
||||
if (options.scheduledEventId) url += `&guild_scheduled_event_id=${options.scheduledEventId}`
|
||||
if (options.withCounts !== undefined) { url += `with_counts=${options.withCounts.toString()}` }
|
||||
if (options.withExpiration !== undefined) { url += `&with_expiration=${options.withExpiration.toString()}` }
|
||||
if (options.scheduledEventId) { url += `&guild_scheduled_event_id=${options.scheduledEventId}` }
|
||||
}
|
||||
|
||||
return url
|
||||
},
|
||||
|
||||
WEBHOOK: (webhookId: BigString, token: string, options?: { wait?: boolean, threadId?: BigString }) => {
|
||||
WEBHOOK: (
|
||||
webhookId: BigString,
|
||||
token: string,
|
||||
options?: { wait?: boolean, threadId?: BigString }
|
||||
) => {
|
||||
let url = `/webhooks/${webhookId}/${token}?`
|
||||
|
||||
if (options) {
|
||||
if (options?.wait !== undefined) url += `wait=${options.wait}`
|
||||
if (options?.wait !== undefined) url += `wait=${options.wait.toString()}`
|
||||
if (options.threadId) url += `thread_id=${options.threadId}`
|
||||
}
|
||||
|
||||
@@ -380,7 +430,12 @@ export const routes = {
|
||||
WEBHOOK_ID: (webhookId: BigString) => {
|
||||
return `/webhooks/${webhookId}`
|
||||
},
|
||||
WEBHOOK_MESSAGE: (webhookId: BigString, token: string, messageId: BigString, options?: { threadId?: BigString }) => {
|
||||
WEBHOOK_MESSAGE: (
|
||||
webhookId: BigString,
|
||||
token: string,
|
||||
messageId: BigString,
|
||||
options?: { threadId?: BigString }
|
||||
) => {
|
||||
let url = `/webhooks/${webhookId}/${token}/messages/${messageId}?`
|
||||
|
||||
if (options) {
|
||||
@@ -389,7 +444,11 @@ export const routes = {
|
||||
|
||||
return url
|
||||
},
|
||||
WEBHOOK_MESSAGE_ORIGINAL: (webhookId: BigString, token: string, options?: { threadId?: BigString }) => {
|
||||
WEBHOOK_MESSAGE_ORIGINAL: (
|
||||
webhookId: BigString,
|
||||
token: string,
|
||||
options?: { threadId?: BigString }
|
||||
) => {
|
||||
let url = `/webhooks/${webhookId}/${token}/messages/@original?`
|
||||
|
||||
if (options) {
|
||||
@@ -415,14 +474,22 @@ export const routes = {
|
||||
COMMANDS_PERMISSIONS: (applicationId: BigString, guildId: BigString) => {
|
||||
return `/applications/${applicationId}/guilds/${guildId}/commands/permissions`
|
||||
},
|
||||
COMMANDS_PERMISSION: (applicationId: BigString, guildId: BigString, commandId: BigString) => {
|
||||
COMMANDS_PERMISSION: (
|
||||
applicationId: BigString,
|
||||
guildId: BigString,
|
||||
commandId: BigString
|
||||
) => {
|
||||
return `/applications/${applicationId}/guilds/${guildId}/commands/${commandId}/permissions`
|
||||
},
|
||||
COMMANDS_ID: (applicationId: BigString, commandId: BigString, withLocalizations?: boolean) => {
|
||||
COMMANDS_ID: (
|
||||
applicationId: BigString,
|
||||
commandId: BigString,
|
||||
withLocalizations?: boolean
|
||||
) => {
|
||||
let url = `/applications/${applicationId}/commands/${commandId}?`
|
||||
|
||||
if (withLocalizations !== undefined) {
|
||||
url += `withLocalizations=${withLocalizations}`
|
||||
url += `withLocalizations=${withLocalizations.toString()}`
|
||||
}
|
||||
|
||||
return url
|
||||
@@ -436,7 +503,7 @@ export const routes = {
|
||||
let url = `/applications/${applicationId}/guilds/${guildId}/commands/${commandId}?`
|
||||
|
||||
if (withLocalizations !== undefined) {
|
||||
url += `with_localizations=${withLocalizations}`
|
||||
url += `with_localizations=${withLocalizations.toString()}`
|
||||
}
|
||||
|
||||
return url
|
||||
@@ -449,7 +516,11 @@ export const routes = {
|
||||
INTERACTION_ORIGINAL_ID_TOKEN: (interactionId: BigString, token: string) => {
|
||||
return `/webhooks/${interactionId}/${token}/messages/@original`
|
||||
},
|
||||
INTERACTION_ID_TOKEN_MESSAGE_ID: (applicationId: BigString, token: string, messageId: BigString) => {
|
||||
INTERACTION_ID_TOKEN_MESSAGE_ID: (
|
||||
applicationId: BigString,
|
||||
token: string,
|
||||
messageId: BigString
|
||||
) => {
|
||||
return `/webhooks/${applicationId}/${token}/messages/${messageId}`
|
||||
},
|
||||
|
||||
@@ -458,10 +529,10 @@ export const routes = {
|
||||
return `/users/${userId}`
|
||||
},
|
||||
USER_BOT: () => {
|
||||
return `/users/@me`
|
||||
return '/users/@me'
|
||||
},
|
||||
USER_GUILDS: () => {
|
||||
return `/users/@me/guilds`
|
||||
return '/users/@me/guilds'
|
||||
},
|
||||
// TODO: move this away
|
||||
USER_AVATAR: (userId: BigString, icon: string) => {
|
||||
@@ -472,10 +543,10 @@ export const routes = {
|
||||
return `${baseEndpoints.CDN_URL}/embed/avatars/${icon}.png`
|
||||
},
|
||||
USER_DM: () => {
|
||||
return `/users/@me/channels`
|
||||
return '/users/@me/channels'
|
||||
},
|
||||
USER_CONNECTIONS: () => {
|
||||
return `/users/@me/connections`
|
||||
return '/users/@me/connections'
|
||||
},
|
||||
USER_NICK: (guildId: BigString) => {
|
||||
return `/guilds/${guildId}/members/@me`
|
||||
@@ -483,7 +554,7 @@ export const routes = {
|
||||
|
||||
// Discovery Endpoints
|
||||
DISCOVERY_CATEGORIES: () => {
|
||||
return `/discovery/categories`
|
||||
return '/discovery/categories'
|
||||
},
|
||||
DISCOVERY_VALID_TERM: (term: string) => {
|
||||
return `/discovery/valid-term?term=${term}`
|
||||
@@ -497,12 +568,12 @@ export const routes = {
|
||||
|
||||
// OAuth2
|
||||
OAUTH2_APPLICATION: () => {
|
||||
return `/oauth2/applications/@me`
|
||||
return 'oauth2/applications/@me'
|
||||
},
|
||||
|
||||
// Stage instances
|
||||
STAGE_INSTANCES: () => {
|
||||
return `/stage-instances`
|
||||
return '/stage-instances'
|
||||
},
|
||||
STAGE_INSTANCE: (channelId: BigString) => {
|
||||
return `/stage-instances/${channelId}`
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import { ImageFormat, ImageSize } from '../helpers/members/getAvatarUrl.js'
|
||||
|
||||
/** Help format an image url. */
|
||||
export function formatImageURL (url: string, size: ImageSize = 128, format?: ImageFormat) {
|
||||
return `${url}.${format || (url.includes('/a_') ? 'gif' : 'jpg')}?size=${size}`
|
||||
export function formatImageURL (
|
||||
url: string,
|
||||
size: ImageSize = 128,
|
||||
format?: ImageFormat
|
||||
): string {
|
||||
return `${url}.${
|
||||
format ?? (url.includes('/a_') ? 'gif' : 'jpg')
|
||||
}?size=${size}`
|
||||
}
|
||||
|
||||
// Typescript is not so good as we developers so we need this little utility function to help it out
|
||||
@@ -12,5 +18,6 @@ export function hasProperty<T extends {}, Y extends PropertyKey = string> (
|
||||
obj: T,
|
||||
prop: Y
|
||||
): obj is T & Record<Y, unknown> {
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
return obj.hasOwnProperty(prop)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user