feat(platform): wire pearcord-boosts APIs and view.guildBoost

Integrate PearcordBoosts with lazy module init, gossip ingest on
guild-boost, addGuildBoost/setGuildBoostBannerColor/getGuildBoost with
Manage Guild permission checks, audit guild.boost entries, and expose
guildBoost in platform.view() for UI accents and server settings.
This commit is contained in:
Raven Scott
2026-05-21 22:14:34 -04:00
parent 3f614a5c9c
commit 35ee850d17
2 changed files with 62 additions and 0 deletions
+61
View File
@@ -29,6 +29,7 @@ const {
PearcordAnnouncements,
formatCrosspostBody
} = require('pearcord-announcements')
const { PearcordBoosts } = require('pearcord-boosts')
const {
createInstallToken,
verifyInstallToken,
@@ -84,6 +85,7 @@ class PearcordPlatform extends EventEmitter {
this.voiceMedia = null
this.screenShare = null
this.announcements = null
this.boosts = null
this.slashCommands = null
this.emojiRegistry = null
this.botEvents = null
@@ -223,6 +225,8 @@ class PearcordPlatform extends EventEmitter {
await this.automod.ready()
this.announcements = new PearcordAnnouncements({ storagePath: this.storagePath })
await this.announcements.ready()
this.boosts = new PearcordBoosts({ storagePath: this.storagePath })
await this.boosts.ready()
this._forumTagFilter = null
this.guilds = await this.listGuilds()
await this._joinDiscoveryMesh()
@@ -783,6 +787,10 @@ class PearcordPlatform extends EventEmitter {
this.announcements?.ingestFollow(p).catch(() => {})
this.emit('announcements', p)
})
guildInstance.on('guild-boost', (p) => {
this.boosts?.ingestGossip(p).catch(() => {})
this.emit('guild-boost', p)
})
guildInstance.setAttachmentProvider(async (attachmentId) => {
const row = await this.attachments?.get(attachmentId)
if (!row) throw new Error('attachment not found')
@@ -1973,6 +1981,10 @@ class PearcordPlatform extends EventEmitter {
this.announcements = new PearcordAnnouncements({ storagePath: this.storagePath })
await this.announcements.ready()
}
if (!this.boosts) {
this.boosts = new PearcordBoosts({ storagePath: this.storagePath })
await this.boosts.ready()
}
const guildId = this.guild?.guild?.id
if (guildId && this.automod) this.automod.setGuild(guildId)
return { forum: this.forum, stage: this.stage, automod: this.automod }
@@ -2375,6 +2387,49 @@ class PearcordPlatform extends EventEmitter {
return row
}
async addGuildBoost (amount = 1) {
if (!this.guild?.guild) throw new Error('no guild')
const roles = await this._memberRoles()
if (!roleHasPermission(roles, PERMISSION.MANAGE_GUILD)) {
throw new Error('no permission to boost guild')
}
await this._ensureGuildModules()
const row = await this.boosts.addBoost(this.guild.guild.id, amount)
this.guild.gossipGuildBoost({
guildId: row.guildId,
boostCount: row.boostCount,
bannerColor: row.bannerColor,
updatedAt: Date.now()
})
await this._audit('guild.boost', { guildId: row.guildId, targetId: String(row.boostCount) })
this.emit('guild-boost', row)
return row
}
async setGuildBoostBannerColor (bannerColor) {
if (!this.guild?.guild) throw new Error('no guild')
const roles = await this._memberRoles()
if (!roleHasPermission(roles, PERMISSION.MANAGE_GUILD)) {
throw new Error('no permission to edit boost banner')
}
await this._ensureGuildModules()
const row = await this.boosts.setBannerColor(this.guild.guild.id, bannerColor)
this.guild.gossipGuildBoost({
guildId: row.guildId,
boostCount: row.boostCount,
bannerColor: row.bannerColor,
updatedAt: Date.now()
})
this.emit('guild-boost', row)
return row
}
async getGuildBoost () {
await this._ensureGuildModules()
if (!this.guild?.guild) return null
return this.boosts.get(this.guild.guild.id)
}
async unfollowAnnouncementChannel (channelId) {
if (!this.guild?.guild || !this.identity?.user) throw new Error('no guild')
await this._ensureGuildModules()
@@ -3069,6 +3124,10 @@ class PearcordPlatform extends EventEmitter {
}
announcementFollows = await this.announcements.listMyFollows(user.id, guild.id)
}
let guildBoost = null
if (guild && this.boosts) {
guildBoost = await this.boosts.get(guild.id)
}
return {
onboarded: this.onboarded,
user,
@@ -3115,6 +3174,7 @@ class PearcordPlatform extends EventEmitter {
announcementCrosspostByChannel,
announcementFollowing,
announcementFollows,
guildBoost,
myVoiceChannelId,
voiceMedia: this.voiceMedia?.snapshot() || null,
screenShare: this.screenShare?.snapshot() || null,
@@ -3242,6 +3302,7 @@ class PearcordPlatform extends EventEmitter {
this.voiceMedia = null
this.screenShare = null
this.announcements = null
this.boosts = null
this.removeAllListeners()
await this.db.close()
}
+1
View File
@@ -39,6 +39,7 @@
"pearcord-automod": "file:../pearcord-automod",
"pearcord-screen-share": "file:../pearcord-screen-share",
"pearcord-announcements": "git+https://git.ssh.surf/pearcord/pearcord-announcements.git#main",
"pearcord-boosts": "git+https://git.ssh.surf/pearcord/pearcord-boosts.git#main",
"hyperswarm": "^4.11.6",
"pearcord-shared": "file:../pearcord-shared"
}