-
Notifications
You must be signed in to change notification settings - Fork 8
/
parser.js
95 lines (79 loc) · 2.33 KB
/
parser.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
"use strict";
const TRY = (process.argv.indexOf("try") > -1)
require('dotenv').config();
const Filter = require('bad-words');
const customFilter = new Filter({ placeHolder: '*'});
//customFilter.addWords('words','here');
const Grapheme = require('grapheme-splitter');
var splitter = new Grapheme();
const htmlparser2 = require('htmlparser2');
function processInput(toot) {
if (TRY) return toot.text.trim();
var out = '';
var ignore = 0;
const htmlparser = new htmlparser2.Parser({
onopentag(name, attributes) {
if (ignore) {
++ignore;
return;
}
var c = attributes['class'];
if (c !== undefined && c.match(/\b(?:mention|hashtag)\b/)) {
ignore = 1;
return;
}
if (name === 'p' || name === 'br') out += '\n';
},
ontext(text) {
if (!ignore) out += text;
},
onclosetag(name) {
if (ignore) --ignore;
},
});
console.log(toot.text)
htmlparser.parseComplete(toot.text);
out = out.trim();
out = out.replace(/[“”]/g,'"');
console.log(out)
return out;
}
function parseTweet(toot){
var graphemes = splitter.splitGraphemes(toot.text.trim());
var one_hour = 2000000*60*60;
var c = {
emulator: "beebjit",
flags: "-accurate -rom 7 roms/gxr.rom -opt video:paint-start-cycles=60680000,video:border-chars=0 -frame-cycles 1 -max-frames 150",
cycles: 69000000,
compressed: false,
input: "",
mode: 1,
}
for (let i = 0; i<graphemes.length; i++){
switch (graphemes[i]){
case "🚀": // Snapshot after three hours emulation time
c.emulator = "beebjit";
c.flags = " -frame-cycles "+3*one_hour+" -opt video:border-chars=0";
c.mode = 2;
c.cycles = (3*one_hour+4000000000);
break;
case "🎬": // Fast run 3 hours then 3 seconds time lapse
c.emulator = "beebjit";
c.flags = "-opt video:paint-start-cycles="+(3*one_hour)+",video:border-chars=0 -frame-cycles 1 -max-frames 150";
c.cycles = ((3*one_hour)+8000000);
c.mode = 3;
break;
default:
c.input += graphemes[i];
var g = graphemes[i].codePointAt(0);
}
}
toot.text = c.input;
c.input = processInput(toot);
c.rude = (customFilter.clean(c.input) != c.input);
console.log("\n",c);
return c;
}
module.exports = {
parseTweet: parseTweet
};