-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostSuccessfulDonation.js
74 lines (67 loc) · 2.71 KB
/
postSuccessfulDonation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const umbril = require("./umbril");
const config = require("./config.js");
const updateTwitterBio = require("./updateTwitterBio");
const formatNumber = require("./formatNumber");
const sendTwitWithMedia = require("./twitWithMedia");
const supabase = require("./supabase");
async function checkForNewSuccessfulDonation() {
try {
let getJWTToken = await umbril.getJWTToken();
let lastPersonDonated = await umbril.lastDonation(getJWTToken);
let searchDonor = await supabase.searchDonor(lastPersonDonated);
if (searchDonor != null) {
if (!searchDonor.paid) {
let tweetPayLoad = {
id: searchDonor.id,
twitterUserID: searchDonor.twitterUserID,
defaultPayOut: searchDonor.defaultPayOut,
userScrenName: searchDonor.userScrenName,
idThread: searchDonor.idThread,
};
sendPaymentConfirmationTweet(tweetPayLoad);
//Update database
supabase.UpdateDonated(searchDonor.idThread);
//update BIO
updateTwitterBio();
}
}
} catch (err) {
//console.log(err);
}
}
async function sendPaymentConfirmationTweet(payload) {
// Who sent the tweet?
let name = payload.userScrenName;
// What is the text?
// If we want the conversation thread
let id = payload.idThread;
// console.log('Reply to: ', tweet)
// Start a reply back to the sender
let numPeople = "";
if (payload.defaultPayOut <= config.defaultPayOut) {
numPeople = "Thanks for donating the Sats back.";
} else if (payload.defaultPayOut >= config.powerToTip) {
numPeople = `Thanks to you ${Math.floor(payload.defaultPayOut / config.defaultPayOut)} more plebs @ ${config.defaultPayOut} Sats can now enjoy the #LightningNetwork ⚡. Use command: @${
config.twitteraccount
} !TIP ${config.maxTipAmount} to tip plebs ${config.maxTipAmount} Sats.`;
} else {
numPeople = `Thanks to you ${Math.floor(payload.defaultPayOut / config.defaultPayOut)} more plebs @ ${config.defaultPayOut} Sats can now enjoy the #LightningNetwork ⚡`;
}
replyText = `@${payload.userScrenName} ✅ @${payload.userScrenName} We have received your ${formatNumber(payload.defaultPayOut)} Sats donation! ${numPeople}`;
//Send Tweet
try {
let twitOut = await sendTwitWithMedia.twitWithMedia(replyText, false, id, true);
console.log("Twit sent");
} catch (err) {
console.log("Failed to twit from Power Of satoshi, trying again: ", err);
try {
let twitOut = await sendTwitWithMedia.twitWithMedia(replyText, false, id, true);
console.log("Twit sent");
} catch (err) {
console.log("PostSuccessfulDonation Error: ", err);
}
}
//Like tweet
sendTwitWithMedia.twitLove(id);
}
module.exports = checkForNewSuccessfulDonation;