-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunfollow.js
More file actions
78 lines (62 loc) · 1.64 KB
/
unfollow.js
File metadata and controls
78 lines (62 loc) · 1.64 KB
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
var steem = require('steem');
class Unfollow {
constructor(user, listToUnfollow, password) {
this.user = user;
this.listToUnfollow = listToUnfollow;
this.password = password;
}
setListToUnfollow(newList) {
this.listToUnfollow = newList;
}
makeCustomJson(friend) {
var result = []
result.push('follow');
const custom_json = {
follower: this.user,
following : friend,
what: []
}
result.push(custom_json);
return JSON.stringify(result);
}
makeTranzaction(friend) {
var tranzaction = ['custom_json'];
var json = {
required_auths: [],
required_posting_auths: [this.user],
id: 'follow',
json: this.makeCustomJson(friend)
}
tranzaction.push(json);
return tranzaction;
}
unfollowFriends() {
var tranzactions = []
for(var i=0; i< this.listToUnfollow.length; i++) {
tranzactions.push(this.makeTranzaction(this.listToUnfollow[i]));
}
return steem.broadcast.sendAsync(
{
extensions: [],
operations: tranzactions
}, [this.password]);
}
}
function getListOfFriends(apiFollowingResponse) {
var res = []
for(var i=0; i<apiFollowingResponse.length; i++) {
res.push(apiFollowingResponse[i]['following']);
}
return res;
}
async function main() {
const LIMIT = 10;
const NAME = ''
const PASSWORD = ''
var unf = new Unfollow(NAME, [], PASSWORD);
const apiListOfFollowing = await steem.api.getFollowingAsync(NAME, '', 'blog', LIMIT);
unf.setListToUnfollow(getListOfFriends(apiListOfFollowing));
const unfollowRes = await unf.unfollowFriends();
// console.log(unfollowRes);
}
main()