diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 226854b..c7ea37d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -20,6 +20,7 @@ jobs: source ~/.nvm/nvm.sh cd farcaster-praise-bot git pull origin main + npm install -g bun pm2 stop all bun install pm2 start all \ No newline at end of file diff --git a/src/routes/bot.ts b/src/routes/bot.ts index 22f296c..353c19e 100644 --- a/src/routes/bot.ts +++ b/src/routes/bot.ts @@ -7,18 +7,46 @@ const bot = async (req: Request) => { } const body = await req.text(); const hookData = JSON.parse(body); + const { channel, author, text, mentioned_profiles } = hookData; + const praiseHandle = process.env.PRAISE_FARCASTER_HANDLE; + const praiseReceiver = mentioned_profiles.find((profile: any) => profile.username !== praiseHandle) + if (!praiseReceiver) { + await neynarClient.publishCast( + process.env.SIGNER_UUID, + `gm ${author.username}! Please mention a Farcaster account to praise for`, + { + replyTo: hookData.data.hash, + } + ); + } + let index = text.indexOf('for'); + let reason + if (index !== -1) { + reason = text.substring(index); + } else { + // There's no 'for' in the praise + reason = text.split(praiseReceiver.username)[1] + } + const query = { + reason, + channel, + giver: author.username, + recipient: praiseReceiver.verified_addresses.eth_addresses[0] || praiseReceiver.custody_address + }; console.log('--------------------') console.log(hookData.data) console.log('--------------------') + console.log(query) + console.log('--------------------') const reply = await neynarClient.publishCast( process.env.SIGNER_UUID, - `gm ${hookData.data.author.username}`, + `gm ${author.username}`, { embeds: [ { - url: process.env.APP_URL!, + url: process.env.APP_URL + '?' + new URLSearchParams(query), }, ], replyTo: hookData.data.hash,