-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
1808 lines (1777 loc) · 82.2 KB
/
index.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
const express = require('express'),
builder = require('botbuilder'),
fs = require('fs'),
request = require('request').defaults({headers: {"User-Agent": "https://metagon.austinhuang.me / im@austinhuang.me"}}),
bodyParser = require('body-parser'),
cloudinary = require('cloudinary'),
decode = require('decode-html'),
connector = new builder.ChatConnector({
appId: process.env.appid,
appPassword: process.env.appkey
}),
botbuilderMongodb = require("botbuilder-mongodb"),
bot = new builder.UniversalBot(connector).set("storage",
botbuilderMongodb.GetMongoDBLayer({
ip: "discoin-shard-00-00-i5e6f.mongodb.net:27017,discoin-shard-00-01-i5e6f.mongodb.net:27017,discoin-shard-00-02-i5e6f.mongodb.net",
port: "27017",
database: "heroku_fs0bkx2s",
collection: "metagon",
username: "austinhuang",
password: process.env.MONGO_PASS,
queryString: "heroku_fs0bkx2s?ssl=true&replicaSet=discoin-shard-0&authSource=admin&retryWrites=true&w=majority"
})
),
gagbrds = ["cute", "anime-manga", "ask9gag", "awesome", "car", "comic", "darkhumor", "country", "food", "funny", "got", "gaming", "gif", "girl", "girly", "horror", "imadedis", "movie-tv", "music", "nsfw", "overwatch", "pcmr", "politics", "relationship", "satisfying", "savage", "science", "superhero", "sport", "school", "timely", "video", "wallpaper", "wtf", "starwars", "classicalartmemes", "travel", "surrealmemes"],
gagsubs = ["hot", "fresh"],
yoda_said = [
'"Fear is the path to the dark side. Fear leads to anger, anger leads to hate, hate leads to suffering." -- Yoda \n',
'"Confer on you, the level of Jedi Knight, the Council does. But, agree with your taking this boy as your Padawan Learner, I do not." -- Yoda to Obi-Wan Kenobi\n',
'"Qui-Gon\'s defiance I sense in you. Need that you do not. Agree with you, the Council does. Your apprentice young Skywalker will be." -- Yoda to Obi-Wan Kenobi\n',
'"Lost a planet, Master Obi-Wan has. How embarrassing, how embarrassing." -- Yoda\n',
'"Go to the center of the gravity\'s pull, and find your planet you will." -- Yoda to Obi-Wan\n',
'"Meditate on this, I will." -- Yoda\n',
'"Clear, your mind must be if you are to discover the real villains behind the plot." -- Yoda to Obi-Wan\n',
'"Pain. Suffering. Death, I feel. Something terrible has happened. Young Skywalker is in pain. Terrible pain." -- Yoda\n',
'"Around the survivors, a perimeter create!" -- Yoda\n',
'"Powerful you have become, Dooku. The dark side I sense in you." -- Yoda to Dooku\n',
'"Master Obi-Wan, not victory. The shroud of the dark side has fallen. Begun, the Clone War has!" -- Yoda\n',
'"Much to learn, you still have." -- Yoda to Dooku\n',
'"Like fire across the galaxy, the Clone Wars spread. In league with the wicked Count Dooku more and more planets slip. Upon the Jedi Knights falls the duty to lead the newly formed Army of the Republic." -- Yoda\n',
'"Death is a natural part of life. Rejoice for those who transform into the Force. Mourn them do not. Miss them do not. Attachment leads to jealousy. The shadow of greed, that is." -- Yoda\n',
'"Careful you must be when sensing the future, Anakin. The fear of loss is a path to the dark side." -- Yoda to Anakin Skywalker\n',
'"Train yourself to let go of everything you fear to lose." -- Yoda to Anakin Skywalker\n',
'"Go, I will. Good relations with the Wookiees, I have." -- Yoda\n',
'"Too much under the sway of the Chancellor, he is. Much anger there is in him. Too much pride in his powers." -- Yoda\n',
'"If a special session of Congress there is, easier for us to enter the Jedi Temple it will be." -- Yoda\n',
'"If into the security recordings you go, only pain will you find." -- Yoda to Obi-Wan Kenobi\n',
'"Destroy the Sith, we must." -- Yoda\n',
'"To fight this Lord Sidious, strong enough, you are not." -- Yoda to Obi-Wan Kenobi\n',
'"Twisted by the dark side, young Skywalker has become." -- Yoda to Obi-Wan Kenobi\n',
'"The boy you trained, gone he is, consumed by Darth Vader." -- Yoda to Obi-Wan Kenobi\n',
'"I hear a new apprentice you have, Emperor. Or should I call you Darth Sidious?" -- Yoda to Palpatine\n',
'"At an end your rule is, and not short enough it was." -- Yoda to Palpatine\n',
'"Not if anything to say about it, I have!" -- Yoda\n',
'"Into exile I must go. Failed, I have." -- Yoda to Bail Organa\n',
'"If so powerful you are, why leave?" -- Yoda\n',
'"Faith in your new apprentice, misplaced may be. As is your faith in the dark side of the Force." -- Yoda\n',
'Luke: "I feel like". Yoda: "Feel like what?" -- Luke Skywalker and Yoda\n',
'"Looking? Found someone you have I would say, mm?" -- Yoda\n',
'"Help you I can! Yes! Mm!" -- Yoda to Luke\n',
'"Awww, cannot get your ship out, heh-heheheh!" -- Yoda to Luke\n',
'"How you get so big, eating food of this kind?" -- Yoda to Luke\n',
'"Mine! Or I will help you not!" -- Yoda to Luke\n',
'"Mudhole? Slimy? My home this is!" -- Yoda to Luke\n',
'"Mine! Mine! Mine! MINE!!!" -- Yoda to R2-D2\n',
'"No, no no, stay and help you I will! Hehe! Find your friend, mm?" -- Yoda to Luke\n',
'"Ohhh, Jedi Master! Yoda. You seek Yoda!" -- Yoda to Luke\n',
'"No! Try not. Do, or do not. There is no try." -- Yoda to Luke\n',
'Luke: "I\'m looking for a great warrior." Yoda: "Wars not make one great." -- Luke Skywalker and Yoda\n',
'"Ready are you? What know you of ready? For eight hundred years have I trained Jedi. My own counsel will I keep on who is to be trained! A Jedi must have the deepest commitment, the most serious mind. This one a long time have I watched. All his life has he looked away, to the future, to the horizon. Never his mind on where he was. Hmm? What he was doing. Hmph. Adventure. Heh. Excitement. Heh. A Jedi craves not these things. You are reckless!" -- Yoda\n',
'Yoda: "I cannot teach him. The boy has no patience." Obi-Wan: "He will learn patience." Yoda: "Hmm. Much anger in him, like his father." Obi-Wan: "Was I any different, when you taught me?" -- Yoda and Obi-Wan Kenobi\n',
'Luke: "I won\'t fail you. I\'m not afraid." Yoda: "You will be. You will be." -- Luke Skywalker and Yoda\n',
'"Yes. A Jedi\'s strength flows from the Force. But beware the dark side. Anger, fear, aggression. The dark side of the Force are they. Easily they flow, quick to join you in a fight. If once you start down the dark path, forever will it dominate your destiny. Consume you it will, as it did Obi-Wan\'s apprentice." -- Yoda to Luke\n',
'Luke: "Vader, Is the dark side stronger?"; Yoda: "No, no, no. Quicker, easier, more seductive.";Luke: "But how am I to know the good side from the bad?";Yoda: "You will know, when you are calm, at peace, passive. A Jedi uses the Force for knowledge and defense, never for attack." -- Yoda to Luke\n',
'"So certain are you. Always with you it cannot be done. Hear you nothing that I say?" -- Yoda to Luke\n',
'"No! No different! Only different in your mind. You must unlearn what you have learned." -- Yoda to Luke\n',
'Luke: "I don\'t believe it"; Yoda: "That is why you fail." -- Yoda to Luke\n',
'"No! Try not. Do. Or do not. There is no try." -- Yoda to Luke , \n',
'"Size matters not. Look at me. Judge me by my size do you?" -- Yoda to Luke\n',
'"And well you should not! For my ally is the Force. And a powerful ally it is. Life creates it, makes it grow. Its energy surrounds us, and binds us. Luminous beings are we, not this, [nudging Luke\'s arm] crude matter! You must feel the Force around you. Here, between you, me, the tree, the rock, everywhere! Even between the land and the ship." -- Yoda to Luke\n',
'"Through the Force, things you will see. Other places. The future, the past, old friends long gone." -- Yoda to Luke\n',
'"Hmm. Control, control. You must learn control." -- Yoda to Luke\n',
'"Difficult to see. Always in motion is the future." -- Yoda to Luke\n',
'"Decide you must how to serve them best. If you leave now, help them you could. But you would destroy all for which they have fought and suffered." -- Yoda to Luke\n',
'"Strong is Vader. Mind what you have learned. Save you it can!" -- Yoda to Luke\n',
'"No. There is another." -- Yoda to Obi-Wan\n',
'"When nine hundred years old you reach, look as good, you will not, hm?" -- Yoda to Luke Skywalker\n',
'"Strong am I with the Force, but not that strong. Twilight is upon me, and soon night must fall. That is the way of things, the way of the Force." -- Yoda to Luke Skywalker\n',
'"No more training do you require. Already know you that which you need." -- Yoda to Luke Skywalker\n',
'"No. Unfortunate that you rushed to face him, that incomplete was your training. Not ready for the burden were you." -- Yoda to Luke Skywalker\n',
'"Remember, a Jedi\'s strength flows from the Force. But beware. Anger, fear, aggression. The dark side are they. Once you start down the dark path, forever will it dominate your destiny." -- Yoda to Luke Skywalker\n',
'"Your father he is." -- Yoda to Luke Skywalker\n',
'"Luke, Luke, Do not, Do not underestimate the powers of the Emperor, or suffer your father\'s fate, you will." -- Yoda to Luke Skywalker\n',
'"Luke, when gone am I, the last of the Jedi will you be." -- Yoda to Luke Skywalker\n',
'"Luke, there is another, Skywalker." -- Yoda to Luke Skywalker\n',
'"Pity your new disciple I do; so lately an apprentice, so soon without a Master." -- Yoda\n',
'"War does not make one great." -- Yoda\n',
'"Proud I am, to stand by Wookiees in their hour of need." -- Yoda\n',
'"Yoda I am, fight I will." -- Yoda\n',
'"Tired I am, rest I must." -- Yoda\n',
'"When all choices seem wrong, choose restraint." -- recalled by Mace Windu\n',
'"If no mistake have you made, yet losing you are, a different game you should play." -- recalled by Mace Windu\n',
'"A trial of being old is this: remembering which thing one has said into which young ears." -- Yoda\n',
'Yoda: "Think you I have never felt the touch of the dark? Know you what a soul so great as Yoda can make, in eight hundred years?"; Dooku: "Master?"; Yoda: "Many mistakes!" -- Yoda and Dooku\n',
'"Think you the relationship between Master and Padawan is only to help them? Oh, this is what we let them believe, yes! But when the day comes that even old Yoda does not learn something from his students-then truly, he shall be a teacher no more." -- Yoda\n',
'"On many long journeys have I gone. And waited, too, for others to return from journeys of their own. Some return; some are broken; some come back so different only their names remain." -- Yoda\n',
'"When you fall, apprentice, catch you I will." -- Yoda to Dooku\n',
'"Secret, shall I tell you? Grand Master of Jedi Order am I. Won this job in a raffle I did, think you? "How did you know, how did you know, Master Yoda?" Master Yoda knows these things. His job it is." -- Master Yoda to Scout\n',
'"Honor life by living, Padawan. Killing honors only death: only the dark side." -- Yoda\n',
'"To be Jedi is to face the truth, and choose. Give off light, or darkness, Padawan. Be a candle, or the night, Padawan: but choose!" -- Yoda to Whie Malreaux\n',
'"When you look at the dark side, careful you must be , for the dark side looks back." -- Yoda\n',
'"You think Yoda stops teaching, just because his student does not want to hear? Yoda a teacher is. Yoda teaches like drunkards drink. Like killers kill." -- Yoda\n',
'"Humility endless is." -- Yoda\n',
'"A labyrinth of evil, this war has become." -- Yoda\n',
'"Sworn by oath to uphold you, we are." -- Yoda to Palpatine\n',
'"From the dark path, no returning there is. Forever, the direction of your life it dominates." -- Yoda\n',
'"To the Force, look for guidance. Accept what fate has placed before us." -- Yoda\n',
'"Yoda, you seek?" -- Yoda\n', '"My ally is the Force" -- Yoda\n'
],
parseString = require('xml2js').parseString;
cloudinary.config({
cloud_name: 'metagon',
api_key: process.env.cloudinary1,
api_secret: process.env.cloudinary2
});
var nsfw = JSON.parse(fs.readFileSync("./nsfw.json", "utf8"));
//bot.connector("cisco", cisco);
bot.use({
botbuilder: function (session, next) {
session.error = function (err) {
session.endDialog("An error occured. Please report this, along with the chat history, to \"im@austinhuang.me\".\n\n"+err);
console.error(err.stack);
};
next();
}
});
function f2c(f) {
var c = (parseInt(f) - 32) / 1.8;
return c.toFixed();
}
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
bot.on('conversationUpdate', function (message) {
if (message.address.conversation.isGroup) {
if (message.membersAdded) {
message.membersAdded.forEach(function (identity) {
if (identity.id === message.address.bot.id) {
var reply = new builder.Message()
.address(message.address)
.text("Hello everyone! This is Metagon. You can reply \"start\" to start using me! For more info, visit http://metagon.austinhuang.me.");
bot.send(reply);
}
});
}
if (message.membersRemoved) {
message.membersRemoved.forEach(function (identity) {
if (identity.id === message.address.bot.id) {
var reply = new builder.Message()
.address(message.address)
.text("Sorry to see you go! If you experienced issue, or you'd like to see a better Metagon, please tell us at http://metagon.austinhuang.me/#contact-us.");
bot.send(reply);
}
});
}
}
});
bot.on('contactRelationUpdate', function (message) {
if (message.action === 'add') {
var name = message.user ? message.user.name : null;
var reply = new builder.Message()
.address(message.address)
.text("Hello there! This is Metagon. You can reply \"start\" to start using me! For more info, visit http://metagon.austinhuang.me.");
bot.send(reply);
}
});
// Menus
bot.dialog('/menu', [
function (session) {
if (session.message.source === "groupme" || session.message.source === "skypeforbusiness" || session.message.source === "ciscospark") {
session.send("Keyboard Mode is not available on GroupMe / Skype for Business. Please use only commands.\nFor more information, type \"help\".");
}
else if (session.message.source !== "line" && session.message.source !== "facebook") {
builder.Prompts.choice(session, "What would you like to do right now?", "Images|Utility|Fun|About|Feedback|Quit", { listStyle: 3 });
}
else {
var msg = new builder.Message(session);
msg.attachmentLayout(builder.AttachmentLayout.carousel);
msg.attachments([
new builder.HeroCard(session)
.text("What would you like to do right now?")
.buttons([
builder.CardAction.imBack(session, "Images", "Images"),
builder.CardAction.imBack(session, "Utility", "Utility"),
builder.CardAction.imBack(session, "Fun", "Fun")
]),
new builder.HeroCard(session)
.text("What would you like to do right now?")
.buttons([
builder.CardAction.imBack(session, "About", "About"),
builder.CardAction.imBack(session, "Feedback", "Feedback"),
builder.CardAction.imBack(session, "Quit", "Quit")
])
]);
builder.Prompts.choice(session, msg, "Images|Utility|Fun|About|Feedback|Quit");
}
}, function (session, results) {
switch (results.response.entity) {
case "Images":
session.replaceDialog("/image");
break;
case "Utility":
session.replaceDialog("/utility");
break;
case "Fun":
session.replaceDialog("/fun");
break;
case "About":
session.replaceDialog("/about");
break;
case "Feedback":
session.replaceDialog("/feedback");
break;
case "Quit":
session.endDialog("You have quit the keyboard mode. You can start again by typing \"start\".");
break;
}
}
]).triggerAction({ matches: /^(\/|Metagon |)start/gi});
bot.dialog('/image', [
function (session) {
switch (session.message.source) {
case "kik":
builder.Prompts.choice(session, "What would you like to do right now?", "Cat|Dog|Snake|Bunny|Anime actions|Back to Start Menu|Quit", { listStyle: 3 });
break;
case "line":
case "facebook":
var msg = new builder.Message(session);
msg.attachmentLayout(builder.AttachmentLayout.carousel);
msg.attachments([
new builder.HeroCard(session)
.text("What would you like to do right now?")
.buttons([
builder.CardAction.imBack(session, "Imgur", "Imgur"),
builder.CardAction.imBack(session, "Flickr", "Flickr"),
]),
new builder.HeroCard(session)
.text("What would you like to do right now?")
.buttons([
builder.CardAction.imBack(session, "DeviantArt", "DeviantArt"),
builder.CardAction.imBack(session, "Anime actions", "Anime actions"),
builder.CardAction.imBack(session, "Cat", "Cat")
]),
new builder.HeroCard(session)
.text("What would you like to do right now?")
.buttons([
builder.CardAction.imBack(session, "Dog", "Dog"),
builder.CardAction.imBack(session, "Snake", "Snake"),
builder.CardAction.imBack(session, "Bunny", "Bunny")
]),
new builder.HeroCard(session)
.text("What would you like to do right now?")
.buttons([
builder.CardAction.imBack(session, "Duck", "Duck"),
builder.CardAction.imBack(session, "Birb", "Birb"),
builder.CardAction.imBack(session, "Back to Start Menu", "Back to Start Menu"),
])
]);
builder.Prompts.choice(session, msg, "Imgur|Flickr|DeviantArt|Anime actions|Cat|Dog|Snake|Bunny|Duck|Birb|Back to Start Menu|Quit");
break;
default:
builder.Prompts.choice(session, "What would you like to do right now?", "Imgur|Flickr|DeviantArt|Anime actions|Cat|Dog|Snake|Bunny|Duck|Birb|Back to Start Menu|Quit", { listStyle: 3 });
break;
}
},
function (session, results) {
switch (results.response.entity) {
case "Imgur":
session.replaceDialog("/imgur1");
break;
case "Flickr":
session.replaceDialog("/flickr1");
break;
case "DeviantArt":
session.replaceDialog("/deviantart1");
break;
case "Anime actions":
session.replaceDialog("/anime");
break;
case "Back to Start Menu":
session.beginDialog("/menu");
break;
case "Quit":
session.endDialog("You have quit the keyboard mode. You can start again by typing \"start\".");
break;
default:
session.replaceDialog("/"+results.response.entity.toLowerCase());
break;
}
}
]);
bot.dialog('/utility', [
function (session) {
switch (session.message.source) {
case "line":
case "facebook":
var msg = new builder.Message(session);
msg.attachmentLayout(builder.AttachmentLayout.carousel);
msg.attachments([
new builder.HeroCard(session)
.text("What would you like to do right now?")
.buttons([
builder.CardAction.imBack(session, "Weather", "Weather"),
builder.CardAction.imBack(session, "Dictionary", "Dictionary"),
builder.CardAction.imBack(session, "Shorten URLs", "Shorten URLs")
]),
new builder.HeroCard(session)
.text("What would you like to do right now?")
.buttons([
builder.CardAction.imBack(session, "Expand Bitly URLs", "Expand Bitly URLs"),
builder.CardAction.imBack(session, "Minecraft User Lookup", "Minecraft User"),
builder.CardAction.imBack(session, "Minecraft Server Ping", "Minecraft Server")
]),
new builder.HeroCard(session)
.text("What would you like to do right now?")
.buttons([
builder.CardAction.imBack(session, "Pastebin", "Pastebin"),
builder.CardAction.imBack(session, "Back to Start Menu", "Back to Start Menu"),
builder.CardAction.imBack(session, "Quit", "Quit")
])
]);
builder.Prompts.choice(session, msg, "Weather|Shorten URLs|Expand Bitly URLs|Minecraft User Lookup|Minecraft Server Status|Pastebin|Back to Start Menu|Quit", { listStyle: 0 });
break;
default:
builder.Prompts.choice(session, "What would you like to do right now?", "Weather|Dictionary|Shorten URLs|Expand Bitly URLs|Minecraft User Lookup|Minecraft Server Status|Pastebin|Back to Start Menu|Quit", { listStyle: 3 });
break;
}
},
function (session, results) {
switch (results.response.entity) {
case "Shorten URLs":
session.replaceDialog("/shorten1");
break;
case "Expand Bitly URLs":
session.replaceDialog("/expand1");
break;
case "Minecraft User Lookup":
session.replaceDialog("/mcuser1");
break;
case "Minecraft Server Status":
session.replaceDialog("/mcserver1");
break;
case "Back to Start Menu":
session.beginDialog("/menu");
break;
case "Quit":
session.endDialog("You have quit the keyboard mode. You can start again by typing \"start\".");
break;
default:
session.replaceDialog("/"+results.response.entity.toLowerCase()+"1");
break;
}
}
]);
bot.dialog('/fun', [
function (session) {
switch (session.message.source) {
case "line":
case "facebook":
var msg = new builder.Message(session);
msg.attachmentLayout(builder.AttachmentLayout.carousel);
msg.attachments([
new builder.HeroCard(session)
.text("What would you like to do right now?")
.buttons([
builder.CardAction.imBack(session, "9gag", "9gag"),
builder.CardAction.imBack(session, "Urban Dictionary", "Urban Dictionary"),
builder.CardAction.imBack(session, "Cat Facts", "Cat Facts")
]),
new builder.HeroCard(session)
.text("What would you like to do right now?")
.buttons([
builder.CardAction.imBack(session, "Trivia", "Trivia"),
builder.CardAction.imBack(session, "Chuck Norris", "Chuck Norris"),
builder.CardAction.imBack(session, "Yoda Quote", "Yoda Quote")
]),
new builder.HeroCard(session)
.text("What would you like to do right now?")
.buttons([
builder.CardAction.imBack(session, "Quote on Design", "Quote on Design"),
builder.CardAction.imBack(session, "Back to Start Menu", "Back to Start Menu"),
builder.CardAction.imBack(session, "Quit", "Quit")
])
]);
builder.Prompts.choice(session, msg, "9gag|Urban Dictionary|Cat Facts|Trivia|Chuck Norris|Yoda Quote|Quote on Design|Back to Start Menu|Quit");
break;
default:
builder.Prompts.choice(session, "What would you like to do right now?", "9gag|Urban Dictionary|Cat Facts|Trivia|Chuck Norris|Yoda Quote|Quote on Design|Back to Start Menu|Quit", { listStyle: 3 });
break;
}
},
function (session, results) {
switch (results.response.entity) {
case "9gag":
session.replaceDialog("/9gag1");
break;
case "Urban Dictionary":
session.replaceDialog("/ud1");
break;
case "Chuck Norris":
session.replaceDialog("/joke");
break;
case "Cat Facts":
session.replaceDialog("/catfact");
break;
case "Trivia":
session.replaceDialog("/trivia1");
break;
case "Yoda Quote":
session.replaceDialog("/yoda");
break;
case "Quote on Design":
session.replaceDialog("/design");
break;
case "Back to Start Menu":
session.beginDialog("/menu");
break
case "Quit":
session.endDialog("You have quit the keyboard mode. You can start again by typing \"start\".");
break;
}
}
]);
bot.dialog('/about', function (session) {
if (session.message.source === "kik") {
session.send("Thank you for using Metagon. I am a multi-platform multi-function bot to suit your needs!\n\n* Documentation: http://metagon.austinhuang.me\n* Suggestions: https://feedback.austinhuang.me\n* If you have any questions, feel free to contact my master at @austinhuang0131 .\n* Do I help you a lot? Consider a small donation (Detail in documentation)!\n* The simplest way to use this bot is by typing \"start\".");
}
else if (session.message.source === "telegram") {
session.send("Thank you for using Metagon. I am a multi-platform multi-function bot to suit your needs!\n\n* Documentation: http://metagon.austinhuang.me\n* Suggestions: https://feedback.austinhuang.me\n* If you have any questions, feel free to contact my master at @austinhuang .\n* Do I help you a lot? Consider a small donation (Detail in documentation)!\n* The simplest way to use this bot is by typing \"start\".");
}
else if (session.message.source === "line") {
session.send("Thank you for using Metagon. I am a multi-platform multi-function bot to suit your needs!\n\n* Documentation: http://metagon.austinhuang.me\n* Suggestions: https://feedback.austinhuang.me\n* If you have any questions, feel free to contact my master by adding me (line://ti/p/eCQ4745xqO).\n* Do I help you a lot? Consider a small donation (Detail in documentation)!\n* The simplest way to use this bot is by typing \"start\".");
}
else if (session.message.source === "skype") {
session.send("Thank you for using Metagon. I am a multi-platform multi-function bot to suit your needs!\n\n* Documentation: http://metagon.austinhuang.me\n* Suggestions: https://feedback.austinhuang.me\n* If you have any questions, feel free to contact my master at \"live:austin.0131\".\n* Do I help you a lot? Consider a small donation (Detail in documentation)!\n* The simplest way to use this bot is by typing \"start\".");
}
else if (session.message.source === "slack" && session.message.address.conversation.isGroup) {
session.send();
}
else {
session.send("Thank you for using Metagon. I am a multi-platform multi-function bot to suit your needs!\n\n* Documentation: https://metagon.austinhuang.me\n* Contact us: https://austinhuang.me/contact\n* Suggestions: https://feedback.austinhuang.me\n\nDo I help you a lot? Consider a small donation (Detail in documentation)! The simplest way to use this bot is by typing \"start\".");
}
if (session.message.source !== "groupme" && session.message.source !== "skypeforbusiness" && session.message.source !== "ciscospark" && session.message.text !== ("/help")) {
session.replaceDialog("/menu");
}
else {
session.endDialog();
}
}).triggerAction({ matches: /^(\/|)help/i});
bot.dialog('/feedback', function (session) {
session.send("https://feedback.austinhuang.me");
session.replaceDialog("/menu");
});
// Image
bot.dialog('/cat', function (session) {
if (session.message.source !== "line") {session.sendTyping();}
request('http://aws.random.cat/meow', {json: true}, function(error, response, body) {
if (!error && response.statusCode === 200) {
var type = body.file.endsWith(".gif") ? "gif" : "jpeg";
session.send({
attachments: [
{
contentType: "image/"+type,
contentUrl: body.file,
name: "cat."+type.replace("jpeg", "jpg")
}
]
});
if (!session.message.text.includes("/cat")) session.beginDialog("/image");
}
else {
session.endDialog("ERROR! I could not connect to http://aws.random.cat/meow. Please retry. If the problem persists, please contact im@austinhuang.me");
}
});
}).triggerAction({ matches: /^( ||Metagon )\/cat/g});
bot.dialog('/snake', function (session) {
if (session.message.source !== "line") {session.sendTyping();}
request('http://fur.im/snek', {json: true}, function(error, response, body) {
if (!error && response.statusCode === 200) {
session.send({
attachments: [
{
contentType: "image/*",
contentUrl: body.file.replace("http://", "https://")
}
]
});
if (!session.message.text.includes("/snake")) {
session.replaceDialog("/image");
}
else {
session.endDialog();
}
}
else {
session.endDialog("ERROR! I could not connect to http://fur.im/snek/snek.php. Please retry. If the problem persists, please contact im@austinhuang.me");
}
});
}).triggerAction({ matches: /^( ||Metagon )\/snake/g});
bot.dialog('/dog', function (session) {
if (session.message.source !== "line") {session.sendTyping();}
request('https://random.dog/woof.json', function(error, response, body) {
if (!error && response.statusCode === 200) {
body = JSON.parse(body);
if (body.url.endsWith("mp4") || body.url.endsWith("webm")) { session.send({
attachments: [
{
contentType: "video/*",
contentUrl: body.url
}
]
});
}
else { session.send({
attachments: [
{
contentType: "image/*",
contentUrl: body.url
}
]
});
}
if (!session.message.text.includes("/dog")) {
session.replaceDialog("/image");
}
else {
session.endDialog();
}
}
else {
session.endDialog("ERROR! I could not connect to https://random.dog/woof.json. Please retry. If the problem persists, please contact im@austinhuang.me");
}
});
}).triggerAction({ matches: /^( ||Metagon )\/dog/g});
bot.dialog('/bunny', function (session) {
if (session.message.source !== "line") {session.sendTyping();}
request('https://api.bunnies.io/v2/loop/random/?media=gif,mp4', function(error, response, body) {
if (!error && response.statusCode === 200 && session.message.source.includes("skype") && session.message.source.includes("kik")) {
body = JSON.parse(body);
session.send({
attachments: [
{
contentType: "video/*",
contentUrl: body.media.mp4
}
]
});
if (!session.message.text.includes("/bunny")) {
session.replaceDialog("/image");
}
else {
session.endDialog();
}
}
else if (!error && response.statusCode === 200) {
body = JSON.parse(body);
session.send({
attachments: [
{
contentType: "image/gif",
contentUrl: body.media.gif
}
]
});
if (!session.message.text.includes("/bunny")) {
session.replaceDialog("/image");
}
else {
session.endDialog();
}
}
else {
session.send("ERROR! I could not connect to https://api.bunnies.io/v2/loop/random/?media=gif,mp4 . Please retry. If the problem persists, please contact im@austinhuang.me");
}
});
}).triggerAction({ matches: /^( ||Metagon )\/bunny/g});
bot.dialog('/birb', function (session) {
if (session.message.source !== "line") {session.sendTyping();}
request('https://random.birb.pw/tweet', function(error, response, body) {
if (!error && response.statusCode === 200) {
var type = body.endsWith(".gif") ? "gif" : "*";
session.endDialog({
attachments: [
{
contentType: "image/" + type,
contentUrl: "https://random.birb.pw/img/"+body
}
]
});
if (!session.message.text.includes("/bir")) session.beginDialog("/image");
}
else {
session.endDialog("ERROR! I could not connect to https://random.birb.pw/tweet. Please retry. If the problem persists, please contact im@austinhuang.me");
}
});
}).triggerAction({ matches: /^( ||Metagon )\/bir(b|d)/g});
bot.dialog('/duck', function (session) {
if (session.message.source !== "line") {session.sendTyping();}
request('https://random-d.uk/api/v1/random', function(error, response, body) {
if (!error && response.statusCode === 200) {
body = JSON.parse(body);
var type = body.url.endsWith(".gif") ? "gif" : "jpeg";
session.endDialog({
attachments: [
{
contentType: "image/" + type,
contentUrl: body.url
}
]
});
if (!session.message.text.includes("/duck")) session.beginDialog("/image");
}
else {
session.endDialog("ERROR! I could not connect to https://random-d.uk/api/v1/random. Please retry. If the problem persists, please contact im@austinhuang.me");
}
});
}).triggerAction({ matches: /^( ||Metagon )\/duck/g});
bot.dialog('/anime', [
function (session) {
if (session.message.source !== "line") builder.Prompts.choice(session, "What would you like to do right now?", "Kiss|Pat|Hug|Feed|Poke|Slap|Cuddle|Tickle|Back to Image Menu|Quit", { listStyle: 3 });
else {
var msg = new builder.Message(session);
msg.attachmentLayout(builder.AttachmentLayout.carousel);
msg.attachments([
new builder.HeroCard(session)
.text("What would you like to do right now?")
.buttons([
builder.CardAction.imBack(session, "Kiss", "Kiss"),
builder.CardAction.imBack(session, "Pat", "Pat"),
builder.CardAction.imBack(session, "Hug", "Hug")
]),
new builder.HeroCard(session)
.text("What would you like to do right now?")
.buttons([
builder.CardAction.imBack(session, "Poke", "Pole"),
builder.CardAction.imBack(session, "Slap", "Slap"),
builder.CardAction.imBack(session, "Cuddle", "Cuddle")
]),
new builder.HeroCard(session)
.text("Due to Line API restrictions, all GIFs will NOT be displayed properly.")
.buttons([
builder.CardAction.imBack(session, "Feed", "Feed"),
builder.CardAction.imBack(session, "Tickle", "Tickle"),
builder.CardAction.imBack(session, "Back to Image Menu", "Back to Image Menu"),
])
]);
builder.Prompts.choice(session, msg, "Kiss|Pat|Hug|Feed|Poke|Slap|Cuddle|Tickle|Back to Image Menu|Quit");
}
},
function (session, results) {
switch (results.response.entity) {
case "Back to Image Menu":
session.beginDialog("/image");
break;
case "Quit":
session.endDialog("You have quit the keyboard mode. You can start again by typing \"start\".");
break;
default:
session.beginDialog("/kph");
break;
}
}
]);
bot.dialog('/kph', function (session) {
var endpoint = "hug";
if (session.message.text.search(/kiss/gi) > -1) {endpoint = "kiss";}
else if (session.message.text.search(/pat/gi) > -1) {endpoint = "pat"}
else if (session.message.text.search(/poke/gi) > -1) {endpoint = "poke"}
else if (session.message.text.search(/slap/gi) > -1) {endpoint = "slap"}
else if (session.message.text.search(/cuddle/gi) > -1) {endpoint = "cuddle"}
else if (session.message.text.search(/feed/gi) > -1) {endpoint = "feed"}
request('https://nekos.life/api/v2/img/'+endpoint, function(error, response, body) {
if (!error && response.statusCode === 200) {
body = JSON.parse(body);
session.send({
attachments: [
{
contentType: "image/gif",
contentUrl: body.url
}
]
});
if (!session.message.text.includes("/")) {
session.replaceDialog("/anime");
}
}
else {
session.endDialog("ERROR! I could not connect to https://nekos.life/api. Please retry. If the problem persists, please contact im@austinhuang.me");
}
});
}).triggerAction({ matches: /^( ||Metagon )\/(kiss|pat|hug|poke|slap|cuddle|feed|tickle)/g});
bot.dialog('/imgur1',[
function (session) {
var msg = new builder.Message(session);
msg.attachmentLayout(builder.AttachmentLayout.list);
msg.attachments([
new builder.HeroCard(session)
.title("Input a search query.")
.subtitle("ProTip: Supports boolean operators (AND, OR, NOT) and indices (tag: user: title: ext: subreddit: album: meme:).")
.buttons([
builder.CardAction.imBack(session, "Back to Image Menu", "Back to Image Menu")
])
]);
builder.Prompts.text(session, msg);
},
function (session, results) {
if (results.response.replace(/^Metagon /g, "") !== "Back to Image Menu") {
request({url:"https://api.imgur.com/3/gallery/search?q="+results.response.replace(/^Metagon /g, ""), headers:{'Authorization': 'Client-ID '+process.env.imgur}}, function(error, response, body) {
if (!error && response.statusCode === 200) {
body = JSON.parse(body);
if (body.data.length === 0) {
session.send("No results. Change your query?");
session.replaceDialog("/image");
}
else {
session.send(body.data[Math.floor(Math.random() * body.data.length)].link);
session.replaceDialog("/image");
}
}
else {
session.send("Failed to connect to http://imgur.com");
session.replaceDialog("/image");
}
});
}
else {
session.replaceDialog("/image");
}
}]);
bot.dialog('/imgur2', function (session) {
if (session.message.source === "kik") {
session.endDialog('It seems like you\'re confused. Maybe try typing \"help\". Alternatively, type \"start\" to start the bot up.');
return;
}
if (session.message.text.replace("/imgur", "").replace(" ", "") !== "") {
request({url:"https://api.imgur.com/3/gallery/search?q="+session.message.text.substring(7), headers:{'Authorization': 'Client-ID '+process.env.imgur}}, function(error, response, body) {
if (!error && response.statusCode === 200) {
body = JSON.parse(body);
if (body.data.length === 0) {session.endDialog("No results. Change your query?");}
else {session.endDialog(body.data[Math.floor(Math.random() * body.data.length)].link);}
}
else {session.endDialog("Failed to connect to http://imgur.com");}
});
}
else {
session.endDialog("Missing search query! Correct usage: \"/imgur (Query)\"");
}
}).triggerAction({ matches: /^( ||Metagon )\/imgur/g});
bot.dialog('/flickr1',[
function (session) {
var msg = new builder.Message(session);
msg.attachmentLayout(builder.AttachmentLayout.list);
msg.attachments([
new builder.HeroCard(session)
.title("Input a search query.")
.buttons([
builder.CardAction.imBack(session, "Back to Image Menu", "Back to Image Menu")
])
]);
builder.Prompts.text(session, msg);
},
function (session, results, next) {
if (results.response.replace(/^Metagon /g, "") !== "Back to Image Menu") {
if (session.message.source !== "line") {session.sendTyping();}
request("https://api.flickr.com/services/rest?api_key="+process.env.flickr+"&method=flickr.photos.search&text="+results.response.replace(/^Metagon /g, "")+"&format=json&per_page=500&nojsoncallback=1&media=photos", function(error, response, body) {
if (!error && response.statusCode === 200) {
body = JSON.parse(body);
var photo = body.photos.photo[Math.floor(Math.random() * body.photos.photo.length)];
if (photo === undefined) {
session.send("No results.");
session.replaceDialog("/image");
return;
}
request("https://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key="+process.env.flickr+"&photo_id="+photo.id+"&format=json&nojsoncallback=1", function(error, response, body) {
if (!error && response.statusCode === 200) {
body = JSON.parse(body);
if (!body.sizes) {
session.send("A persisting error occured. Please report this with your whole dialog to https://github.com/austinhuang0131/metagon/issues or email \"im@austinhuang.me\".");
}
else {
session.send({
text: photo.title,
attachments: [
{
contentType: "image/*",
contentUrl: body.sizes.size[body.sizes.size.length - 1].source
}
]
});
}
session.replaceDialog("/image");
}
else {
session.send("Failed to connect to http://flickr.com");
session.replaceDialog("/image");
}
});
}
else {
session.send("Failed to connect to http://flickr.com");
session.replaceDialog("/image");
}
});
}
else {
session.replaceDialog("/image");
}
}]);
bot.dialog('/flickr2', function (session) {
if (session.message.source === "kik") {
session.endDialog('It seems like you\'re confused. Maybe try typing \"help\". Alternatively, type \"start\" to start the bot up.');
return;
}
if (session.message.source !== "line") {session.endDialogTyping();}
if (session.message.text.replace(/( |)\/flickr/, "") !== "") {
request("https://api.flickr.com/services/rest?api_key="+process.env.flickr+"&method=flickr.photos.search&text="+session.message.text.replace(/( |)\/flickr/, "")+"&format=json&per_page=500&nojsoncallback=1", function(error, response, body) {
if (!error && response.statusCode === 200) {
body = JSON.parse(body);
var photo = body.photos.photo[Math.floor(Math.random() * body.photos.photo.length)];
if (photo === undefined) {
session.endDialog("No results.");
return;
}
request("https://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key="+process.env.flickr+"&photo_id="+photo.id+"&format=json&nojsoncallback=1", function(error, response, body) {
if (!error && response.statusCode === 200) {
body = JSON.parse(body);
if (!body.sizes) {
session.endDialog("A persisting error occured. Please report this with your whole dialog to https://github.com/austinhuang0131/metagon/issues or email \"im@austinhuang.me\".");
}
else {
session.endDialog({
text: photo.title,
attachments: [
{
contentType: "image/*",
contentUrl: body.sizes.size[body.sizes.size.length - 1].source
}
]
});
}
}
else {session.endDialog("Failed to connect to http://flickr.com");}
});
}
else {session.endDialog("Failed to connect to http://flickr.com");}
});
}
else {
session.endDialog("Missing search query! Correct usage: \"/flickr (Query)\"");
}
}).triggerAction({ matches: /^( ||Metagon )\/flickr/g});
bot.dialog('/deviantart1',[
function (session) {
var msg = new builder.Message(session);
msg.attachmentLayout(builder.AttachmentLayout.list);
msg.attachments([
new builder.HeroCard(session)
.title("Input a search query.")
.buttons([
builder.CardAction.imBack(session, "Back to Image Menu", "Back to Image Menu")
])
]);
builder.Prompts.text(session, msg);
},
function (session, results) {
if (results.response.replace(/^Metagon /g, "") !== "Back to Image Menu") {
if (session.message.source !== "line") {session.sendTyping();}
request("https://backend.deviantart.com/rss.xml?type=deviation&q="+results.response.replace(/^Metagon /g, ""), function(error, response, body) {
if (!error && response.statusCode === 200) {
parseString(body, function (err, result) {
if (!result.rss.channel[0].item) {
session.send("No results!");
session.replaceDialog("/image");
return;
}
var things = result.rss.channel[0].item.filter(r => {return r["media:content"][0]["$"].medium === "image";});
var thing = things[Math.floor(Math.random() * things.length)];
session.send({
text: thing.title[0],
attachments: [
{
contentType: "image/*",
contentUrl: thing["media:content"][0]["$"].url
}
]
});
session.replaceDialog("/image");
});
}
else {
session.send("Failed to connect to https://backend.deviantart.com/rss.xml");
session.replaceDialog("/image");
}
});
}
else {
session.replaceDialog("/image");
}
}]);
bot.dialog('/deviantart2', function (session) {
if (session.message.source === "kik") {
session.send('It seems like you\'re confused. Maybe try typing \"help\". Alternatively, type \"start\" to start the bot up.');
return;
}
if (session.message.source !== "line") {session.sendTyping();}
if (session.message.text.replace(/( |)\/deviantart/, "") !== "") {
request("https://backend.deviantart.com/rss.xml?type=deviation&q="+session.message.text.replace(/( |)\/deviantart/, ""), function(error, response, body) {
if (!error && response.statusCode === 200) {
parseString(body, function (err, result) {
if (!result.rss.channel[0].item) {
session.send("No results!");
session.replaceDialog("/image");
return;
}
var thing = result.rss.channel[0].item[Math.floor(Math.random() * result.rss.channel[0].item.length)];
session.endDialog({
text: thing.title[0],
attachments: [
{
contentType: "image/*",
contentUrl: thing["media:content"][0]["$"].url
}
]
});
});
}
else {
console.log(body);
session.endDialog("Failed to connect to https://backend.deviantart.com/rss.xml");
}
});
}
else {
session.endDialog("Missing search query! Correct usage: \"/deviantart (Query)\"");
}
}).triggerAction({ matches: /^( ||Metagon )\/deviantart/g});
// Utility
bot.dialog('/shorten1',[
function (session) {
var msg = new builder.Message(session);
msg.attachmentLayout(builder.AttachmentLayout.list);
msg.attachments([
new builder.HeroCard(session)
.title("Input the URL you'd like to shorten.")
.subtitle("ProTip: Does not need http://")
.buttons([
builder.CardAction.imBack(session, "Back to Utility Menu", "Back to Utility Menu")
])
]);
builder.Prompts.text(session, msg);
},
function (session, results) {
if (results.response.replace(/^Metagon /g, "").endsWith("Back to Utility Menu")) {
session.replaceDialog("/utility");
return;
}
if (results.response.replace(/^Metagon /g, "").startsWith("<") && results.response.replace(/^Metagon /g, "").includes("|")) {
var site = results.response.replace(/^Metagon /g, "").split("|")[0].replace("<", "");
}
else if (results.response.replace(/^Metagon /g, "").startsWith("<")) {
var site = results.response.replace(/^Metagon /g, "").replace("<", "").replace(">", "").replace(";", "");
}
else {
var site = results.response.replace(/^Metagon /g, "");
}
if (!site.startsWith("http")) {
site = "http://"+results.response.replace(/^Metagon /g, "");
}