forked from 1Crazymoney/yield-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add webhook for tvl spikes (DefiLlama#239)
- Loading branch information
1 parent
38b041c
commit 3e1e2d3
Showing
5 changed files
with
59 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const fetch = require('node-fetch'); | ||
|
||
// copy pasta from defillama-server | ||
module.exports.sendMessage = async (message, webhookUrl, formatted = true) => { | ||
const formattedMessage = formatted ? '```\n' + message + '\n```' : message; // Put it into a code block to prevent the format from getting messed up | ||
if (formattedMessage.length >= 2000) { | ||
const lines = message.split('\n'); | ||
if (lines.length <= 2) { | ||
throw new Error('Lines are too long, reaching infinite recursivity'); | ||
} | ||
const mid = Math.round(lines.length / 2); | ||
await sendMessage(lines.slice(0, mid).join('\n'), webhookUrl); | ||
await sendMessage(lines.slice(mid).join('\n'), webhookUrl); | ||
return; | ||
} | ||
// Example: https://gist.github.com/dragonwocky/ea61c8d21db17913a43da92efe0de634 | ||
// Docs: https://gist.github.com/dragonwocky/ea61c8d21db17913a43da92efe0de634 | ||
const response = await fetch(`${webhookUrl}?wait=true`, { | ||
method: 'post', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
content: formattedMessage, | ||
}), | ||
}).then((body) => body.json()); | ||
console.log('discord', response); | ||
}; |