feat(platform): emoji pack APIs and emojisByPack view fields
Expose upsertEmojiPack, removeEmojiPack, guild emoji pack gossip ingest, and view enrichment (guildEmojiPacks, emojisByPack) for desktop UI. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -781,6 +781,14 @@ class PearcordPlatform extends EventEmitter {
|
||||
this.emojiRegistry?.ingestGossip(row).catch(() => {})
|
||||
this.emit('guild-emoji', row)
|
||||
})
|
||||
guildInstance.on('guild-emoji-pack', (row) => {
|
||||
this.emojiRegistry?.ingestPackGossip(row).catch(() => {})
|
||||
this.emit('guild-emoji-pack', row)
|
||||
})
|
||||
guildInstance.on('guild-emoji-pack-delete', (payload) => {
|
||||
this.emojiRegistry?.ingestPackDeleteGossip(payload).catch(() => {})
|
||||
this.emit('guild-emoji-pack-delete', payload)
|
||||
})
|
||||
guildInstance.on('guild-sticker', (row) => {
|
||||
this.stickerRegistry?.ingestGossip(row).catch(() => {})
|
||||
this.emit('guild-sticker', row)
|
||||
@@ -1939,7 +1947,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
async upsertGuildEmoji ({ name, glyph, description, attachmentId, image }) {
|
||||
async upsertGuildEmoji ({ name, glyph, description, attachmentId, image, packName }) {
|
||||
if (!this.guild?.guild) throw new Error('no guild')
|
||||
const user = this.identity.user
|
||||
if (!user) throw new Error('register first')
|
||||
@@ -1969,7 +1977,8 @@ class PearcordPlatform extends EventEmitter {
|
||||
driveKey: att?.driveKey || null,
|
||||
drivePath: att?.drivePath || null,
|
||||
mimeType: att?.mimeType || null,
|
||||
filename: att?.filename || null
|
||||
filename: att?.filename || null,
|
||||
packName: packName || null
|
||||
})
|
||||
if (att) this.guild.gossipAttachmentMeta(att)
|
||||
this.guild.gossipEmojiUpsert(row)
|
||||
@@ -1977,6 +1986,67 @@ class PearcordPlatform extends EventEmitter {
|
||||
return row
|
||||
}
|
||||
|
||||
async upsertEmojiPack ({
|
||||
name,
|
||||
displayName,
|
||||
description,
|
||||
sortOrder,
|
||||
coverEmojiName,
|
||||
emojiNames
|
||||
}) {
|
||||
if (!this.guild?.guild) throw new Error('no guild')
|
||||
const user = this.identity.user
|
||||
if (!user) throw new Error('register first')
|
||||
const roles = await this._memberRoles()
|
||||
if (!roleHasPermission(roles, PERMISSION.MANAGE_GUILD)) {
|
||||
throw new Error('no permission to manage emoji packs')
|
||||
}
|
||||
if (!this.emojiRegistry) await this._initEmojiRegistry(this.guild.guild.id)
|
||||
const row = await this.emojiRegistry.upsertPack({
|
||||
name,
|
||||
displayName,
|
||||
description,
|
||||
sortOrder,
|
||||
coverEmojiName,
|
||||
emojiNames
|
||||
})
|
||||
this.guild.gossipEmojiPackUpsert(row)
|
||||
this.emit('guild-emoji-pack', row)
|
||||
const emojis = await this.emojiRegistry.list()
|
||||
for (const e of emojis) {
|
||||
if (e.packName === row.name) this.guild.gossipEmojiUpsert(e)
|
||||
}
|
||||
return row
|
||||
}
|
||||
|
||||
async removeEmojiPack (name) {
|
||||
if (!this.guild?.guild) throw new Error('no guild')
|
||||
const user = this.identity.user
|
||||
if (!user) throw new Error('register first')
|
||||
const roles = await this._memberRoles()
|
||||
if (!roleHasPermission(roles, PERMISSION.MANAGE_GUILD)) {
|
||||
throw new Error('no permission to manage emoji packs')
|
||||
}
|
||||
if (!this.emojiRegistry) await this._initEmojiRegistry(this.guild.guild.id)
|
||||
const pack = await this.emojiRegistry.removePack(name)
|
||||
this.guild.gossipEmojiPackDelete({
|
||||
guildId: this.guild.guild.id,
|
||||
name: pack.name,
|
||||
deletedAt: Date.now()
|
||||
})
|
||||
this.emit('guild-emoji-pack-delete', { name: pack.name })
|
||||
const emojis = await this.emojiRegistry.list()
|
||||
for (const e of emojis) {
|
||||
if (!e.packName) this.guild.gossipEmojiUpsert(e)
|
||||
}
|
||||
return pack
|
||||
}
|
||||
|
||||
async listEmojiPacks () {
|
||||
if (!this.emojiRegistry) return []
|
||||
return this.emojiRegistry.listPacks()
|
||||
}
|
||||
|
||||
async readEmojiImage (nameOrAttachmentId) {
|
||||
const byName = this.emojiRegistry
|
||||
? await this.emojiRegistry.get(nameOrAttachmentId)
|
||||
@@ -3622,6 +3692,12 @@ class PearcordPlatform extends EventEmitter {
|
||||
guildEmojis: this.emojiRegistry
|
||||
? await this.emojiRegistry.list()
|
||||
: [],
|
||||
guildEmojiPacks: this.emojiRegistry
|
||||
? await this.emojiRegistry.listPacks()
|
||||
: [],
|
||||
emojisByPack: this.emojiRegistry
|
||||
? await this.emojiRegistry.emojisByPack()
|
||||
: { packs: [], uncategorized: [] },
|
||||
guildStickers: this.stickerRegistry
|
||||
? await this.stickerRegistry.list()
|
||||
: [],
|
||||
|
||||
Reference in New Issue
Block a user