mirror of
https://github.com/stronk-dev/RandomChad.git
synced 2025-07-05 02:35:08 +02:00
✨ add discord webhook notification by Gretal
This commit is contained in:
parent
5cb4511dc9
commit
37a55955da
@ -4,6 +4,7 @@ const { dev, log } = require( '../modules/helpers' )
|
||||
const { ask_signer_is_for_available_emails } = require( './signer_is' )
|
||||
const { send_outfit_available_email } = require( './ses' )
|
||||
const { throttle_and_retry } = require( '../modules/helpers' )
|
||||
const { notify_discord_of_outfit_notifications } = require( './discord' )
|
||||
|
||||
// Web3 APIs
|
||||
const { getOwingAddressOfTokenId } = require( '../modules/contract' )
|
||||
@ -214,7 +215,7 @@ exports.notify_holders_of_changing_room_updates = async context => {
|
||||
|
||||
// Get all Rocketeers with outfits available
|
||||
const network = dev ? `rinkeby` : `mainnet`
|
||||
const limit = dev ? 5000 : 5000 // max supply 3475
|
||||
const limit = dev ? 5 : 5000 // max supply 3475
|
||||
console.log( `Getting ${ limit } rocketeers on ${ network }` )
|
||||
let all_rocketeers = await db.collection( `${ network }Rocketeers` ).limit( limit ).get().then( dataFromSnap )
|
||||
console.log( `Got ${ all_rocketeers.length } Rocketeers` )
|
||||
@ -301,6 +302,9 @@ exports.notify_holders_of_changing_room_updates = async context => {
|
||||
// Log result
|
||||
console.log( `Sent ${ owners_to_email.length } emails for ${ network } outfits` )
|
||||
|
||||
// Notify Discord too
|
||||
await notify_discord_of_outfit_notifications( owners_to_email.length )
|
||||
|
||||
|
||||
} catch( e ) {
|
||||
console.error( `notify_holders_of_changing_room_updates error: `, e )
|
||||
|
@ -1,6 +1,7 @@
|
||||
const functions = require( 'firebase-functions' )
|
||||
const { discord } = functions.config()
|
||||
const fetch = require( 'isomorphic-fetch' )
|
||||
const { dev } = require('../modules/helpers')
|
||||
|
||||
exports.notify_discord_of_new_outfit = async function( username, content, avatar_url, image_title, image_url ) {
|
||||
|
||||
@ -34,4 +35,33 @@ exports.notify_discord_of_new_outfit = async function( username, content, avatar
|
||||
console.error( 'Discord error ', e )
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.notify_discord_of_outfit_notifications = async function( amount=0 ) {
|
||||
|
||||
if( !dev && amount == 0 ) return console.log( `Not sending Discord message for 0 updates` )
|
||||
|
||||
try {
|
||||
|
||||
// Construct discord webhook message
|
||||
const message = {
|
||||
username: "Gretal Marchall Alon of Jupiter",
|
||||
content: `I emailed ${ amount } Rocketeer holders to tell them they have new outfits available in the changing room at https://mint.rocketeer.fans/#/outfits. Want to get email notifications too? Create an email address for your wallet at: https://signer.is/#/email, you'll get a monthly email when your Rocketeers have outfits available.`,
|
||||
avatar_url: "https://storage.googleapis.com/rocketeer-nft.appspot.com/mainnetRocketeers/1.jpg"
|
||||
}
|
||||
|
||||
// Construct request options
|
||||
const options = {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify( message )
|
||||
}
|
||||
|
||||
// Make webhook request
|
||||
const data = await fetch( discord.chatterwebhookurl, options )
|
||||
|
||||
} catch( e ) {
|
||||
console.error( 'Discord error ', e )
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user