-
Notifications
You must be signed in to change notification settings - Fork 3
/
tippyv014.js
2299 lines (2101 loc) · 90.2 KB
/
tippyv014.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// No need to modify these dependencies and variables below
var steem = require('steem');
var fs = require('fs');
require('events')._setMaxListeners = 0;
var prompt = require('prompt');
var colors = require('colors');
var version = "@Tippy ALPHA v0.0.14";
steem.config.set('websocket', 'wss://gtg.steem.house:8090');
// steem.config.set('websocket', 'wss://steemd.steemitdev.com');
// steem.config.set('websocket', 'wss://seed.bitcoiner.me');
//----- Start the tippy engine
console.log("╔══════════════════════════════════════════════════════════════════╗".blue);
console.log("╟".blue + "╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌".blue.bold + "╢".blue);
console.log("║ ".blue + version + " is now " + "ONLINE".green.bold + " - Listening to".white + " STEEM".blue.bold + " Network! ".white + "║".blue);
console.log("╟".blue + "╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌".blue.bold + "╢".blue);
console.log("╠══════════════════════════════════════════════════════════════════╣".blue);
// console.log("╟".blue + "╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌╼╌".bold.blue + "╢".blue);
//console.log("║".blue + " @Tippy Text to Tip STEEM & SBD Tip Bot Engine | A Node.js Script ".white + "║".blue);
//console.log("║".blue + " Developed by @KLYE ".white + "|".blue.bold + " Idea by @steemitqa".white + " |".blue.bold + " Free Code Open Sourced ".white + "║".blue);
console.log("╟".blue + "╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌".blue + "|".blue + "§".blue.bold + "|".blue + "╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌".blue + "╢".blue);
console.log("╠══════════════════════════════════════════════════════════════════╣".blue);
console.log("║".blue + "** ".blue.bold + "LOADING:".green.bold + " Config Settings & Blockdata... - Please Wait " + " **║".blue);
console.log("╠══════════════════════════════════════════════════════════════════╣".blue);
// engine config Variable Declarations - DO NOT FILL OUT
var firstrun;
var devmode;
var uptimeinfo;
var debugmode;
var tipfee;
var tippy;
var attippy;
var owner;
var wif;
var bank;
var memopubkey;
var profilepic;
var setup;
var devmsg;
var showlogo;
var logo;
var spacer;
var devmsg;
var tippyfooter = "<center><sub>🤖 @Tippy - <b>STEEM & SBD Text-to-Tip Service - </b> by @KLYE 🤖<br>( click reply & type @tippy help for commands )</sub></center>";
var autosaveblock;
var showtime;
var jsonMetadata = {
"app": "Tippy/0.0.14"
};
var protype;
var profee;
var offline;
var savedblock;
var newfile;
var stattype;
var to;
var sender;
var info;
var tipmemo;
var commentwait = false;
var totalblocks = 0;
var totalvote = 0;
var totalcomment = 0;
var count = 20;
var logo = "";
var time = "";
if (showtime == true){
var tnsecs = new Date().getUTCSeconds();
if (tnsecs == 0){
tnsecs = String("00");
}
if (tnsecs == 1){
tnsecs = String("0" + tnsecs);
}
if (tnsecs >= 10 && tnsecs.length < 2){
tnsecs = String(tnsecs + "0");
}
var tnmins = new Date().getUTCMinutes();
if (tnmins <= 10){
tnmins = String("0" + tnmins);
}
var tnhours = new Date().getUTCHours();
time = tnhours + ":" + tnmins + ":" + tnsecs + " │ ".blue;
};//END if (showtime == true)
// stats
var last_block = 0;
var current_block = 0;
var new_current_block = 0;
var synced = 0;
var headstreamblock;
var safestreamblock;
var parentAuthor;
var parentPermlink;
var permlink;
var reciever;
var steembalance;
var steembalanceafter
var sbdbalance;
var sbdbalanceafter;
var fee;
var blockdataread = false;
//----- Define some Queues to get around posting limits and 3 second rule
// set up our tipQueue function
function tipQueue() {
this.elements = [];
};
// enqueue a new thingy
tipQueue.prototype.enqueue = function (e) {
//console.log("tipQueue Enqueue");
this.elements.push(e);
};
// remove an element from the front of the queue
tipQueue.prototype.dequeue = function () {
return this.elements.shift();
};
// check if the queue is empty
tipQueue.prototype.isEmpty = function () {
return this.elements.length == 0;
};
// get the element at the front of the queue
tipQueue.prototype.peek = function () {
return !this.isEmpty() ? this.elements[0] : undefined;
};
var qt = new tipQueue();
// while tipQueue has items, call/fire them!
while (tipQueue.length) {
tipQueue.shift().call();
};
function voteQueue() {
this.elements = [];
};
// enqueue a new thingy
voteQueue.prototype.enqueue = function (e) {
if (debugmode == true){
//console.log("voteQueue enqueue");
}
this.elements.push(e);
};
// remove an element from the front of the queue
voteQueue.prototype.dequeue = function () {
return this.elements.shift();
};
// check if the queue is empty
voteQueue.prototype.isEmpty = function () {
return this.elements.length == 0;
};
// get the element at the front of the queue
voteQueue.prototype.peek = function () {
return !this.isEmpty() ? this.elements[0] : undefined;
};
var qv = new voteQueue();
// while tipQueue has items, call/fire them!
while (voteQueue.length) {
voteQueue.shift().call();
};
/*
setInterval(function(){
console.log("3 seconds");
}, 3000);
*/
function commentQueue() {
this.elements = [];
};
// enqueue a new thingy
commentQueue.prototype.enqueue = function (e) {
this.elements.push(e);
};
// remove an element from the front of the queue
commentQueue.prototype.dequeue = function () {
return this.elements.shift();
};
// check if the queue is empty
commentQueue.prototype.isEmpty = function () {
return this.elements.length == 0;
};
// get the element at the front of the queue
commentQueue.prototype.peek = function () {
return !this.isEmpty() ? this.elements[0] : undefined;
};
var qc = new commentQueue();
var cr;
var timetimetime = 1000;
function countdown() {
count = 19;
if (count >= 0){
var timerId = setInterval(function() {
console.log("║".blue + logo + " W ".blue.dim + "WAIT".grey.dim + " │ ".blue + count + "s on Post Limiter");
count--;
if(count <= 0) {
// your code goes here
clearInterval(timerId);
count = 0;
commentwait = false;
timetimetime = 1000;
}
}, timetimetime);
};
}
var counttime = parseFloat(count + "000");
// counttime = (count * 1000);
//----- Profile Updater / Stop Script function
function profileupdate(protype, profee, problock) {
if (debugmode == true) {
console.log("║".blue + logo + " ~ DBUG".magenta.dim + " │ ".blue + "function ".magenta.dim + "profileupdate".blue.bold + "(".white.dim + protype + "," + profee + "," + problock + ")".white.dim);
};
var profeepercent = parseFloat((1 - profee) * 100).toFixed(2);
if (protype == "offline") {
var tippyofflineprofile = {
'profile': {
'profile_image': profilepic,
'name': 'Tippy ©',
'about': 'STEEM Text to Tip Bot 🤖 is Under Development & OFFLINE! Hopefully Will Be Online Soon! 😘 Just the Tip..?',
'location': '❌OFFLINE (Coming Soon!)',
'website': 'https://steemit.com/@tippy'
}
};
steem.broadcast.accountUpdate(bank, tippy, undefined, undefined, undefined, memopubkey, tippyofflineprofile, function (err, result) {
if (err) {
console.log("ERROR: Failed to Update Profile")
if (debugmode == true) {
console.log("║".blue + logo + "~~~DBUG ".magenta.dim + " │ ".blue + err);
};
};// END if(err)
if (result) {
if (debugmode == true) {
console.log("║".blue + logo + " ~ DBUG ".magenta.dim + " │ ".blue + "Account Update Broadcast to Network Success!");
}; //END if (debugmode == true)
console.log("║".blue + logo + " > ".green.bold + "SEND".white.bold.underline + " │ ".blue + "Profile Updated to OFFLINE Mode");
console.log("║".blue + logo + " X".red.bold + " EXIT".red.bold.underline + " │ ".blue + "Shutting Down Now, Goodbye!");
process.exit();
} //END if(result)
}); // END steem.broadcast.accountUpdate
}; //END if(protype == "offline")
if (protype == "feeupdate") {
var savefee = {
firstrun: firstrun,
devmode: devmode,
debugmode: debugmode,
uptimeinfo: uptimeinfo,
version: version,
tipfee: profee,
tippy: tippy,
owner: owner,
wif: wif,
bank: bank,
memopubkey: memopubkey,
profilepic: profilepic,
showlogo: showlogo,
autosaveblock: autosaveblock,
jsonMetadata: jsonMetadata,
showtime: showtime,
setup: setup
};
fs.writeFile(__dirname + "/db/engine/config", JSON.stringify(savefee), function (err, win) {
if (err) {
console.log("ERROR: Unable to Write Block Data File!");
};
//console.log("║".blue + logo + " O".green.bold + " DISK".green.bold + " │".blue + " Saved New Tipping Fee " + profeepercent + "%");
});
profeepercent = parseFloat((1 - profee) * 100).toFixed(2);
var proupdate = {
'profile': {
'profile_image': profilepic,
'name': 'Tippy ©',
'about': 'STEEM Text to Tip Bot 🤖 Type "@' + tippy + ' help" for Commands 🤑 Low ' + profeepercent + '% Tipping Fee! 😘 Just the Tip..?',
'location': '✔️ONLINE (Alpha v0.0.14)',
'website': 'https://steemit.com/@tippy'
}
};
steem.broadcast.accountUpdate(bank, tippy, undefined, undefined, undefined, memopubkey, proupdate, function (err, result) {
if (err) {
console.log("ERROR: Failed to Update Profile")
if (debugmode == true) {
console.log("║".blue + logo + "~~~DBUG ".magenta.dim + " │ ".blue + err);
};
};
if (result) {
console.log("║".blue + logo + " > ".green.bold + "SEND".white.bold.underline + " │ ".blue + "Profile on ".white.dim + "@".green + tippy.green.bold + " Updated Fee to ".white.dim + profeepercent.white.bold + "%".white.bold);
if (debugmode == true) {
console.log("║".blue + logo + " ~ DBUG".magenta.dim + " │ ".blue + "method ".green.dim + "steem.broadcast.account Update was Success!");
}; //END debug
} //END if(result)
}); //END accountUpdate
}; //END feeupdate
if (protype == "blocksave") {
profeepercent = parseFloat((1 - profee) * 100).toFixed(2);
var proupdate = {
'profile': {
'profile_image': profilepic,
'name': 'Tippy ©',
'about': 'STEEM Text-to-Tip Service ❔ Type "@' + tippy + ' help" for Commands Low ' + profeepercent + '% Tipping Fee! 💲 Last Scanned Block: #' + problock + "",
'location': '✔️ONLINE (Alpha v0.0.14)',
'website': 'https://steemit.com/@tippy'
}
};
steem.broadcast.accountUpdate(bank, tippy, undefined, undefined, undefined, memopubkey, proupdate, function (err, result) {
if (err) {
console.log("ERROR: Failed to Update Profile")
if (debugmode == true) {
console.log("║".blue + logo + "~~~DBUG ".magenta.dim + " │ ".blue + err);
};
};
if (result) {
console.log("║".blue + logo + " > ".green.bold + "SEND".white.bold.underline + " │ ".blue + "Profile on ".white.dim + "@".green + tippy.green.bold + " Updated Last Saved Block to #".white.dim + problock);
if (debugmode == true) {
console.log("║".blue + logo + " ~ DBUG".magenta.dim + " │ ".blue + "method ".green.dim + "steem.broadcast.account Update was Success!");
}; //END debug
} //END if(result)
}); //END accountUpdate
}; //END if blocksave
}; //END function profileupdate();
//----- Reply to comment function
var replycomment = function (wif, parentAuthor, parentPermlink, tippy, permlink, title, content, metadata, block) {
if (debugmode == true) {
console.log("║".blue + logo + " ~ DBUG".magenta.dim + " │ ".blue + "function ".magenta.dim + "replycomment".blue.bold + "(".white.dim + wif + "," + parentAuthor + "," + parentPermlink + "," + tippy + "," + permlink + "," + title + "," + content + "," + metadata + "," + block + ")".white.dim);
};
if(commentwait == false){
steem.broadcast.comment(wif, parentAuthor, parentPermlink, tippy, permlink, title, content, metadata, function (commentfailz, commentwinz) {
if (commentfailz) {
if (debugmode == true) {
console.log(commentfailz);
};
console.log("║".blue + logo + " W ".yellow.dim + "WAIT".yellow + " │ ".blue + "Waiting on Comment Limiter to F**k Off!");
setTimeout(function() {
// Load first op without removing
steem.broadcast.comment(wif, parentAuthor, parentPermlink, tippy, permlink, title, content, metadata, function (errqc, winqc) {
if(errqc){
}
if(winqc){
console.log("║".blue + logo + " > ".green.bold + "SEND".green.bold + " │ ".blue + time + "@" + parentAuthor + "'s Response Sent on Block #" + headstreamblock);
countdown();
}
});
}, counttime)
}; //END if (commentfailz)
if (commentwinz) {
console.log("║".blue + logo + " > ".green.bold + "SEND".green.bold + " │ ".blue + time + "@" + parentAuthor + "'s Response Sent on Block #" + headstreamblock);
if (debugmode == true) {
console.log(commentwinz);
};
countdown();
}
});
} else {
console.log("║".blue + logo + " W ".yellow.dim + "WAIT".yellow + " │ ".blue + "Waiting on Comment Limiter to F**k Off!");
setTimeout(function() {
// Load first op without removing
console.log("║".blue + logo + " > ".yellow.dim + "SEND".yellow.dim + " │ ".blue + "@" + parentAuthor + "'s Queued Response is Broadcasting");
steem.broadcast.comment(wif, parentAuthor, parentPermlink, tippy, permlink, title, content, metadata, function (errqc, winqc) {
if(errqc){
}
if(winqc){
console.log("║".blue + logo + " > ".green.bold + "SEND".green.bold + " │ ".blue + "@" + parentAuthor + "'s Response Sent on Block #" + headstreamblock);
countdown();
};
});
}, counttime)
};
};//END replycomment
//----- Stat updater
var updatestat = function (stattype, statamount, newfile) {
if (debugmode == true) {
console.log("║".blue + logo + " ~ DBUG".magenta.dim + " │ ".blue + "function ".magenta.dim + "updatestat".blue.bold + "(".white.dim + stattype + "," + statamount + "," + newfile + ")".white.dim);
};
if (newfile == true) {
var newstattype
if (stattype == "balances") {
newstattype = {
balances: statamount
};
}; //END stattype == balances
if (stattype == "helps") {
newstattype = {
helps: statamount
};
}; //END stattype == helps
if (stattype == "infos") {
newstattype = {
infos: statamount
};
}; //END stattype == infos
if (stattype == "pings") {
newstattype = {
pings: statamount
};
}; //END stattype == pings
if (stattype == "tips") {
newstattype = {
tips: statamount
};
}; //END stattype == tips
if (stattype == "sbdtipped") {
newstattype = {
sbdtipped: statamount
};
}; //END stattype == sbdtipped
if (stattype == "steemtipped") {
newstattype = {
steemtipped: statamount
};
}; //END stattype == steemtipped
if (stattype == "steemdepo") {
newstattype = {
steemdepo: statamount
};
}; //END stattype == steemtipped
if (stattype == "sbddepo") {
newstattype = {
sbddepo: statamount
};
}; //END stattype == sbddepo
console.log("║".blue + logo + " + ".green.bold + "DATA".gray.dim + " │".blue + ' Creating New ' + stattype + ' File...');
fs.writeFile(__dirname + "/db/stats/" + stattype, JSON.stringify(newstattype), function (updatestaterr, updatestatwin) {
if (updatestaterr) return console.log('Save error', null);
if (stattype == "balances") {
steem.broadcast.comment(wif, parentAuthor, parentPermlink, "tippy", permlink, "@Tippy Account Error:", "<b>@tippy - Account: ERROR - </b>Steemit Tip Bot<hr>You didn't have a @tippy account or balance so one was created!<hr><sub>@Tippy - Steemit Text-to-Tip Service - Tip Without Ever Leaving The Page!<br>" + devmsg + "</sub>", version, function (err, result) {});
}
console.log("║".blue + logo + " + ".green.bold + "DATA".gray.dim + " │".blue + ' Completed New ' + stattype + ' File Creation!');
});
}; //END if newfile == true
if (newfile == null) {
if (debugmode == true) {
console.log("║".blue + logo + " ~ DBUG".magenta.dim + " │ ".blue + "newfile == undefined!".white.dim);
};
var statupdate;
fs.readFile(__dirname + "/db/stats/" + stattype, function (updatestatreaderror, updatestatread) {
if (updatestatreaderror) return console.log(stattype + ' File Not Found', null);
if (updatestatread) {
if (debugmode == true) {
console.log("║".blue + logo + " ~ DBUG".magenta.dim + " │ ".blue + "Success on Stats File Read of ".white.dim + stattype);
};
var statdata = JSON.parse(updatestatread);
if (stattype == "balances") {
statupdate = statdata.balances;
}; //END stattype == balances
if (stattype == "helps") {
statupdate = statdata.helps;
}; //END stattype == helps
if (stattype == "infos") {
statupdate = statdata.infos;
}; //END stattype == infos
if (stattype == "pings") {
statupdate = statdata.pings;
};
if (stattype == "tips") {
statupdate = statdata.tips;
};
if (stattype == "sbdtipped") {
statupdate = statdata.sbdtipped;
};
if (stattype == "steemtipped") {
statupdate = statdata.steemtipped;
};
if (stattype == "steemdepo") {
statupdate = statdata.steemdepo;
};
if (stattype == "sbddepo") {
statupdate = statdata.sbddepo;
};
var newstatupdate = statupdate + statamount;
var writestat;
if (stattype == "balances") {
writestat = {
balances: newstatupdate
};
}; //END stattype == balances
if (stattype == "helps") {
writestat = {
helps: newstatupdate
};
}; //END stattype == helps
if (stattype == "infos") {
writestat = {
infos: newstatupdate
};
}; //END stattype == infos
if (stattype == "pings") {
writestat = {
pings: newstatupdate
};
}; //END stattype == pings
if (stattype == "tips") {
writestat = {
tips: newstatupdate
};
}; //END stattype == pings
if (stattype == "sbdtipped") {
writestat = {
sbdtipped: newstatupdate
};
}; //END stattype == sbdtipped
if (stattype == "steemtipped") {
writestat = {
steemtipped: newstatupdate
};
}; //END stattype == steemtipped
if (stattype == "steemdepo") {
writestat = {
steemdepo: newstatupdate
};
}; //END stattype == steemdepo
if (stattype == "sbddepo") {
writestat = {
sbddepo: newstatupdate
};
}; //END stattype == sbddepo
fs.writeFile(__dirname + "/db/stats/" + stattype, JSON.stringify(writestat), function (writestaterr, writestatdata) {
if (writestaterr) return console.log('Save error', null);
console.log("║".blue + logo + " + ".green.bold + "STAT".cyan.bold.underline + " │".blue + " Stat Increased: " + stattype + " +" + statamount);
});
};
});
} //END newfile == true
}; //END function updatestat
//----- Tips/Transfer function
var transfertip = function (bankwif, tippy, to, from, amount, currency, message, block, newbalval) {
fs.readFile(__dirname + "/db/balances/" + from, function (err, details) {
if (err) {
console.log("Oh shit error!");
}
if (details) {
var info = JSON.parse(details);
// Read & Store Current STEEM/SBD Balances
steembalance = info.steem;
sbdbalance = info.sbd;
if (from != tippy) {
console.log("║".blue + " $ ".green.bold + "BANK".green.bold + " │ ".blue + "User @" + from + "'s STEEM Balance: " + steembalance);
console.log("║".blue + " $ ".green.bold + "BANK".green.bold + " │ ".blue + "User @" + from + "'s SBD Balance: " + sbdbalance);
};
};
});
steem.broadcast.transfer(bankwif, tippy, to, amount, message, function (fuckeduptransfer, senttransfer) {
if (fuckeduptransfer) {
console.log("transfer fucked up: " + fuckeduptransfer);
};
if (senttransfer) {
// Save out blockheight!
if (from != tippy) {
saveblockdataheight(block);
if (currency == "STEEM") {
// Prepare the Users STEEM Balance to be Saved After Adjusting Above
info = {
user: from,
steem: newbalval,
sbd: sbdbalance
};
amount = parseFloat(amount);
stattype = "steemtipped";
updatestat(stattype, amount, null);
};
if (currency == "SBD") {
// Prepare the Users SBD Balance to be Saved After Adjusting Above
info = {
user: from,
steem: steembalance,
sbd: newbalval
};
amount = parseFloat(amount);
stattype = "sbdtipped";
updatestat(stattype, amount, null);
};
// Write Sending Users New Balance to Balances File
fs.writeFile(__dirname + "/db/balances/" + from, JSON.stringify(info), function (err, d) {
// If User Balance Save to File Fails
if (err) {
console.log("║".blue + logo + " ! ".red.bold.underline + "WARN".red.bold.underline + " │".blue + 'Save error');
};
stattype = "tips";
updatestat(stattype, 1, null);
console.log("║".blue + logo + " O".green.bold + " DISK".green.bold + " │".blue + " @" + from + " Balance Updated");
}); // End writefile / balance save
};
}; //END senttransfer
}); //END steem.broadcast.transfer
}; //END transfertip function
//----- Confirmation via upvotes
var confirmvote = function (parentAuthor, permlink, weight, type) {
if (debugmode == true) {
console.log("║".blue + logo + " ~ DBUG".magenta.dim + " │ ".blue + "function ".magenta.dim + "confirmvote".blue.bold + "(".white.dim + parentAuthor + "," + permlink + "," + weight + "," + type + ")".white.dim);
};
steem.broadcast.vote(
wif,
tippy,
parentAuthor,
permlink,
weight,
function (err, result) {
if (debugmode == true) {
if (err) {
console.log("║".blue + logo + "~~~DBUG ".magenta.dim + " │ ".blue + " " + type + " Confirmation Vote FAILED");
console.log(err);
};
if (result) {
console.log("║".blue + logo + "~~~DBUG ".magenta.dim + " │ ".blue + " " + type + " Confirmation Vote Success!");
console.log(result);
};
} else {
if (err) {
console.log("║ ".blue + logo + "!".red + " WARN".red.bold + " " + type + " Confirmation Upvote FAILED");
};
if (result) {
console.log("║ ".blue + logo + "^".white.bold.bgBlue + " VOTE".blue.bold + " │ ".blue + type + " Confirmation Vote SUCCESS!");
};
};
});
};
//----- Grab Blockchain Data
function blockdatainit() {
steem.api.getDynamicGlobalProperties(function (err, props) {
if (err) {console.log("ERROR: Something went wrong in blockdatainit()");}
if (props) {
current_block = props["last_irreversible_block_num"];
}
});
if (debugmode == true) {
console.log("║".blue + logo + "~~ DEBUG: ".magenta.dim + "function ".magenta.dim + "blockdatainit".blue.bold + "(".white.dim + ")".white.dim + " **║".blue);
};
fs.exists(__dirname + "/db/stats/blockdata", function (exists) {
// if not exist then create new config file
if (!exists) {
var newblockdata = {
last_block: 0
};
console.log("Notice".white.bold.underline.bgYellow + "No Block Data File Found! Creating Now!");
fs.writeFile(__dirname + "/db/stats/blockdata", JSON.stringify(newblockdata), function (err, win) {
if (err) {
console.log("ERROR: Unable to Save Block Data to Disk!");
};
if (win) {
console.log("SUCCESS:".green.bold.underline.dim + " Created New Blockdata File!");
};
}); // END /db/engine/config writeFile
} else {
console.log("║** ".blue + "SYSTEM:".gray.dim + " Found Block Data..! Loading Last Scanned Block" + " **║".blue);
fs.readFile(__dirname + "/db/stats/blockdata", function (err, data) {
if (err) {
console.log("ERROR: Unable to Read Block Data File!");
};
if (data) {
var bd = JSON.parse(data);
last_block = bd.last_block;
console.log("║** ".blue + "SUCCESS:".green.bold.underline.dim + " Found Block Data - Last Block: #" + last_block + " **║".blue);
console.log("╠══════════════════════════════════════════════════════════════════╣".blue);
console.log("║".blue + "** ".blue.bold + "LOADING:".green.bold + " Current STEEM Block Height For Sync... Please Wait " + " **║".blue);
if (logo == true) {
console.log("╠══════════════════════════════════════════════════════════════════╣".blue);
};
if (logo == false) {
console.log("╠══════════════════════════════════════════════════════════════════╣".blue);
};
};
});
}; //END else statment
}); //END !exists db/engine
steem.api.getDynamicGlobalProperties(function (err, props) {
if (err) { console.log("Error fetching current block Height... Please restart!");}
if (props) {
current_block = props["last_irreversible_block_num"];
console.log("║** ".blue + "NOTICE: ".yellow.bold.underline + "Bot Account ".white + "(".white + "@".green.dim + tippy.green.bold + ") Needs Sync to Block #".white + current_block + " **║".blue);
if (logo == true) {
console.log("╠══════════════╤═══════════════════════════════════════════════════╝".blue);
};
if (logo == false) {
console.log("╠════════╤═════════════════════════════════════════════════════════╝".blue);
};
}
});
steem.api.getDynamicGlobalProperties(function (err, props) {
if (props) {
current_block = props["last_irreversible_block_num"];
//check to see if we need to catch up to current block height
if (current_block > last_block) {
prompt.start();
prompt.message = "";
prompt.get([{
name: 'asksyncinput',
description: '║** '.blue.dim + 'SYNC'.red.bold + ' │ '.blue + ' Blocks Missed While Offline?'.white + ' (true / false)',
default: false
}], function (err, result) {
if (err) {
console.log("ERROR: Sync Input Failed! Please Restart")
};
if (result) {
var syncinput = result.asksyncinput;
if ( syncinput.toString() == "true" ) {
synced = 0;
current();
} else {
protype = "feeupdate";
profileupdate(protype, tipfee);
synced = 1;
startsplash();
};//END syncinput == true
}; //END if (result)
}); // END Setup Prompt
};
}
if (err) {
console.log("ERROR: Failed to Get Current Block!");
}
});
}; //END function blockdatainit();
//----- Create some motherfucking folders if they ain't existin'
function createdb() {
// Debug Stuff
if (debugmode == true) {
console.log("║".blue + logo + "~~ DEBUG: ".magenta.dim + "function ".magenta.dim + "createdb".blue.bold + "( ".white.dim + ")".white.dim);
};
if (!fs.existsSync(__dirname + "/db")) {
fs.mkdirSync(__dirname + "/db");
console.log("NOTICE:".yellow.bold.underline + "No Database Directory Found.. Creating /db Folder");
};
if (!fs.existsSync(__dirname + "/db/balances")) {
console.log("NOTICE:".yellow.bold.underline + "No Balance Directory Found.. Creating /db/balances Folder");
fs.mkdirSync(__dirname + "/db/balances");
};
if (!fs.existsSync(__dirname + "/db/stats")) {
console.log("NOTICE:".yellow.bold.underline + "No Stats Directory Found.. Creating /db/stats Folder");
fs.mkdirSync(__dirname + "/db/stats");
};
if (!fs.existsSync(__dirname + "/db/engine")) {
console.log("NOTICE:".yellow.bold.underline + "No Engine Directory Found.. Creating /db/engine Folder");
fs.mkdirSync(__dirname + "/db/engine");
};
}; // END function createdb();
//----- first run & setup functionality
function firsttime() {
if (debugmode == true) {
console.log("║".blue + logo + "~~ DEBUG: ".magenta.dim + "function ".magenta.dim + "firsttime".blue.bold + "( ".white.dim + ")".white.dim);
};
console.log("Notice".white.bold.underline.bgYellow + ": First Run Detected! Please Configure Tip Bot Engine to Continue!".white);
prompt.start();
prompt.message = "";
prompt.get([{
name: 'tippyinput',
description: 'Bot Account Name? (No @)',
required: true
}, {
name: 'bankinput',
description: "Bot Account Active Private Key?",
required: true,
replace: '*',
hidden: true
}, {
name: 'wifinput',
description: "Bot Account Posting Private Key?",
required: true,
replace: '*',
hidden: true
}, {
name: 'memopubkeyinput',
description: "Bot Account Memo Public Key?",
required: true
}, {
name: 'tipfeeinput',
description: "Fee to Charge on Tips? (As a Percentage - 1.00%)",
required: true
}, {
name: 'profilepicinput',
description: 'Enter URL to Profile Picture: (http://site.com/picture.png)',
required: true
}, {
name: 'devmodeinput',
description: 'Enable Developer Mode / Show Warning Footer ( true or false )',
required: true,
validator: /t[rue]*|f[alse]?/,
warning: 'Must respond true or false!',
default: 'false'
}, {
name: 'debugmodeinput',
description: 'Enable Debug Output in Console? ( true or false )',
required: true,
validator: /t[rue]*|f[alse]?/,
warning: 'Must respond true or false!',
default: 'false'
}, {
name: 'uptimeinfoinput',
description: 'Show Uptime Info in Console? ( true or false )',
required: true,
validator: /t[rue]*|f[alse]?/,
warning: 'Must respond true or false!',
default: 'false'
}, {
name: 'showlogoinput',
description: 'Show Logo in Console? ( true or false )',
required: true,
validator: /t[rue]*|f[alse]?/,
warning: 'Must respond true or false!',
default: 'false'
}, {
name: 'autosaveblockinput',
description: 'Number of Blocks Between Autosaves?',
required: true,
default: 10
}, {
name: 'showtimeinput',
description: 'Show Time on Console Output? ( true or false )',
validator: /t[rue]*|f[alse]?/,
warning: 'Must respond true or false!',
default: 'false'
}, {
name: 'ownerinput',
description: "Owner Account Name? (No @) ",
required: true
}], function (err, result) {
if (err) {
console.log("ERROR: Something Went Wrong During Config.. Please Restart Service! (ctrl + c to exit)")
};
if (result) {
var newconfig = {
firstrun: false,
devmode: result.devmodeinput,
debugmode: result.debugmodeinput,
uptimeinfo: result.uptimeinfoinput,
version: version,
tipfee: result.tipfeeinput,
tippy: result.tippyinput,
owner: result.ownerinput,
wif: result.wifinput,
bank: result.bankinput,
memopubkey: result.memopubkeyinput,
profilepic: result.profilepicinput,
showlogo: result.showlogoinput,
autosaveblock: result.autosaveblockinput,
showtime: result.showtimeinput,
jsonMetadata: jsonMetadata,
setup: false
};
console.log("SYSTEM:".bold.purple + " You Completed The Configuration - Saving");
fs.writeFile(__dirname + "/db/engine/config", JSON.stringify(newconfig), function (err, win) {
if (err) {
console.log("ERROR: Unable to Save Config to Disk!");
};
if (win) {
console.log("SUCCESS:".green.bold.underline.dim + " New Configuration Input Saved");
};
}); // END /db/engine/config writeFile
blockdatainit();
}; //END if (result)
}); // END Setup Prompt
}; //END function firstrun();
//----- Configuration file exists? load it.
function configexists() {
if (debugmode == true) {
console.log("║".blue + logo + "~~ DEBUG: ".magenta.dim + "function ".magenta.dim + "configexists".blue.bold + "( ".white.dim + ")".white.dim);
};
fs.readFile(__dirname + "/db/engine/config", function (configexistserror, configexistsdata) {
if (configexistserror) {
console.log("ERROR: Unable to Read Config File!")
};
if (configexistsdata) {
console.log("║** ".blue + "SUCCESS:".green.bold.underline.dim + " Fetched & Parsed Config File Data!" + " **║".blue)
var configdata = JSON.parse(configexistsdata);
debugmode = configdata.debugmode;
if (debugmode == true) {
console.log("║".blue + logo + "~~~DBUG ".magenta.dim + " configdata: ".bold + configdata);
}
firstrun = false;
devmode = configdata.devmode;
debugmode = configdata.debugmode;
uptimeinfo = configdata.uptimeinfo;
version = version;
tipfee = configdata.tipfee;
tippy = configdata.tippy;
owner = configdata.owner;
wif = configdata.wif;
bank = configdata.bank;
memopubkey = configdata.memopubkey;
profilepic = configdata.profilepic;
showlogo = configdata.showlogo;
autosaveblock = configdata.autosaveblock;
showtime = configdata.showtime;
jsonMetadata = configdata.jsonMetadata;
setup = false;
// Set the logo on or off here
if (showlogo == true) {
logo = (" -".blue.dim + "|".blue + "§".blue.bold + "|".blue + "-".blue.dim);
spacer = "";
};
if (showlogo == false) {
logo = "";
spacer = " ";
};
// Set the logo on or off here
if (showtime == true) {
var tnhours = new Date().getUTCHours();
var tnmins = new Date().getUTCMinutes();
var tnsecs = new Date().getUTCSeconds();
if (tnsecs == 0){
tnsecs = String("00");
}
if (tnsecs == 1){
tnsecs = String("0" + tnsecs);
}
if (tnsecs < 10 && tnsecs > 1){
tnsecs = String(tnsecs + "0");
}
if (tnsecs == 10){
tnsecs = 10;
}
var tnmins = new Date().getUTCMinutes();
if (tnmins <= 10){
tnmins = String("0" + tnmins);
}
if (tnmins == 10){
tnmins = 10;
}
var tnhours = new Date().getUTCHours();
time = tnhours + ":" + tnmins + ":" + tnsecs + " │ ".blue;