This repository has been archived by the owner on Dec 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
sessionController.js
executable file
·134 lines (116 loc) · 3.43 KB
/
sessionController.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
var mongo = require("./mongo.js");
var assert = require("assert");
var autolike = require("./autolike.js");
var instaSessionController = require("./instaSessionController.js");
var _ = require('underscore');
var Log = require("./log.js");
var logger = new Log();
var db;
var sessions;
var init = function()
{
mongo(function(_db)
{
db = _db;
sessions = _db.collection("sessions");
cleanAllLikeSession();
setNotRunning();
setInterval(checkSessions, 2000);
logger.log("SessionController initialized");
});
}
var newLikeSession = function(creator)
{
var accounts = db.collection("accounts");
cleanLikeSession(creator);
accounts.findOne({username: creator}, function(error, user)
{
assert.equal(null, error);
if(user)
{
var dateNow = new Date();
var minutes = _.random(parseInt(user.settings.autoLike.sessionDelayMin), parseInt(user.settings.autoLike.sessionDelayMax));
var sessionDate = new Date(dateNow.getTime() + minutes * 60000);
if(user.settings.autoLike.likeByTagList)
{
var tags = user.settings.autoLike.likeByTagList.split(" ");
var tag = tags[_.random(0, tags.length - 1)];
var likeCountMin = parseInt(user.settings.autoLike.likeCountMin);
var likeCountMax = parseInt(user.settings.autoLike.likeCountMax);
var likeCount = _.random(likeCountMin, likeCountMax);
var sessionObject =
{
date: sessionDate,
type: "Likebot",
sourceType: "tag",
source: tag,
likeCount: likeCount,
creator: creator,
executed: false,
mediaList: [],
likesDone: 0
};
logger.log("Initializing new like session");
db.collection("sessions").insert(sessionObject);
}
}
})
}
var cleanLikeSession = function(username)
{
var sessions = db.collection("sessions");
sessions.remove({type: "Likebot", creator: username});
}
var cleanAllLikeSession = function()
{
var sessions = db.collection("sessions");
sessions.remove({type: "Likebot"});
}
function checkSessions()
{
sessions.find({}, function(error, data)
{
assert.equal(null, error);
if(data)
{
var date = new Date();
data.forEach(function(session)
{
var sessionDate = new Date(session.date);
if(sessionDate.getMinutes() == date.getMinutes() && sessionDate.getHours() == date.getHours() && !session.executed)
{
var type = session.type;
logger.log("Found session to execute, type: " + type);
if(type == "Likebot")
{
var sourceType = session.sourceType;
if(sourceType == "tag")
{
instaSessionController.getSession(session.creator, function(instaSession)
{
exp =
{
newLikeSession: newLikeSession,
cleanLikeSession: cleanLikeSession
}
logger.log("Initializing new like session");
autolike.likeByTag(session, instaSession, exp);
});
}
}
db.collection("sessions").update({_id: session._id}, {$set : {executed: true}}, function(){});
}
});
}
});
}
function setNotRunning()
{
db.collection("accounts").updateMany({}, {$set: {"settings.autoLike.running": false}});
}
module.exports =
{
newLikeSession: newLikeSession,
init: init,
cleanLikeSession: cleanLikeSession
}