feat(controllers): add CHANNEL_PINS_UPDATE controller (#651)

* feat(controllers/channels): add CHANNEL_PINS_UPDATE controller

* sep file

* Update src/api/controllers/channels.ts

* Update src/api/controllers/CHANNEL_PINS_UPDATE.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

* Update src/api/controllers/CHANNEL_PINS_UPDATE.ts

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>
This commit is contained in:
ayntee
2021-03-10 20:28:11 +04:00
committed by GitHub
parent 26019cbfd1
commit aa27808bfc
4 changed files with 26 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
import { eventHandlers } from "../../bot.ts";
import {
DiscordChannelPinsUpdateEvent,
DiscordPayload,
} from "../../types/mod.ts";
import { cacheHandlers } from "./cache.ts";
export async function handleChannelPinsUpdate(data: DiscordPayload) {
const payload = data.d as DiscordChannelPinsUpdateEvent;
const channel = await cacheHandlers.get("channels", payload.channel_id);
if (!channel) return;
const guild = payload.guild_id ? await cacheHandlers.get("guilds", payload.guild_id) : undefined;
eventHandlers.channelPinsUpdate?.(channel, guild, payload.last_pin_timestamp);
}

View File

@@ -7,6 +7,7 @@ import {
handleInternalChannelDelete,
handleInternalChannelUpdate,
} from "./channels.ts";
import { handleChannelPinsUpdate } from "./CHANNEL_PINS_UPDATE.ts";
import {
handleInternalGuildCreate,
handleInternalGuildDelete,
@@ -62,6 +63,7 @@ export let controllers = {
CHANNEL_CREATE: handleInternalChannelCreate,
CHANNEL_DELETE: handleInternalChannelDelete,
CHANNEL_UPDATE: handleInternalChannelUpdate,
CHANNEL_PINS_UPDATE: handleChannelPinsUpdate,
GUILD_CREATE: handleInternalGuildCreate,
GUILD_DELETE: handleInternalGuildDelete,
GUILD_UPDATE: handleInternalGuildUpdate,

View File

@@ -24,6 +24,7 @@ export interface DiscordPayload {
| "CHANNEL_CREATE"
| "CHANNEL_DELETE"
| "CHANNEL_UPDATE"
| "CHANNEL_PINS_UPDATE"
| "GUILD_CREATE"
| "GUILD_DELETE"
| "GUILD_UPDATE"

View File

@@ -117,6 +117,12 @@ export interface EventHandlers {
channelUpdate?: (channel: Channel, cachedChannel: Channel) => unknown;
/** Sent when a channel relevant to the current user is deleted. */
channelDelete?: (channel: Channel) => unknown;
/** Sent when a message is pinned or unpinned in a text channel. This is not sent when a pinned message is deleted. */
channelPinsUpdate?: (
channel: Channel,
guild?: Guild,
lastPinTimestamp?: string | null,
) => unknown;
debug?: (args: DebugArg) => unknown;
dispatchRequirements?: (data: DiscordPayload, shardID: number) => unknown;
/** Sent when a user is banned from a guild. */