From 2c1f80a045e746d1b9d6860909a702bec30abb14 Mon Sep 17 00:00:00 2001 From: Mentor Date: Fri, 17 Dec 2021 16:27:30 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20discord=20webhook=20functiona?= =?UTF-8?q?lity=20to=20the=20changing=20room?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/README.md | 2 ++ functions/nft-media/changing-room.js | 13 ++++++++++++- functions/package-lock.json | 14 ++++++++++++++ functions/package.json | 1 + 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/functions/README.md b/functions/README.md index 018fd0e..0baa7eb 100644 --- a/functions/README.md +++ b/functions/README.md @@ -1,4 +1,6 @@ ## Requirements - [ ] `./functions`: set Infura project ID through `firebase functions:config:set infura.projectid=` + - [ ] also set `integration.secret` + - [ ] also set `discord.webhookurl` - [ ] `./functions/package.json`: dependencies for backend, run `npm i` in `./functions` diff --git a/functions/nft-media/changing-room.js b/functions/nft-media/changing-room.js index fa7b456..e837f03 100644 --- a/functions/nft-media/changing-room.js +++ b/functions/nft-media/changing-room.js @@ -3,13 +3,13 @@ const { getRgbArrayFromColorName, randomNumberBetween } = require( '../modules/h const { getTokenIdsOfAddress } = require( '../modules/contract' ) const svgFromAttributes = require( './svg-generator' ) const Throttle = require( 'promise-parallel-throttle' ) +const { notifyDiscordWebhook } = require( '../integrations/discord' ) // /////////////////////////////// // Rocketeer generator // /////////////////////////////// async function generateNewOutfitFromId( id, network='mainnet' ) { - /* /////////////////////////////// // Changing room variables // /////////////////////////////*/ @@ -87,8 +87,19 @@ async function generateNewOutfitFromId( id, network='mainnet' ) { // Path format of new rocketeers is id-outfitnumber.{svg,jpg} try { + // Generate new outfit const newOutfitSvg = await svgFromAttributes( rocketeer.attributes, `${ network }Rocketeers/${ id }-${ available_outfits + 1 }` ) + // Notify discord + const [ firstname ] = rocketeer.name.split( ' ' ) + await notifyDiscordWebhook( + rocketeer.name, + `${ firstname } obtained a new outfit on ${ network }!`, + rocketeer.image, + `Outfit #${ available_outfits + 1 }`, + newOutfitSvg.replace( '.svg','.jpg' ) + ) + return newOutfitSvg } catch( e ) { diff --git a/functions/package-lock.json b/functions/package-lock.json index ad2c129..70cac92 100644 --- a/functions/package-lock.json +++ b/functions/package-lock.json @@ -3837,6 +3837,15 @@ "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=" }, + "isomorphic-fetch": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz", + "integrity": "sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==", + "requires": { + "node-fetch": "^2.6.1", + "whatwg-fetch": "^3.4.1" + } + }, "isstream": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", @@ -6366,6 +6375,11 @@ } } }, + "whatwg-fetch": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.2.tgz", + "integrity": "sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==" + }, "whatwg-mimetype": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-3.0.0.tgz", diff --git a/functions/package.json b/functions/package.json index 4dc0401..13449ba 100644 --- a/functions/package.json +++ b/functions/package.json @@ -21,6 +21,7 @@ "express": "^4.17.1", "firebase-admin": "^10.0.0", "firebase-functions": "^3.11.0", + "isomorphic-fetch": "^3.0.0", "jsdom": "^18.0.0", "promise-parallel-throttle": "^3.3.0", "puppeteer": "^12.0.0",