mirror of
https://github.com/tornadocash/trusted-setup-server.git
synced 2024-11-24 10:59:45 +01:00
update logic
This commit is contained in:
parent
49b87d51b3
commit
ef1693cfec
@ -7,7 +7,8 @@ const {
|
|||||||
TWITTER_ACCESS_TOKEN_KEY,
|
TWITTER_ACCESS_TOKEN_KEY,
|
||||||
TWITTER_ACCESS_TOKEN_SECRET,
|
TWITTER_ACCESS_TOKEN_SECRET,
|
||||||
NUXT_ENV_TWITTER_HASHTAG,
|
NUXT_ENV_TWITTER_HASHTAG,
|
||||||
TWITTER_INTERVAL_ATTESTATION
|
TWITTER_INTERVAL_ATTESTATION,
|
||||||
|
NODE_ENV
|
||||||
} = process.env
|
} = process.env
|
||||||
|
|
||||||
const client = new Twitter({
|
const client = new Twitter({
|
||||||
@ -19,24 +20,15 @@ const client = new Twitter({
|
|||||||
|
|
||||||
const { Contribution } = require('./models')
|
const { Contribution } = require('./models')
|
||||||
|
|
||||||
async function attestationWatcher() {
|
function attestationWatcher() {
|
||||||
// get the last saved tweet
|
// get the last saved tweet
|
||||||
let initTweet
|
let initTweet
|
||||||
try {
|
try {
|
||||||
initTweet = require('/tmp/lastTweet.json').lastTweet
|
initTweet = require('/tmp/lastTweet.json').lastTweet
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
initTweet = process.env.LAST_TWEET
|
initTweet = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// get all contributions without attestation
|
|
||||||
const contributions = await Contribution.findAll({
|
|
||||||
where: {
|
|
||||||
socialType: 'twitter',
|
|
||||||
attestation: null
|
|
||||||
},
|
|
||||||
attributes: ['id', 'handle', 'socialType', 'attestation']
|
|
||||||
})
|
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
since_id: initTweet,
|
since_id: initTweet,
|
||||||
q: `#${NUXT_ENV_TWITTER_HASHTAG} -filter:retweets`,
|
q: `#${NUXT_ENV_TWITTER_HASHTAG} -filter:retweets`,
|
||||||
@ -45,20 +37,48 @@ async function attestationWatcher() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// search tweets with params
|
// search tweets with params
|
||||||
client.get('search/tweets', params, function(error, tweets, response) {
|
client.get('search/tweets', params, async function(error, tweets, response) {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
tweets.statuses.forEach((tweet) => {
|
for (const tweet of tweets.statuses) {
|
||||||
contributions.forEach((contribution) => {
|
if (NODE_ENV === 'development') {
|
||||||
// compare account compliance
|
console.log(
|
||||||
if (contribution.handle === tweet.user.screen_name) {
|
'\x1B[36m%s\x1B[0m',
|
||||||
// update the database record by id
|
`${tweet.text} https://twitter.com/${tweet.user.screen_name}/status/${tweet.id_str}`
|
||||||
Contribution.update({ attestation: tweet.id_str }, { where: { id: contribution.id } })
|
)
|
||||||
console.log(
|
}
|
||||||
`Succesful attestation https://${contribution.socialType}.com/${contribution.handle}/status/${tweet.id_str}`
|
|
||||||
|
// find the contribution id in a tweet
|
||||||
|
let matchTweetContributionId = null
|
||||||
|
let tweetContributionId = null
|
||||||
|
|
||||||
|
if ((matchTweetContributionId = tweet.text.match(/#([0-9]+)/))) {
|
||||||
|
tweetContributionId = Number(matchTweetContributionId[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
// if found the contribution id then search a contribution
|
||||||
|
if (tweetContributionId) {
|
||||||
|
// try update the database record by id
|
||||||
|
try {
|
||||||
|
const result = await Contribution.update(
|
||||||
|
{ attestation: tweet.id_str },
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
id: tweetContributionId,
|
||||||
|
handle: tweet.user.screen_name,
|
||||||
|
attestation: null
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
if (result[0]) {
|
||||||
|
console.log(
|
||||||
|
`Succesful attestation #${tweetContributionId} https://twitter.com/${tweet.user.screen_name}/status/${tweet.id_str}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
// save the last tweet received
|
// save the last tweet received
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
|
@ -53,7 +53,7 @@ const actions = {
|
|||||||
window.location.replace(`/api/connect/${provider}`)
|
window.location.replace(`/api/connect/${provider}`)
|
||||||
},
|
},
|
||||||
makeTweet({ state }) {
|
makeTweet({ state }) {
|
||||||
const tweetText = `Just made the contribution %23${state.contributionIndex} to Tornado.cash Trusted Setup Ceremony! 🚀 %23${process.env.NUXT_ENV_TWITTER_HASHTAG}`
|
const tweetText = `Just made the contribution %23${state.contributionIndex} to @TornadoCash Trusted Setup Ceremony! 🚀 %23${process.env.NUXT_ENV_TWITTER_HASHTAG}`
|
||||||
const popUpWindowWidth = 600
|
const popUpWindowWidth = 600
|
||||||
const popUpWindowHeight = 250
|
const popUpWindowHeight = 250
|
||||||
const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX
|
const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX
|
||||||
|
Loading…
Reference in New Issue
Block a user