Merge remote-tracking branch 'upstream/master'

This commit is contained in:
ITOH
2021-02-10 15:26:15 +01:00
6 changed files with 100 additions and 7 deletions

View File

@@ -52,8 +52,6 @@ export async function handleInternalGuildDelete(data: DiscordPayload) {
}
});
await cacheHandlers.delete("guilds", payload.id);
if (payload.unavailable) {
return cacheHandlers.set("unavailableGuilds", payload.id, Date.now());
}
@@ -61,6 +59,8 @@ export async function handleInternalGuildDelete(data: DiscordPayload) {
const guild = await cacheHandlers.get("guilds", payload.id);
if (!guild) return;
await cacheHandlers.delete("guilds", payload.id);
eventHandlers.guildDelete?.(guild);
}
@@ -102,7 +102,7 @@ export async function handleInternalGuildUpdate(data: DiscordPayload) {
}
}).filter((change) => change) as GuildUpdateChange[];
await cacheHandlers.set("guilds", payload.id, { ...cachedGuild, ...changes });
await cacheHandlers.set("guilds", payload.id, cachedGuild);
eventHandlers.guildUpdate?.(cachedGuild, changes);
}

View File

@@ -3,6 +3,8 @@ import {
DiscordPayload,
IntegrationCreateUpdateEvent,
IntegrationDeleteEvent,
InviteCreateEvent,
InviteDeleteEvent,
PresenceUpdatePayload,
ReadyPayload,
TypingStartPayload,
@@ -234,3 +236,45 @@ export function handleInternalIntegrationDelete(data: DiscordPayload) {
guildID,
});
}
export function handleInternalInviteCreate(payload: DiscordPayload) {
if (payload.t !== "INVITE_CREATE") return;
const {
channel_id: channelID,
created_at: createdAt,
max_age: maxAge,
guild_id: guildID,
target_user: targetUser,
target_user_type: targetUserType,
max_uses: maxUses,
...rest
} = payload.d as InviteCreateEvent;
eventHandlers.inviteCreate?.({
...rest,
channelID,
guildID,
maxAge,
targetUser,
targetUserType,
maxUses,
createdAt,
});
}
export function handleInternalInviteDelete(payload: DiscordPayload) {
if (payload.t !== "INVITE_DELETE") return;
const {
channel_id: channelID,
guild_id: guildID,
...rest
} = payload.d as InviteDeleteEvent;
eventHandlers.inviteDelete?.({
...rest,
channelID,
guildID,
});
}

View File

@@ -35,6 +35,8 @@ import {
handleInternalIntegrationCreate,
handleInternalIntegrationDelete,
handleInternalIntegrationUpdate,
handleInternalInviteCreate,
handleInternalInviteDelete,
handleInternalPresenceUpdate,
handleInternalReady,
handleInternalTypingStart,
@@ -92,6 +94,8 @@ export let controllers = {
INTEGRATION_CREATE: handleInternalIntegrationCreate,
INTEGRATION_UPDATE: handleInternalIntegrationUpdate,
INTEGRATION_DELETE: handleInternalIntegrationDelete,
INVITE_CREATE: handleInternalInviteCreate,
INVITE_DELETE: handleInternalInviteDelete,
};
export type Controllers = typeof controllers;

View File

@@ -113,9 +113,10 @@ export async function startBigBrainBot(data: BigBrainBotConfig) {
botGatewayData,
identifyPayload,
data.firstShardID,
data.lastShardID || botGatewayData.shards >= 25
? (data.firstShardID + 25)
: botGatewayData.shards,
data.lastShardID ||
(botGatewayData.shards >= 25
? (data.firstShardID + 25)
: botGatewayData.shards),
);
}

View File

@@ -53,7 +53,9 @@ export interface DiscordPayload {
| "WEBHOOKS_UPDATE"
| "INTEGRATION_CREATE"
| "INTEGRATION_UPDATE"
| "INTEGRATION_DELETE";
| "INTEGRATION_DELETE"
| "INVITE_CREATE"
| "INVITE_DELETE";
}
export interface DiscordBotGatewayData {
@@ -325,3 +327,39 @@ export interface IntegrationDeleteEvent {
/** id of the bot/OAuth2 application for this discord integration */
"application_id"?: string;
}
/** https://discord.com/developers/docs/topics/gateway#invite-create */
export interface InviteCreateEvent {
/** the channel the invite is for */
"channel_id": string;
/** the unique invite code */
code: string;
/** the time at which the invite was created */
"created_at": string;
/** the guild of the invite */
"guild_id"?: string;
/** the user that created the invite */
inviter?: UserPayload;
/** how long the invite is valid for (in seconds) */
"max_age": number;
/** the maximum number of times the invite can be used */
"max_uses": number;
/** the target user for this invite */
"target_user"?: Partial<UserPayload>;
/** the type of user target for this invite */
"target_user_type"?: number;
/** whether or not the invite is temporary (invited users will be kicked on disconnect unless they're assigned a role) */
temporary: boolean;
/** how many times the invite has been used (always will be 0) */
uses: number;
}
/** https://discord.com/developers/docs/topics/gateway#invite-delete */
export interface InviteDeleteEvent {
/** the channel of the invite */
"channel_id": string;
/** the guild of the invite */
"guild_id"?: string;
/** the unique invite code */
code: string;
}

View File

@@ -10,6 +10,8 @@ import {
Emoji,
IntegrationCreateUpdateEvent,
IntegrationDeleteEvent,
InviteCreateEvent,
InviteDeleteEvent,
PresenceUpdatePayload,
TypingStartPayload,
VoiceStateUpdatePayload,
@@ -232,6 +234,10 @@ export interface EventHandlers {
integrationUpdate?: (data: Camelize<IntegrationCreateUpdateEvent>) => unknown;
/** Sent when an integration is deleted. */
integrationDelete?: (data: Camelize<IntegrationDeleteEvent>) => undefined;
/** Sent when a new invite to a channel is created. */
inviteCreate?: (data: Camelize<InviteCreateEvent>) => unknown;
/** Sent when an invite is deleted. */
inviteDelete?: (data: Camelize<InviteDeleteEvent>) => unknown;
}
/** https://discord.com/developers/docs/topics/gateway#list-of-intents */