Skip to content

Commit

Permalink
Merge pull request #12 from Adamant-im/dev
Browse files Browse the repository at this point in the history
v1.7.0
  • Loading branch information
gost1k337 authored Nov 1, 2022
2 parents 865b909 + de23622 commit d3a0f4b
Show file tree
Hide file tree
Showing 12 changed files with 23,456 additions and 88 deletions.
1 change: 0 additions & 1 deletion .gitignore
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
Expand Down
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function init() {
require('./modules/apiTester');
require('./modules/checkTwitterReqs');
require('./modules/checkTwitterRetweet');
require('./modules/checkTwitterRetweetwComment');
require('./modules/checkAdamantContacts');
require('./modules/checkAll');
require('./modules/outAddressFetcher');
Expand Down
26 changes: 17 additions & 9 deletions config.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
**/
"passPhrase": "qwert yuiop asdfg hjkl zxcvb nmqwe",

/**
/**
List of nodes to fetch transactions.
If one become unavailable, pool will choose live one.
**/
"node_ADM": [
"http://localhost:36666",
"https://endless.adamant.im",
"http://localhost:36666",
"https://clown.adamant.im",
"https://bid.adamant.im",
"https://unusual.adamant.im",
Expand Down Expand Up @@ -64,14 +64,15 @@
/** How to reply user in-chat, if first unknown command received. **/
"welcome_string": "Hi! 😊 I'm a bounty bot. And this is a stub. Are you ready for the awesome bounty campaign with automatic payout? Type **/help** to see bounty rules.",

/**
/**
Bounty rules. Shown by /help command. You can use template literals
like ${config.rewards_list}, ${config.rewards_tickers}, ${config.twitter_follow[0]},
${config.twitter_retweet[0].tweet}, ${config.twitter_retweet_list},
${config.twitter_retweet_w_comment[0].tweet}, ${config.twitter_follow_list},
${config.twitter_retweet_w_comment[0].min_mentions}, ${config.twitter_retweet_w_comment[0].tag_list},
${config.twitterEligibleString}
**/
"help_message": "Earn **${config.rewards_tickers}** with your social activity! A reward depends on how much Twitter followers you have. Your account ${config.twitterEligibleString}.\n${config.rewards_range}\n\n \nThe campaign rules:\n- Follow account ${config.twitter_follow_list} on Twitter\n- Like & quote ${config.twitter_retweet_w_comment[0].tweet}, mentioning ${config.twitter_retweet_w_comment[0].min_mentions} friends and ${config.twitter_retweet_w_comment[0].tag_list} tags.\n- Invite ${config.adamant_campaign.min_contacts} friend in ADAMANT Messenger. They must message you.\n- Send me the name (like @adamant_im) or the link to your Twitter profile to verify.\n\n \nGo!",
"help_message": "Earn **${config.rewards_tickers}** with your social activity! A reward depends on how much Twitter followers you have. Your account ${config.twitterEligibleString}.\n${config.rewards_range}\n\n \nThe campaign rules:\n- Follow account ${config.twitter_follow_list} on Twitter\n- Like & quote ${config.twitter_retweet_w_comment?.[0].tweet}, mentioning ${config.twitter_retweet_w_comment?.[0].min_mentions} friends and ${config.twitter_retweet_w_comment?.[0].tag_list} tags.\n- Like & retweet ${config.twitter_retweet_list}\n- Invite ${config.adamant_campaign.min_contacts} friend in ADAMANT Messenger. They must message you.\n- Send me the name (like @adamant_im) or the link to your Twitter profile to verify.\n\n \nGo!",

/** Bot's name for notifications **/
"bot_name": "Lovely Bounty Bot",
Expand All @@ -94,7 +95,7 @@
"min_days": 20
},

/**
/**
Tweets user should quote (retweet with comment).
Min_mentions is how much people he should mention. Hashtags is a list of tags he must use.
**/
Expand All @@ -111,7 +112,14 @@
}
],

/**
/** Tweets user should retweet **/
"twitter_retweet": [
{
"tweet": "https://twitter.com/adamant_im/status/1272945640574722048"
}
],

/**
Minimum contacts user must invite to ADAMANT Messenger.
Contacts must be new users.
0 is disabled.
Expand All @@ -132,7 +140,7 @@
}
],

/**
/**
Set progressive scale of reward amounts for each cryptocurrency,
Where `func` is a mathjs.org function. Limit followers with `limit_followers` parameter.
If not set for a currency, plain amount is used, which is set in `rewards.amount`.
Expand All @@ -154,7 +162,7 @@
"access_token_secret": ""
},

/**
/**
Interval in minutes to test Twitter API. Because of different reasons Twitter may temporary block API requests.
To continue, you need manually login into your Twitter account and solve captcha.
This parameter allows to automatically check if Twitter API works well every twitter_api_test_interval minutes.
Expand All @@ -178,7 +186,7 @@
/** If you want to receive notifications when user receives a Bounty reward **/
"notifyRewardReceived": true,

