Skip to content

Commit

Permalink
feat: add entitlement logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Snazzah committed Dec 14, 2024
1 parent 2f62652 commit cc4bbe0
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,29 @@ export async function onEntitlementCreate(entitlement: Eris.Entitlement) {
}
});
}

if (process.env.DISCORD_ENTITLEMENT_WEBHOOK)
await fetch(process.env.DISCORD_ENTITLEMENT_WEBHOOK, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
content: `https://discord.com/application-directory/${entitlement.applicationID}/store/${entitlement.skuID}`,
embeds: [{
title: `Entitlement Created${!entitlement.startsAt ? ' [Test]' : ''}`,
color: 0x2ecc71,
description: [
`SKU: ${entitlement.skuID}`,
`User ID: ${entitlement.userID ?? '<none>'}`,
`Guild ID: ${entitlement.guildID ?? '<none>'}`,
`Starts At: ${entitlement.startsAt ? `<t:${Math.round(new Date(entitlement.startsAt).valueOf() / 1000)}` : '<none>'}`,
`Ends At: ${entitlement.endsAt ? `<t:${Math.round(new Date(entitlement.endsAt).valueOf() / 1000)}` : '<none>'}`,
`Type: ${Eris.Constants.EntitlementTypes[entitlement.type] ?? '<unknown>'} (${entitlement.type})`
].join('\n')
}]
})
}).catch(() => {});
}

export async function onEntitlementUpdate(entitlement: Eris.Entitlement) {
Expand Down Expand Up @@ -122,6 +145,29 @@ export async function onEntitlementUpdate(entitlement: Eris.Entitlement) {
console.error(`Error while updating entitlement [${entitlement.id}]`, e);
return;
}

if (process.env.DISCORD_ENTITLEMENT_WEBHOOK)
await fetch(process.env.DISCORD_ENTITLEMENT_WEBHOOK, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
content: `https://discord.com/application-directory/${entitlement.applicationID}/store/${entitlement.skuID}`,
embeds: [{
title: `Entitlement Updated${!entitlement.startsAt ? ' [Test]' : ''}`,
color: 0xe67e22,
description: [
`SKU: ${entitlement.skuID}`,
`User ID: ${entitlement.userID ?? '<none>'}`,
`Guild ID: ${entitlement.guildID ?? '<none>'}`,
`Starts At: ${entitlement.startsAt ? `<t:${Math.round(new Date(entitlement.startsAt).valueOf() / 1000)}` : '<none>'}`,
`Ends At: ${entitlement.endsAt ? `<t:${Math.round(new Date(entitlement.endsAt).valueOf() / 1000)}` : '<none>'}`,
`Type: ${Eris.Constants.EntitlementTypes[entitlement.type] ?? '<unknown>'} (${entitlement.type})`
].join('\n')
}]
})
}).catch(() => {});
}

export async function onEntitlementDelete(entitlement: Eris.Entitlement) {
Expand All @@ -140,6 +186,27 @@ export async function onEntitlementDelete(entitlement: Eris.Entitlement) {
console.error(`Error while deleting entitlement [${entitlement.id}]`, e);
return;
}

if (process.env.DISCORD_ENTITLEMENT_WEBHOOK)
await fetch(process.env.DISCORD_ENTITLEMENT_WEBHOOK, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
content: `https://discord.com/application-directory/${entitlement.applicationID}/store/${entitlement.skuID}`,
embeds: [{
title: `Entitlement Deleted${!entitlement.startsAt ? ' [Test]' : ''}`,
color: 0xe74c3c,
description: [
`SKU: ${entitlement.skuID}`,
`User ID: ${entitlement.userID ?? '<none>'}`,
`Guild ID: ${entitlement.guildID ?? '<none>'}`,
`Type: ${Eris.Constants.EntitlementTypes[entitlement.type] ?? '<unknown>'} (${entitlement.type})`
].join('\n')
}]
})
}).catch(() => {});
}

async function updateGuildBenefits(guildId: string) {
Expand Down

0 comments on commit cc4bbe0

Please sign in to comment.