-
Notifications
You must be signed in to change notification settings - Fork 0
/
PurgeComments.js
executable file
·73 lines (65 loc) · 2.02 KB
/
PurgeComments.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
#!/usr/bin/env node
var { FB, FacebookApiException } = require("fb");
//const REGEX = /^(?:(?:\(?(?:00|\+)([1-4]\d\d|[1-9]\d?)\)?)?[\-\.\ \\\/]?)?((?:\(?\d{1,}\)?[\-\.\ \\\/]?){0,})(?:[\-\.\ \\\/]?(?:#|ext\.?|extension|x)[\-\.\ \\\/]?(\d+))?/i;
const REGEX = /\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*/i;
const EREGEX = /\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$/i;
const IDREGEX = /id=\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*/i;
const SREGEX = /\/*\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*\//i;
var program = require("commander");
program.version("0.1.0").option("-o, --offset [offset]", "Offset", parseInt);
//
program.command("remove-comments <access-token>").action(function(cmd) {
let offset = program.offset || 0;
FB.setAccessToken(cmd);
FB.api(
"/me/posts",
"GET",
{
fields: "comments{can_hide,message, is_hidden}",
limit: "100",
pretty: "0",
offset,
},
function(response) {
for (var p of response.data) {
if (p["comments"]) {
// We need to page this.
console.log(p.comments.paging)
let commentsWithPhones = p.comments.data.filter(
m =>
!(
IDREGEX.test(m.message) ||
SREGEX.test(m.message)
) && REGEX.test(m.message)
);
commentsWithPhones.forEach(m =>
console.log(m.id, m.message, m.can_hide, m.is_hidden)
);
if (commentsWithPhones.filter(m => !m.is_hidden).length) {
for (var m of commentsWithPhones
.filter(m => !m.is_hidden)
.filter(m => m.can_hide)) {
FB.api(
`/${m.id}`,
"POST",
{
is_hidden: true,
},
function(response2) {
console.log(response2);
if (response2 && !response2.error) {
/* handle the result */
}
}
);
}
}
}
}
}
);
});
program.parse(process.argv);
if (!process.argv.slice(2).length) {
program.outputHelp();
}