-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Adamant-im/dev
v1.7.0
- Loading branch information
Showing
12 changed files
with
23,456 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
node_modules/ | ||
logs/ | ||
.vscode/ | ||
package-lock.json | ||
tests.js | ||
config.test | ||
.idea | ||
|
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
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,135 @@ | ||
const db = require('./DB'); | ||
const config = require('./configReader'); | ||
const helpers = require('../helpers/utils'); | ||
const api = require('./api'); | ||
const log = require('../helpers/log'); | ||
const twitterapi = require('./twitterapi'); | ||
|
||
let inProcess = false; | ||
|
||
module.exports = async () => { | ||
if (inProcess) return; | ||
inProcess = true; | ||
|
||
try { | ||
const {UsersDb} = db; | ||
|
||
// Called strictly after isTwitterFollowCheckPassed = true to eliminate userDb collisions | ||
const users = await UsersDb.find({ | ||
$and: [ | ||
{isInCheck: true}, | ||
{isTwitterAccountEligible: true}, | ||
{isTwitterRetweetCommentCheckPassed: false}, | ||
{$or: [ | ||
{isTwitterFollowCheckPassed: true}, | ||
{$expr: {$eq: [0, config.twitter_follow.length]}}, | ||
]}, | ||
{isTasksCompleted: false}, | ||
{$or: [ | ||
{isAdamantCheckPassed: true}, | ||
{$expr: {$eq: [0, config.adamant_campaign.min_contacts]}}, | ||
]}, | ||
], | ||
}); | ||
|
||
for (const user of users) { | ||
try { | ||
const { | ||
twitterAccount, | ||
userId, | ||
} = user; | ||
|
||
log.log(`Running module ${helpers.getModuleName(module.id)} for user ${userId}…`); | ||
|
||
let msgSendBack = ''; | ||
|
||
let toRetweet; | ||
let minMentions; | ||
let hashtags; | ||
let retweetResult; | ||
let isRetweeted; | ||
for (let index = 0; index < config.twitter_retweet_w_comment.length; index++) { | ||
toRetweet = config.twitter_retweet_w_comment[index].tweet; | ||
minMentions = config.twitter_retweet_w_comment[index].min_mentions; | ||
hashtags = config.twitter_retweet_w_comment[index].hashtags; | ||
retweetResult = await twitterapi.checkIfAccountRetweetedwComment(twitterAccount, toRetweet, minMentions, hashtags); | ||
isRetweeted = retweetResult.success; | ||
|
||
if (isRetweeted) { | ||
log.log(`User ${userId}… ${twitterAccount} did retweet ${toRetweet}.`); | ||
} else { | ||
// const friendsExample = ['@elonmusk', '@cz_binance', '@FabriLemus7', '@crypto', '@CryptoWhale']; | ||
// let friendsExampleString = ''; | ||
// for (let index = 0; index < friendsExample.length && index < minMentions; index++) { | ||
// friendsExampleString += friendsExample[index] + ' ' | ||
// } | ||
// friendsExampleString = friendsExampleString.trim(); | ||
|
||
await user.update({ | ||
isTwitterRetweetCommentCheckPassed: false, | ||
isInCheck: false, | ||
isTasksCompleted: false, | ||
}, true); | ||
switch (retweetResult.error) { | ||
case ('no_quote'): | ||
msgSendBack = `To meet the Bounty campaign rules, you should quote (retweet with comment) ${toRetweet}.`; | ||
if (minMentions > 0 && hashtags.length > 0) { | ||
msgSendBack += ` Mention ${minMentions} friends, and use ${config.twitter_retweet_w_comment[index].tag_list} tags.`; | ||
} else { | ||
if (minMentions > 0) { | ||
msgSendBack += ` Mention ${minMentions} friends.`; | ||
} | ||
if (hashtags.length > 0) { | ||
msgSendBack += ` Use ${config.twitter_retweet_w_comment[index].tag_list} tags.`; | ||
} | ||
} | ||
msgSendBack += ` Example: _Meet the ADAMANT blockchain messenger! @elonmusk @cz_binance @FabriLemus7 #privacy #crypto #anonymity #decentralization_`; | ||
msgSendBack += `. Then you apply again.`; | ||
break; | ||
case ('not_enough_mentions'): | ||
msgSendBack = `I see your quote.`; | ||
if (minMentions > 0) { | ||
msgSendBack += ` To meet the Bounty campaign rules, it should mention at least ${minMentions} friends.`; | ||
msgSendBack += ` Example: _Meet the ADAMANT blockchain messenger! @elonmusk @cz_binance @FabriLemus7 #privacy #crypto #anonymity #decentralization_`; | ||
} | ||
msgSendBack += `. Quote once again.`; | ||
break; | ||
case ('no_hashtags'): | ||
msgSendBack = `I see your quote.`; | ||
if (hashtags.length > 0) { | ||
msgSendBack += ` To meet the Bounty campaign rules, it should include ${config.twitter_retweet_w_comment[index].tag_list} tags.`; | ||
msgSendBack += ` Example: _Meet the ADAMANT blockchain messenger! @elonmusk @cz_binance @FabriLemus7 #privacy #crypto #anonymity #decentralization_`; | ||
} | ||
msgSendBack += `. Quote once again.`; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
await api.sendMessageWithLog(config.passPhrase, userId, msgSendBack); | ||
log.log(`User ${userId}… ${twitterAccount} did NOT retweet ${toRetweet}: ${retweetResult.error}. Message to user: ${msgSendBack}`); | ||
|
||
break; | ||
} | ||
} | ||
await user.update({ | ||
isTwitterRetweetCommentCheckPassed: isRetweeted, | ||
}, true); | ||
} catch (e) { | ||
log.error(`Error in ${helpers.getModuleName(module.id)} module: ${e}`); | ||
} | ||
} | ||
} finally { | ||
inProcess = false; | ||
} | ||
}; | ||
|
||
if (config.twitter_retweet_w_comment.length > 0) { | ||
setInterval(() => { | ||
module.exports(); | ||
}, 11 * 1000); | ||
} | ||
|
||
setInterval(() => { | ||
module.exports(); | ||
}, 11 * 1000); |
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
Oops, something went wrong.