/**
/**
Port for getting debug info.
Do not set for live exchange bots, use only for debugging.
Allows to get DBs records like http://ip:port/db?tb=IncomingTxs
Expand Down
2 changes: 1 addition & 1 deletion modules/DB.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const log = require('../helpers/log');
const MongoClient = require('mongodb').MongoClient;
const mongoClient = new MongoClient('mongodb://localhost:27017/', {useNewUrlParser: true, useUnifiedTopology: true, serverSelectionTimeoutMS: 3000});
const mongoClient = new MongoClient('mongodb://127.0.0.1:27017/', {useNewUrlParser: true, useUnifiedTopology: true, serverSelectionTimeoutMS: 3000});
const model = require('../helpers/dbModel');
const config = require('./configReader');

Expand Down
2 changes: 2 additions & 0 deletions modules/checkAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = async () => {
userId,
isTwitterFollowCheckPassed,
isTwitterRetweetCommentCheckPassed,
isTwitterRetweetCheckPassed,
isAdamantCheckPassed,
twitterAccount,
twitterFollowers,
Expand All @@ -39,6 +40,7 @@ module.exports = async () => {
if (
((config.twitter_follow.length === 0) || isTwitterFollowCheckPassed) &&
((config.twitter_retweet_w_comment.length === 0) || isTwitterRetweetCommentCheckPassed) &&
((config.twitter_retweet.length === 0) || isTwitterRetweetCheckPassed) &&
((config.adamant_campaign.min_contacts === 0) || isAdamantCheckPassed)
) {
await user.update({
Expand Down
82 changes: 22 additions & 60 deletions modules/checkTwitterRetweet.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ module.exports = async () => {
$and: [
{isInCheck: true},
{isTwitterAccountEligible: true},
{isTwitterRetweetCommentCheckPassed: false},
{$or: [
{isTwitterFollowCheckPassed: true},
{$expr: {$eq: [0, config.twitter_follow.length]}},
]},
{isTwitterRetweetCheckPassed: false},
{
$or: [
{isTwitterFollowCheckPassed: true},
{$expr: {$eq: [0, config.twitter_follow.length]}},
],
},
{isTasksCompleted: false},
{$or: [
{isAdamantCheckPassed: true},
{$expr: {$eq: [0, config.adamant_campaign.min_contacts]}},
]},
{
$or: [
{isAdamantCheckPassed: true},
{$expr: {$eq: [0, config.adamant_campaign.min_contacts]}},
],
},
],
});

Expand All @@ -44,66 +48,24 @@ module.exports = async () => {
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);
for (let index = 0; index < config.twitter_retweet.length; index++) {
toRetweet = config.twitter_retweet[index].tweet;
retweetResult = await twitterapi.checkIfAccountRetweeted(twitterAccount, toRetweet);
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,
isTwitterRetweetCheckPassed: false,
isInCheck: false,
isTasksCompleted: false,
}, true);
switch (retweetResult.error) {
case ('no_retweet'):
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;
if (retweetResult.error === 'no_retweet') {
msgSendBack = `To meet the Bounty campaign rules, you should retweet ${toRetweet}.`;
msgSendBack += ` Then you apply again.`;
}

await api.sendMessageWithLog(config.passPhrase, userId, msgSendBack);
Expand All @@ -113,7 +75,7 @@ module.exports = async () => {
}
}
await user.update({
isTwitterRetweetCommentCheckPassed: isRetweeted,
isTwitterRetweetCheckPassed: isRetweeted,
}, true);
} catch (e) {
log.error(`Error in ${helpers.getModuleName(module.id)} module: ${e}`);
Expand All @@ -124,7 +86,7 @@ module.exports = async () => {
}
};

if (config.twitter_retweet_w_comment.length > 0) {
if (config.twitter_retweet.length > 0) {
setInterval(() => {
module.exports();
}, 11 * 1000);
Expand Down
135 changes: 135 additions & 0 deletions modules/checkTwitterRetweetwComment.js
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);
2 changes: 2 additions & 0 deletions modules/checkTxs.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module.exports = async (itx, tx) => {
isTasksCompleted: false,
isTwitterFollowCheckPassed: false,
isTwitterRetweetCommentCheckPassed: false,
isTwitterRetweetCheckPassed: false,
isTwitterAccountEligible: false,
});
} else {
Expand All @@ -77,6 +78,7 @@ module.exports = async (itx, tx) => {
isTasksCompleted: false,
isTwitterFollowCheckPassed: false,
isTwitterRetweetCommentCheckPassed: false,
isTwitterRetweetCheckPassed: false,
isTwitterAccountEligible: false,
isAdamantCheckPassed: false,
});
Expand Down
Loading

0 comments on commit d3a0f4b

Please sign in to comment.