forked from jcostello93/node-red-contrib-node-reddit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode-reddit.html
1387 lines (1284 loc) · 56.6 KB
/
node-reddit.html
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
<!-- START Config Node -->
<script type="text/x-red" data-template-name="reddit-credentials">
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> <span> name</span></label>
<input type="text" id="node-config-input-name">
</div>
<hr>
<div class="form-row">
<label for="node-config-input-client_id"><i class="fa fa-tag"></i> <span> client ID</span></label>
<input type="text" id="node-config-input-client_id">
</div>
<div class="form-row">
<label for="node-config-input-client_secret"><i class="fa fa-key"></i> <span> client secret</span></label>
<input type="text" id="node-config-input-client_secret">
</div>
<div class="form-row">
<label for="node-config-input-user_agent"><i class="fa fa-tag"></i> <span> user agent</span></label>
<input type="text" id="node-config-input-user_agent">
</div>
<div class="form-row" id="node-action-auth_type">
<label for="node-config-input-auth_type"><i class="fa fa-wrench"></i> authentication</label>
<select type="text" id="node-config-input-auth_type" style="display: inline-block; width: 250px; vertical-align: top;">
<option value="username_password" outputs="1">username/password</option>
<option value="refresh_token" outputs="1">refresh token</option>
<option value="access_token" outputs="1">access token</option>
</select>
</div>
<div class="form-row" id="node-action-username">
<label for="node-config-input-username"><i class="fa fa-tag"></i> <span> username</span></label>
<input type="text" id="node-config-input-username">
</div>
<div class="form-row" id="node-action-password">
<label for="node-config-input-password"><i class="fa fa-key"></i> <span> password</span></label>
<input type="password" id="node-config-input-password">
</div>
<div class="form-row" id="node-action-refresh_token">
<label for="node-config-input-refresh_token"><i class="fa fa-key"></i> <span> refresh Token</span></label>
<input type="text" id="node-config-input-refresh_token">
</div>
<div class="form-row" id="node-action-access_token">
<label for="node-config-input-access_token"><i class="fa fa-key"></i> <span> access Token</span></label>
<input type="text" id="node-config-input-access_token">
</div>
</script>
<script type="text/javascript">
function oneditprepare() {
function hideExtraActions(){
$("#node-action-username").hide();
$("#node-action-password").hide();
$("#node-action-refresh_token").hide();
$("#node-action-access_token").hide();
}
function showActions(){
var auth_type = $("#node-config-input-auth_type option:selected").val();
if (auth_type == "username_password") {
$("#node-action-username").show();
$("#node-action-password").show();
}
else if (auth_type == "refresh_token"){
$("#node-action-refresh_token").show();
}
else if (auth_type == "access_token"){
$("#node-action-access_token").show();
}
}
$("#node-config-input-auth_type").change(function() {
hideExtraActions()
showActions()
});
hideExtraActions()
showActions()
}
RED.nodes.registerType('reddit-credentials',{
defaults: {
username: {value:"", required: false},
user_agent: {value:"", required: true},
auth_type: {value:"username_password", required: false},
name: {value:"", required: false}
},
category: 'config',
credentials: {
password: {type: "password", required: false},
client_id: {type: "password", required: true},
client_secret: {type: "password", required: true},
refresh_token: {type:"password", required: false},
access_token: {type:"password", required: false}
},
label: function() {
return this.name || this.username;
},
exportable: false,
icon: "snoo2.png",
color:"#ffa27f",
oneditprepare: oneditprepare
});
</script>
<script type="text/x-red" data-help-name="reddit-credentials">
<p>Authentication for the Reddit API</p>
<p>To create a Reddit app and obtain its Client ID and Client Secret, log in to your Reddit account and visit <a href="https://ssl.reddit.com/prefs/apps/">this link.</a></p>
<p>There are 3 ways to provide authentication:</p>
<ol>
<li><i>Username/password</i>: For long-term access. Possible for script-type apps only.</li>
<li><i>Refresh token</i>: For long-term access. Visit <a href="https://not-an-aardvark.github.io/reddit-oauth-helper/">here</a> to generate a token.</li>
<li><i>Access token</i>: For short-term access. Expires in one hour. Visit <a href="https://not-an-aardvark.github.io/reddit-oauth-helper/">here</a> to generate a token.</li>
</ol>
<h3>References</h3>
<ul>
<li><a href="https://github.com/reddit-archive/reddit/wiki/oauth2">Reddit OAuth2 docs</a> - full description of authtication methods</li>
<li><a href="https://not-an-aardvark.github.io/snoowrap/snoowrap.html">Snoowrap docs</a> - guidelines for creating Snoowrap objects</li>
</ul>
</script>
<!-- END Config Node -->
<!-- START Stream -->
<script type="text/javascript">
RED.nodes.registerType('stream', {
category: 'reddit',
color: '#a6bbcf',
defaults: {
name: {value: ""},
reddit: {type: "reddit-credentials", required: true},
kind: {value: "", required: true},
subreddit: {value: ""},
filter: {value: "inbox"},
markedAsRead: {},
timeout: {value: ""},
pollTime: {value: ""}
},
inputs: 0,
outputs: 1,
icon: "snoo2.png",
color:"#ffa27f",
label: function() {
let creds = RED.nodes.node(this.reddit);
if (this.name) {
return this.name;
} else if (this.kind === "PMs") {
return creds ? "u/" + creds.username : "PM stream";
} else if (this.subreddit) {
return "r/" + this.subreddit;
} else {
return "stream";
}
},
oneditprepare: () => {
$("#node-input-markedAsRead").prop("disabled", true);
$("#node-input-kind").change(() => {
$("#node-action-subreddit").hide();
$("#node-action-filter").hide();
$("#node-action-markedAsRead").hide();
let type = $("#node-input-kind option:selected").val();
if (type === "submissions" || type === "comments") {
$("#node-action-subreddit").show();
} else if (type === "PMs") {
$("#node-action-filter").show();
$("#node-action-markedAsRead").show();
}
});
$("#node-input-filter").change(() => {
$("#node-input-markedAsRead").prop("disabled", true);
if ($("#node-input-filter").val() === "unread") {
$("#node-input-markedAsRead").prop("disabled", false);
}
});
}
});
</script>
<script type="text/x-red" data-template-name="stream">
<div class="form-row">
<label for="node-input-reddit"><i class="fa fa-reddit"></i> credentials</label>
<input type="text" id="node-input-reddit">
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> name</label>
<input type="text" id="node-input-name" placeholder="optional name for this node">
</div>
<hr>
<div class="form-row">
<label for="node-input-kind"><i class="fa fa-wrench"></i> stream</label>
<select type="text" id="node-input-kind" style="display: inline-block; width: 250px; vertical-align: top;">
<option value="submissions" outputs="1">submissions</option>
<option value="comments" outputs="1">comments</option>
<option value="PMs" outputs="1">private messages</option>
</select>
</div>
<div class="form-row" id="node-action-subreddit">
<label for="node-input-subreddit"><i class="icon-tag"></i> subreddit</label>
<input type="text" id="node-input-subreddit" placeholder="subreddit name">
</div>
<div class="form-row" id="node-action-filter">
<label for="node-input-filter"><i class="fa fa-wrench"></i> filter</label>
<select type="text" id="node-input-filter" style="display: inline-block; width: 250px; vertical-align: top;">
<option value="inbox" outputs="1">inbox</option>
<option value="unread" outputs="1">unread</option>
<option value="messages" outputs="1">messages</option>
<option value="comments" outputs="1">comments</option>
<option value="selfreply" outputs="1">selfreply</option>
<option value="mentions" outputs="1">mentions</option>
</select>
</div>
<div class="form-row" id="node-action-markedAsRead">
<label for="node-input-markedAsRead" style="width:auto"><i class="icon-tag"></i> mark as read</label>
<input type="checkbox" id="node-input-markedAsRead" style="width:23px">
</div>
<div class="form-row">
<label for="node-input-pollTime"><i class="icon-tag"></i> polltime (s)</label>
<input type="number" id="node-input-pollTime" min="2" max="3600" step="any" placeholder="optional refresh rate">
</div>
<div class="form-row">
<label for="node-input-timeout"><i class="icon-tag"></i> timeout (s)</label>
<input type="number" id="node-input-timeout" min="1" placeholder="optional timeout in seconds">
</div>
</script>
<script type="text/x-red" data-help-name="stream">
<p>Stream submissions and comments from a subreddit or PMs from your inbox.</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>stream <span class="property-type">selection</span></dt>
<dd> choose comments, submissions, or PMs.</dd>
<dt>subreddit <span class="property-type">string</span></dt>
<dd> the subreddit to stream (unused for PMs).</dd>
<dt>filter <span class="property-type">selection</span></dt>
<dd> choose which type of messages to stream from Inbox</dd>
<dt class="optional">mark as read <span class="property-type">checkbox</span></dt>
<dt class="optional">polltime <span class="property-type">number</span></dt>
<dd> the refresh rate in seconds.</dd>
<dt class="optional">timeout <span class="property-type">number</span></dt>
<dd> the length of time to stream in seconds.</dd>
</dl>
<h3>Outputs</h3>
<ol class="node-ports">
<li>Standard output
<dl class="message-properties">
<dt>payload <span class="property-type">object</span></dt>
<dd> details of the comment, submission, or PM.</dd>
</dl>
</li>
<li>Standard error
<dl class="message-properties">
<dt>payload <span class="property-type">string</span></dt>
<dd>the standard error of the command.</dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<p>Exclude the "r/" when entering your <code>subreddit</code>. "r/<code>subreddit</code>" will be
used for the display name if <code>name</code> is left empty.
</p>
<p>"u/<code>credentials.username</code>" will be used for the display name if <code>name</code> is left empty.
</p>
<p>The <code>polltime</code> is the number of seconds (between 2 and 3600) that the stream polls for updates.
Reddit enforces a ratelimit of 30 polls per minute. If your stream continues to hit the ratelimit, consider
increasing the <code>polltime</code>.
</p>
<p>The <code>timeout</code> will stop the stream after the desired number of seconds.
If left blank, the stream will continue until the node is deleted from the flow, an error is thrown,
or node-RED is shutdown.
</p>
<h3>References</h3>
<ul>
<li><a href='https://www.reddit.com/dev/api/'>Reddit API docs</a> - descriptions of comment and submission listings</li>
<li><a href='https://github.com/jcostello93/node-red-contrib-node-reddit'>node-red-contrib-node-reddit</a> - the Node-Reddit github repository</li>
</ul>
</script>
<!-- END Stream -->
<!-- START Get -->
<script type="text/javascript">
function oneditprepare() {
function resetFetchAll() {
var type = $("#node-input-content_type option:selected").val();
var current_source_identifier = "#node-input-" + type + "_source option:selected";
var current_source = $(current_source_identifier).val();
// A user can get all submissions/replies from a user and all contents of their inbox
if (current_source == "user" || current_source == "inbox") {
return
}
// A user can expand all replies for a submission
if (type == "comment" && $("#node-input-comment_source option:selected").val() == "submission") {
return
}
// In every other case, fetch_all is set to false
$("#node-input-fetch_all").val("false");
}
function hideExtraActions(){
$("#node-action-submission_source").hide();
$("#node-action-comment_source").hide();
$("#node-action-pm_source").hide();
$("#node-action-content_source").hide();
$("#node-action-subreddit").hide();
$("#node-action-user").hide();
$("#node-action-sort").hide();
$("#node-action-time").hide();
$("#node-action-limit").hide();
$("#node-action-fetch_all").hide();
$("#node-action-content_id").hide();
$("#node-action-depth").hide();
}
function showActions() {
// 1. type
// 2. source
// 3. subreddit
// 4. user
// 5. sort
// 6. time
// 7. fetch all
// 8. limit
var type = $("#node-input-content_type option:selected").val();
var submission_source = $("#node-input-submission_source option:selected").val();
var comment_source = $("#node-input-comment_source option:selected").val();
var pm_source = $("#node-input-pm_source option:selected").val();
var current_source_identifier = "#node-input-" + type + "_source option:selected";
var current_source = $(current_source_identifier).val();
var sort = $("#node-input-sort option:selected").val();
if (type == "submission") {
if (current_source == "subreddit") {
$("#node-action-subreddit").show();
if (sort == "top" || sort == "controversial") {
$("#node-action-time").show();
}
$("#node-action-sort").show();
}
else if (current_source == "user") {
$("#node-action-user").show();
$("#node-action-sort").show();
$("#node-action-fetch_all").show();
}
else if (current_source == "id") {
$("#node-action-content_id").show();
}
$("#node-action-submission_source").show()
}
else if (type == "comment") {
if (current_source == "subreddit") {
$("#node-action-subreddit").show();
}
else if (current_source == "user") {
$("#node-action-user").show();
$("#node-action-fetch_all").show();
}
else if (current_source == "submission") {
$("#node-action-content_id").show();
$("#node-action-fetch_all").show();
if ($("#node-input-fetch_all").val() != "true") {
$("#node-action-depth").show();
}
}
else if (current_source == "id") {
$("#node-action-content_id").show();
}
$("#node-action-comment_source").show()
}
else if (type == "pm") {
if (current_source == "inbox") {
$("#node-action-fetch_all").show();
}
else if (current_source == "id") {
$("#node-action-content_id").show();
}
$("#node-action-pm_source").show()
} else if (type == "content") {
$("#node-action-content_source").show();
}
if ($("#node-input-fetch_all").val() != "true" && current_source != "id") {
$("#node-action-limit").show();
}
}
$("#node-input-reddit").change(function() {
resetFetchAll()
hideExtraActions()
showActions()
});
$("#node-input-content_type").change(function() {
resetFetchAll()
hideExtraActions()
showActions()
});
$("#node-input-submission_source").change(function() {
resetFetchAll()
hideExtraActions()
showActions()
});
$("#node-input-comment_source").change(function() {
resetFetchAll()
hideExtraActions()
showActions()
});
$("#node-input-pm_source").change(function() {
resetFetchAll()
hideExtraActions()
showActions()
});
$("#node-input-user").keyup(function() {
resetFetchAll()
hideExtraActions()
showActions()
});
$("#node-input-fetch_all").change(function() {
hideExtraActions()
showActions()
});
$("#node-input-sort").change(function() {
hideExtraActions()
showActions()
});
}
RED.nodes.registerType('get',{
category: 'reddit',
color: '#a6bbcf',
defaults: {
name: {value:""},
reddit: { type:"reddit-credentials",required:true},
content_type: {value:"submission"},
submission_source: {value:"subreddit"},
comment_source: {value:"subreddit"},
pm_source: {value:"inbox"},
content_source: {value:"saved"},
subreddit: {value:""},
user: {value:""},
limit: {value:""},
sort: {value:"hot"},
time: {value:"hour"},
fetch_all: {value:"false"},
submission: {value: ""},
depth: {value: ""},
content_id: {value: ""}
},
inputs:1,
outputs:1,
icon: "snoo2.png",
color:"#ffa27f",
label: function() {
var type = (this.content_type == "pm") ? "PM" : this.content_type;
var submission_source = this.submission_source;
var comment_source = this.comment_source;
var pm_source = this.pm_source;
var label;
if ((type == "submission" && submission_source == "id") || (type == "comment" && comment_source == "id") || (type == "PM" && pm_source == "id") || (type == "content")) {
label = "get " + type;
}
else {
label = "get " + type + "s";
}
return this.name || label;
},
oneditprepare: oneditprepare
});
</script>
<script type="text/x-red" data-template-name="get">
<div class="form-row">
<label for="node-input-reddit"><i class="fa fa-reddit"></i> <span> credentials</span></label>
<input type="text" id="node-input-reddit">
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> name</label>
<input type="text" id="node-input-name" placeholder="name">
</div>
<hr>
<div class="form-row">
<label for="node-input-content_type"><i class="fa fa-wrench"></i> type</label>
<select type="text" id="node-input-content_type" style="display: inline-block; width: 250px; vertical-align: top;">
<option value="submission" outputs="1">submission</option>
<option value="comment" outputs="1">comment</option>
<option value="pm" outputs="1">PM</option>
<option value="content" outputs="1">content</option>
</select>
</div>
<div class="form-row" id="node-action-submission_source">
<label for="node-input-submission_source"><i class="fa fa-wrench"></i> source</label>
<select type="text" id="node-input-submission_source" style="display: inline-block; width: 250px; vertical-align: top;">
<option value="subreddit" outputs="1">subreddit</option>
<option value="user" outputs="1">user</option>
<option value="id" outputs="1">id</option>
</select>
</div>
<div class="form-row" id="node-action-comment_source">
<label for="node-input-comment_source"><i class="fa fa-wrench"></i> source</label>
<select type="text" id="node-input-comment_source" style="display: inline-block; width: 250px; vertical-align: top;">
<option value="subreddit" outputs="1">subreddit</option>
<option value="user" outputs="1">user</option>
<option value="submission" outputs="1">submission</option>
<option value="id" outputs="1">id</option>
</select>
</div>
<div class="form-row" id="node-action-pm_source">
<label for="node-input-pm_source"><i class="fa fa-wrench"></i> source</label>
<select type="text" id="node-input-pm_source" style="display: inline-block; width: 250px; vertical-align: top;">
<option value="inbox" outputs="1">inbox</option>
<option value="id" outputs="1">id</option>
</select>
</div>
<div class="form-row" id="node-action-content_source">
<label for="node-input-content_source"><i class="fa fa-wrench"></i> source</label>
<select type="text" id="node-input-content_source" style="display: inline-block; width: 250px; vertical-align: top;">
<option value="saved" outputs="1">saved</option>
<option value="upvoted" outputs="1">upvoted</option>
<option value="downvoted" outputs="1">downvoted</option>
<option value="gilded" outputs="1">gilded</option>
<option value="hidden" outputs="1">hidden</option>
</select>
</div>
<div class="form-row" id="node-action-subreddit">
<label for="node-input-subreddit"><i class="icon-tag"></i> subreddit</label>
<input type="text" id="node-input-subreddit" placeholder="subreddit">
</div>
<div class="form-row" id="node-action-user">
<label for="node-input-user"><i class="icon-tag"></i> user</label>
<input type="text" id="node-input-user" placeholder="user">
</div>
<div class="form-row" id="node-action-content_id">
<label for="node-input-content_id"><i class="icon-tag"></i> content_id</label>
<input type="text" id="node-input-content_id" placeholder="content_id">
</div>
<div class="form-row" id="node-action-sort">
<label for="node-input-sort"><i class="fa fa-wrench"></i> sort</label>
<select type="text" id="node-input-sort" style="display: inline-block; width: 250px; vertical-align: top;">
<option value="hot" outputs="1">hot</option>
<option value="new" outputs="1">new</option>
<option value="rising" outputs="1">rising</option>
<option value="controversial" outputs="1">controversial</option>
<option value="top" outputs="1">top</option>
</select>
</div>
<div class="form-row" id="node-action-time">
<label for="node-input-time"><i class="fa fa-wrench"></i> time</label>
<select type="text" id="node-input-time" style="display: inline-block; width: 250px; vertical-align: top;">
<option value="hour" outputs="1">hour</option>
<option value="day" outputs="1">day</option>
<option value="week" outputs="1">week</option>
<option value="month" outputs="1">month</option>
<option value="year" outputs="1">year</option>
<option value="all" outputs="1">all time</option>
</select>
</div>
<div class="form-row" id="node-action-fetch_all">
<label for="node-input-fetch_all"><i class="icon-tag"></i> fetch All</label>
<select type="text" id="node-input-fetch_all" style="display: inline-block; width: 250px; vertical-align: top;">
<option value="true" outputs="1">true</option>
<option value="false" outputs="1">false</option>
</select>
</div>
<div class="form-row" id="node-action-limit">
<label for="node-input-limit"><i class="icon-tag"></i> limit</label>
<input type="number" min="0" id="node-input-limit" placeholder="limit">
</div>
<div class="form-row" id="node-action-depth">
<label for="node-input-depth"><i class="icon-tag"></i> depth</label>
<input type="number" min="0" id="node-input-depth" placeholder="depth">
</div>
</script>
<script type="text/x-red" data-help-name="get">
<p>Get Reddit submissions, comments, or PMs</p>
<p>This node will get submissions, comments, or personal messages from subreddits, users, your inbox or the listing’s id, according to its configuration.</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>type
<span class="property-type">string</span>
</dt>
<dd> the type of content to be retrieved </dd>
<dt>source
<span class="property-type">string</span>
</dt>
<dd> the source of the content</dd>
<dt class="optional">subreddit
<span class="property-type">string</span>
</dt>
<dd> the subreddit from which submissions or comments will be retrieved</dd>
<dt class="optional">user
<span class="property-type">string</span>
</dt>
<dd> the user who submitted the submissions or comments</dd>
<dt class="optional">content_id
<span class="property-type">string</span>
</dt>
<dd> the id of the listing to be retrieved</dd>
<dt class="optional">sort
<span class="property-type">string</span>
</dt>
<dd> the sorting method for the Reddit content</dd>
<dt class="optional">time
<span class="property-type">string</span>
</dt>
<dd> the time range for the Reddit content</dd>
<dt class="optional">fetch_all
<span class="property-type">string</span>
</dt>
<dd> the option to retrieve all possible content</dd>
<dt class="optional">limit
<span class="property-type">number</span>
</dt>
<dd> the number of listings to be retrieved</dd>
<dt class="optional">depth
<span class="property-type">number</span>
</dt>
<dd> an upper bound for replies in the comment tree</dd>
</dl>
<h3>Outputs</h3>
<ol class="node-ports">
<li>Standard output
<dl class="message-properties">
<dt>payload <span class="property-type">object</span></dt>
<dd>the Snoowrap object representing the Reddit content</dd>
</dl>
</li>
<li>Standard error
<dl class="message-properties">
<dt>payload <span class="property-type">string</span></dt>
<dd>the standard error of the command.</dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<h4>Prefixes</h4>
<p>Exclude the "r/" when entering a <code>subreddit</code> and the "u/" when entering a <code>user</code></p>
<h4>Populating fields</h4>
<p>All text input properties may be hardcoded via text or dynamically populated via mustache syntax relative to the incoming msg object.</p>
<p>For example, if the target <code>subreddit</code> is located in <code>msg.payload.target</code>, then you can fill in <code>{{payload.target}}</code> in the <code>subreddit</code> field.</p>
<h4>Comments</h4>
<p>When a subreddit is the source, the newest comments from the subreddit are retrieved.</p>
<p>When a submission is the source, a comment tree is retrieved, broken up by the parent comments. Replies to these comments, if any, will be in <code>msg.payload.replies</code>.</p>
<h4>Fetch all</h4>
<p>
The <code>fetch_all</code> property is only accessible when retrieving comments or submissions from a user, your own PMs, or comments from a submission.
If set to <code>false</code>, the limit option will determine the number of listings to be retrieved. The Reddit API docs outline the rate limits.
</p>
<h3>References</h3>
<ul>
<li><a href="https://www.reddit.com/dev/api/">Reddit API docs</a> - full description of the Reddit API</li>
<li><a href="https://not-an-aardvark.github.io/snoowrap/">Snoowrap docs</a> - information regarding the limit and depth properties</li>
<li><a href='https://github.com/jcostello93/node-red-contrib-node-reddit'>node-red-contrib-node-reddit</a> - the Node-Reddit github repository</li>
</ul>
</script>
<!-- END Get -->
<!-- START Create -->
<script type="text/javascript">
RED.nodes.registerType('create', {
category: 'reddit',
color: '#a6bbcf',
defaults: {
name: {value: ""},
reddit: { type: "reddit-credentials", required: true},
submissionType: {value: "self"},
subreddit: {value: ""},
title: {value: ""},
url: {value: ""},
text: {value: ""},
original: {value: ""},
recipient: {value: ""},
subject: {value: ""},
message: {value: ""},
},
inputs:1,
outputs:1,
icon: "snoo2.png",
color:"#ffa27f",
label: function() {
if (this.name) {
return this.name;
} else if (this.subreddit && this.subreddit.indexOf("{{") == -1) {
return "r/" + this.subreddit;
} else if (this.recipient && this.recipient.indexOf("{{") == -1) {
return "u/" + this.recipient;
} else {
return "create";
}
},
oneditprepare: () => {
$("#node-input-submissionType").change(() => {
$("#node-action-subreddit").hide();
$("#node-action-title").hide();
$("#node-action-text").hide();
$("#node-action-url").hide();
$("#node-action-original").hide();
$("#node-action-subject").hide();
$("#node-action-recipient").hide();
$("#node-action-message").hide();
let type = $("#node-input-submissionType option:selected").val();
if (type === "self") {
$("#node-action-subreddit").show();
$("#node-action-title").show();
$("#node-action-text").show();
} else if (type === "link") {
$("#node-action-subreddit").show();
$("#node-action-title").show();
$("#node-action-url").show();
} else if (type === "cross") {
$("#node-action-subreddit").show();
$("#node-action-title").show();
$("#node-action-original").show();
} else if (type === "pm") {
$("#node-action-recipient").show();
$("#node-action-subject").show();
$("#node-action-message").show();
}
});
},
});
</script>
<script type="text/x-red" data-template-name="create">
<div class="form-row">
<label for="node-input-reddit"><i class="fa fa-reddit"></i>credentials</label>
<input type="text" id="node-input-reddit">
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i>name</label>
<input type="text" id="node-input-name" placeholder="optional name for this node">
</div>
<hr>
<div class="form-row">
<label for="node-input-submissionType"><i class="fa fa-wrench"></i>type</label>
<select type="text" id="node-input-submissionType" style="display: inline-block; width: 250px; vertical-align: top;">
<option value="self" outputs="1">self-post</option>
<option value="link" outputs="1">link post</option>
<option value="cross" outputs="1">cross-post</option>
<option value="pm" outputs="1">private message</option>
</select>
</div>
<div class="form-row" id="node-action-subreddit">
<label for="node-input-subreddit"><i class="icon-tag"></i>subreddit</label>
<input type="text" id="node-input-subreddit" placeholder="subreddit name">
</div>
<div class="form-row" id="node-action-title">
<label for="node-input-title"><i class="icon-tag"></i>title</label>
<input type="text" id="node-input-title" placeholder="post title">
</div>
<div class="form-row" id="node-action-text">
<label for="node-input-text"><i class="icon-tag"></i>text</label>
<input type="text" id="node-input-text" placeholder="content">
</div>
<div class="form-row" id="node-action-url">
<label for="node-input-url"><i class="icon-tag"></i>url</label>
<input type="text" id="node-input-url" placeholder="url to link">
</div>
<div class="form-row" id="node-action-original">
<label for="node-input-original"><i class="icon-tag"></i>original</label>
<input type="text" id="node-input-original" placeholder="original submission id">
</div>
<div class="form-row" id="node-action-recipient">
<label for="node-input-recipient"><i class="icon-tag"></i>to</label>
<input type="text" id="node-input-recipient" placeholder="recipient's username">
</div>
<div class="form-row" id="node-action-subject">
<label for="node-input-subject"><i class="icon-tag"></i>subject</label>
<input type="text" id="node-input-subject" placeholder="message subject">
</div>
<div class="form-row" id="node-action-message">
<label for="node-input-message"><i class="icon-tag"></i>message</label>
<input type="text" id="node-input-message" placeholder="message">
</div>
</script>
<script type="text/x-red" data-help-name="create">
<p>Create a new Reddit submission or PM.</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>type <span class="property-type">selection</span></dt>
<dd> choose self-, link-, or cross-post, or PM.</dd>
<hr>
<b>For Submissions:</b>
<dt>subreddit <span class="property-type">string</span></dt>
<dd> the subreddit to submit to.</dd>
<dt>title <span class="property-type">string</span></dt>
<dd> the title of the submission.</dd>
<dt> - text <span class="property-type">string</span></dt>
<dd> the text of a self-post.</dd>
<dt> - url <span class="property-type">string</span></dt>
<dd> the url of a link-post.</dd>
<dt> - original <span class="property-type">string</span></dt>
<dd> the original listing name for a cross-post.</dd>
<hr>
<b>For PMs:</b>
<dt>recipient <span class="property-type">string</span></dt>
<dd> the recipient of the PM.</dd>
<dt>subject <span class="property-type">string</span></dt>
<dd> the subject of the PM.</dd>
<dt>message <span class="property-type">string</span></dt>
<dd> the mesage of a PM.</dd>
</dl>
<h3>Outputs</h3>
<ol class="node-ports">
<li>Standard output
<dl class="message-properties">
<dt>payload <span class="property-type">object</span></dt>
<dd> the name of the new submission listing.</dd>
</dl>
</li>
<li>Standard error
<dl class="message-properties">
<dt>payload <span class="property-type">string</span></dt>
<dd>the standard error of the command.</dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<p>Exclude the "r/" when entering your <code>subreddit</code>. "r/<code>subreddit</code>" will be
used for the display name if <code>name</code> is left empty.
</p>
<p>Exclude the "u/" when entering your <code>recipient</code>. "u/<code>recipient</code>" will be
used for the display name if <code>name</code> is left empty.
</p>
<p>
Properties can also be set using mustache syntax of the <code>msg.payload</code>.
</p>
<h3>References</h3>
<ul>
<li><a href='https://www.reddit.com/dev/api/'>Reddit API docs</a> - descriptions of the 3 submission types</li>
<li><a href='https://github.com/jcostello93/node-red-contrib-node-reddit'>node-red-contrib-node-reddit</a> - the Node-Reddit github repository</li>
</ul>
</script>
<!-- END Create -->
<!-- START Reply -->
<script type="text/javascript">
RED.nodes.registerType('reply',{
category: 'reddit',
color: '#a6bbcf',
defaults: {
name: {value:""},
reddit: { type:"reddit-credentials",required:true},
content_type: {value:"submission"},
content_id: {value:""},
text: {value:""}
},
inputs:1,
outputs:1,
align: "left",
icon: "snoo2.png",
color:"#ffa27f",
label: function() {
return this.name||"reply";
}
});
</script>
<script type="text/x-red" data-template-name="reply">
<div class="form-row">
<label for="node-input-reddit"><i class="fa fa-key"></i> <span> credentials</span></label>
<input type="text" id="node-input-reddit">
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> name</label>
<input type="text" id="node-input-name" placeholder="name">
</div>
<hr>
<div class="form-row">
<label for="node-input-content_type"><i class="fa fa-wrench"></i> type</label>
<select type="text" id="node-input-content_type" style="display: inline-block; width: 250px; vertical-align: top;">
<option value="submission" outputs="1">submission</option>
<option value="comment" outputs="1">comment</option>
<option value="pm" outputs="1">PM</option>
</select>
</div>
<div class="form-row">
<label for="node-input-content_id"><i class="icon-tag"></i> content_id</label>
<input type="text" id="node-input-content_id" placeholder="content_id">
</div>
<div class="form-row">
<label for="node-input-text"><i class="icon-tag"></i> text</label>
<input type="text" id="node-input-text" placeholder="text">
</div>
</script>
<script type="text/x-red" data-help-name="reply">
<p>Reply to Reddit submissions, comments, or PMs</p>
<p>This node will reply to submission, comment, or personal message, identified by its Reddit content id.</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>type
<span class="property-type">string</span>
</dt>
<dd> the type of content to be replied to </dd>
<dt>content_id
<span class="property-type">string</span>
</dt>
<dd> the id of the Reddit content to be replied to</dd>
<dt>text
<span class="property-type">string</span>
</dt>
<dd> the body of the response </dd>
</dl>
<h3>Outputs</h3>
<ol class="node-ports">
<li>Standard output
<dl class="message-properties">
<dt>payload <span class="property-type">object</span></dt>
<dd>the Snoowrap object representing the Reddit content</dd>
</dl>
</li>
<li>Standard error
<dl class="message-properties">
<dt>payload <span class="property-type">string</span></dt>
<dd>the standard error of the command.</dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<h4>Populating fields</h4>
<p><code>content_id</code> and <code>text</code> may be hardcoded via text or dynamically populated via mustache syntax relative to the incoming msg object.</p>
<p>For example, if the target <code>content_id</code> is located in <code>msg.payload.target</code>, then you can fill in <code>{{payload.target}}</code> in the <code>content_id</code> field.</p>
<h3>References</h3>
<ul>
<li><a href="https://www.reddit.com/dev/api/">Reddit API docs</a> - full description of the Reddit API</li>
<li><a href='https://github.com/jcostello93/node-red-contrib-node-reddit'>node-red-contrib-node-reddit</a> - the Node-Reddit github repository</li>
</ul>
</script>
<!-- END Reply -->
<!-- START Search -->
<script type="text/javascript">
RED.nodes.registerType('search',{
category: 'reddit',
color: '#a6bbcf',
defaults: {
name: {value:""},
reddit: { type:"reddit-credentials",required:true},
subreddit: {value:"", required:true},
query: {value:"", required:true},
time: {value:"hour"},
sort: {value:"relevance"}
},
inputs:1,
outputs:1,
icon: "snoo2.png",
color:"#ffa27f",
label: function() {
return this.name||"search";
}
});
</script>
<script type="text/x-red" data-template-name="search">
<div class="form-row">
<label for="node-input-reddit"><i class="fa fa-key"></i> <span>credentials</span></label>
<input type="text" id="node-input-reddit">
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> name</label>
<input type="text" id="node-input-name" placeholder="name">
</div>
<hr>
<div class="form-row">