├── .github ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md └── ISSUE_TEMPLATE.md ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── index.js ├── nsfw.json └── package.json /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at im@austinhuang.me. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]. 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Issue 2 | ### Don't post issues: 3 | * Relating to the uptime (After a crash, the bot should restart within 20 minutes if I'm not online, or 5 minutes if I'm online. Uptime is monitored.) 4 | * Relating to the content (We are not responsible for the content provided by various APIs.) 5 | * Unless you're on Kik, where NSFW content is prohibited. As such, you should report to us if the bot posted something questionable **on Kik**. 6 | * Without the template 7 | 8 | ## Pull Request 9 | * **Working on your first Pull Request?** You can learn how from this *free* series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github). (This is just an AD) 10 | * **Please [test it](https://docs.microsoft.com/en-us/bot-framework/debug-bots-emulator) before you request.** 11 | 12 | Thank you for contributing. 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | * Platform: 2 | * Category: 3 | 4 | ## Description 5 | 6 | 7 | ### Steps to Reproduce 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | script: 3 | - npm start 4 | node_js: 5 | - "node" 6 | - "6" 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2017, Austin Huang 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Metagon does a lot. From bringing you the nicest pictures, to providing you the best tools, and giving you the best fun! 2 | 3 | * Search 9gag posts, or get a random post in a section 4 | * Random animal pics 5 | * Search anime pics from major boorus and Pixiv 6 | * Search pics from Imgur and Flickr 7 | * Minecraft tools for servers and users 8 | * Bitly tools 9 | 10 | and more coming up! 11 | 12 | [![Uptime Robot status](https://img.shields.io/uptimerobot/status/m779086466-6bca943c1fe4a5b743ed0a9a.svg)](https://0131.statuspage.io) [![GitHub issues](https://img.shields.io/github/issues/austinhuang0131/metagon.svg)](https://github.com/austinhuang0131/metagon/issues) [![Codacy grade](https://img.shields.io/codacy/grade/d481eda7342f4258a99cf30122acbc90.svg)](https://www.codacy.com/app/austinhuang0131/metagon-telegram) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com) [![license](https://img.shields.io/github/license/austinhuang0131/metagon.svg)]() [![Open Source Love](https://badges.frapsoft.com/os/v3/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/) 13 | 14 | [![forthebadge](https://forthebadge.com/images/badges/contains-cat-gifs.svg)](http://forthebadge.com) [![forthebadge](https://forthebadge.com/images/badges/uses-badges.svg)](http://forthebadge.com) [![forthebadge](https://forthebadge.com/images/badges/uses-js.svg)](http://forthebadge.com) [![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](http://forthebadge.com) 15 | 16 | ## Invite Me! 17 | [![GroupMe](https://dev.botframework.com/client/images/channels/icons/groupme.png)](https://groupme.botframework.com/?botId=metagon) [![Kik](https://dev.botframework.com/client/images/channels/icons/kik.png)](https://bots.kik.com/#/metagon) [![Line](https://upload.wikimedia.org/wikipedia/commons/thumb/4/41/LINE_logo.svg/112px-LINE_logo.svg.png)](https://line.me/R/ti/p/d5IppPNQOK) [![MSTeams](https://dev.botframework.com/client/images/channels/icons/msteams.png)](https://teams.microsoft.com/l/chat/0/0?users=28:b02aeeb5-27a7-44a7-9e33-ba79a0a10246) [![Skype](https://dev.botframework.com/client/images/channels/icons/skype.png)](https://join.skype.com/bot/b02aeeb5-27a7-44a7-9e33-ba79a0a10246) [![Skype for Business](https://dev.botframework.com/client/images/channels/icons/skypeforbusiness.png)](https://skypeappregistration.azurewebsites.net/bot/b02aeeb5-27a7-44a7-9e33-ba79a0a10246) [![Slack](https://dev.botframework.com/client/images/channels/icons/slack.png)](https://slack.com/oauth/authorize?scope=bot&client_id=102106011378.101401841504&redirect_uri=https%3a%2f%2fslack.botframework.com%2fHome%2fauth&state=metagon) [![Telegram](https://dev.botframework.com/client/images/channels/icons/telegram.png)](https://t.me/metagon_bot) 18 | 19 | ## License 20 | BSD-3 21 | 22 | * Even the license is BSD-3, rehosting the bot publicly is not allowed. If we caught so, we will ask appriopriate authorities to take it down. Don't even try. 23 | 24 | ## Documentation 25 | [Here](https://metagon.austinhuang.me). 26 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const express = require('express'), 2 | builder = require('botbuilder'), 3 | fs = require('fs'), 4 | request = require('request').defaults({headers: {"User-Agent": "https://metagon.austinhuang.me / im@austinhuang.me"}}), 5 | bodyParser = require('body-parser'), 6 | cloudinary = require('cloudinary'), 7 | decode = require('decode-html'), 8 | connector = new builder.ChatConnector({ 9 | appId: process.env.appid, 10 | appPassword: process.env.appkey 11 | }), 12 | botbuilderMongodb = require("botbuilder-mongodb"), 13 | bot = new builder.UniversalBot(connector).set("storage", 14 | botbuilderMongodb.GetMongoDBLayer({ 15 | ip: "discoin-shard-00-00-i5e6f.mongodb.net:27017,discoin-shard-00-01-i5e6f.mongodb.net:27017,discoin-shard-00-02-i5e6f.mongodb.net", 16 | port: "27017", 17 | database: "heroku_fs0bkx2s", 18 | collection: "metagon", 19 | username: "austinhuang", 20 | password: process.env.MONGO_PASS, 21 | queryString: "heroku_fs0bkx2s?ssl=true&replicaSet=discoin-shard-0&authSource=admin&retryWrites=true&w=majority" 22 | }) 23 | ), 24 | 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"], 25 | gagsubs = ["hot", "fresh"], 26 | yoda_said = [ 27 | '"Fear is the path to the dark side. Fear leads to anger, anger leads to hate, hate leads to suffering." -- Yoda \n', 28 | '"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', 29 | '"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', 30 | '"Lost a planet, Master Obi-Wan has. How embarrassing, how embarrassing." -- Yoda\n', 31 | '"Go to the center of the gravity\'s pull, and find your planet you will." -- Yoda to Obi-Wan\n', 32 | '"Meditate on this, I will." -- Yoda\n', 33 | '"Clear, your mind must be if you are to discover the real villains behind the plot." -- Yoda to Obi-Wan\n', 34 | '"Pain. Suffering. Death, I feel. Something terrible has happened. Young Skywalker is in pain. Terrible pain." -- Yoda\n', 35 | '"Around the survivors, a perimeter create!" -- Yoda\n', 36 | '"Powerful you have become, Dooku. The dark side I sense in you." -- Yoda to Dooku\n', 37 | '"Master Obi-Wan, not victory. The shroud of the dark side has fallen. Begun, the Clone War has!" -- Yoda\n', 38 | '"Much to learn, you still have." -- Yoda to Dooku\n', 39 | '"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', 40 | '"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', 41 | '"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', 42 | '"Train yourself to let go of everything you fear to lose." -- Yoda to Anakin Skywalker\n', 43 | '"Go, I will. Good relations with the Wookiees, I have." -- Yoda\n', 44 | '"Too much under the sway of the Chancellor, he is. Much anger there is in him. Too much pride in his powers." -- Yoda\n', 45 | '"If a special session of Congress there is, easier for us to enter the Jedi Temple it will be." -- Yoda\n', 46 | '"If into the security recordings you go, only pain will you find." -- Yoda to Obi-Wan Kenobi\n', 47 | '"Destroy the Sith, we must." -- Yoda\n', 48 | '"To fight this Lord Sidious, strong enough, you are not." -- Yoda to Obi-Wan Kenobi\n', 49 | '"Twisted by the dark side, young Skywalker has become." -- Yoda to Obi-Wan Kenobi\n', 50 | '"The boy you trained, gone he is, consumed by Darth Vader." -- Yoda to Obi-Wan Kenobi\n', 51 | '"I hear a new apprentice you have, Emperor. Or should I call you Darth Sidious?" -- Yoda to Palpatine\n', 52 | '"At an end your rule is, and not short enough it was." -- Yoda to Palpatine\n', 53 | '"Not if anything to say about it, I have!" -- Yoda\n', 54 | '"Into exile I must go. Failed, I have." -- Yoda to Bail Organa\n', 55 | '"If so powerful you are, why leave?" -- Yoda\n', 56 | '"Faith in your new apprentice, misplaced may be. As is your faith in the dark side of the Force." -- Yoda\n', 57 | 'Luke: "I feel like". Yoda: "Feel like what?" -- Luke Skywalker and Yoda\n', 58 | '"Looking? Found someone you have I would say, mm?" -- Yoda\n', 59 | '"Help you I can! Yes! Mm!" -- Yoda to Luke\n', 60 | '"Awww, cannot get your ship out, heh-heheheh!" -- Yoda to Luke\n', 61 | '"How you get so big, eating food of this kind?" -- Yoda to Luke\n', 62 | '"Mine! Or I will help you not!" -- Yoda to Luke\n', 63 | '"Mudhole? Slimy? My home this is!" -- Yoda to Luke\n', 64 | '"Mine! Mine! Mine! MINE!!!" -- Yoda to R2-D2\n', 65 | '"No, no no, stay and help you I will! Hehe! Find your friend, mm?" -- Yoda to Luke\n', 66 | '"Ohhh, Jedi Master! Yoda. You seek Yoda!" -- Yoda to Luke\n', 67 | '"No! Try not. Do, or do not. There is no try." -- Yoda to Luke\n', 68 | 'Luke: "I\'m looking for a great warrior." Yoda: "Wars not make one great." -- Luke Skywalker and Yoda\n', 69 | '"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', 70 | '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', 71 | 'Luke: "I won\'t fail you. I\'m not afraid." Yoda: "You will be. You will be." -- Luke Skywalker and Yoda\n', 72 | '"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', 73 | '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', 74 | '"So certain are you. Always with you it cannot be done. Hear you nothing that I say?" -- Yoda to Luke\n', 75 | '"No! No different! Only different in your mind. You must unlearn what you have learned." -- Yoda to Luke\n', 76 | 'Luke: "I don\'t believe it"; Yoda: "That is why you fail." -- Yoda to Luke\n', 77 | '"No! Try not. Do. Or do not. There is no try." -- Yoda to Luke , \n', 78 | '"Size matters not. Look at me. Judge me by my size do you?" -- Yoda to Luke\n', 79 | '"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', 80 | '"Through the Force, things you will see. Other places. The future, the past, old friends long gone." -- Yoda to Luke\n', 81 | '"Hmm. Control, control. You must learn control." -- Yoda to Luke\n', 82 | '"Difficult to see. Always in motion is the future." -- Yoda to Luke\n', 83 | '"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', 84 | '"Strong is Vader. Mind what you have learned. Save you it can!" -- Yoda to Luke\n', 85 | '"No. There is another." -- Yoda to Obi-Wan\n', 86 | '"When nine hundred years old you reach, look as good, you will not, hm?" -- Yoda to Luke Skywalker\n', 87 | '"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', 88 | '"No more training do you require. Already know you that which you need." -- Yoda to Luke Skywalker\n', 89 | '"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', 90 | '"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', 91 | '"Your father he is." -- Yoda to Luke Skywalker\n', 92 | '"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', 93 | '"Luke, when gone am I, the last of the Jedi will you be." -- Yoda to Luke Skywalker\n', 94 | '"Luke, there is another, Skywalker." -- Yoda to Luke Skywalker\n', 95 | '"Pity your new disciple I do; so lately an apprentice, so soon without a Master." -- Yoda\n', 96 | '"War does not make one great." -- Yoda\n', 97 | '"Proud I am, to stand by Wookiees in their hour of need." -- Yoda\n', 98 | '"Yoda I am, fight I will." -- Yoda\n', 99 | '"Tired I am, rest I must." -- Yoda\n', 100 | '"When all choices seem wrong, choose restraint." -- recalled by Mace Windu\n', 101 | '"If no mistake have you made, yet losing you are, a different game you should play." -- recalled by Mace Windu\n', 102 | '"A trial of being old is this: remembering which thing one has said into which young ears." -- Yoda\n', 103 | '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', 104 | '"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', 105 | '"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', 106 | '"When you fall, apprentice, catch you I will." -- Yoda to Dooku\n', 107 | '"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', 108 | '"Honor life by living, Padawan. Killing honors only death: only the dark side." -- Yoda\n', 109 | '"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', 110 | '"When you look at the dark side, careful you must be , for the dark side looks back." -- Yoda\n', 111 | '"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', 112 | '"Humility endless is." -- Yoda\n', 113 | '"A labyrinth of evil, this war has become." -- Yoda\n', 114 | '"Sworn by oath to uphold you, we are." -- Yoda to Palpatine\n', 115 | '"From the dark path, no returning there is. Forever, the direction of your life it dominates." -- Yoda\n', 116 | '"To the Force, look for guidance. Accept what fate has placed before us." -- Yoda\n', 117 | '"Yoda, you seek?" -- Yoda\n', '"My ally is the Force" -- Yoda\n' 118 | ], 119 | parseString = require('xml2js').parseString; 120 | cloudinary.config({ 121 | cloud_name: 'metagon', 122 | api_key: process.env.cloudinary1, 123 | api_secret: process.env.cloudinary2 124 | }); 125 | var nsfw = JSON.parse(fs.readFileSync("./nsfw.json", "utf8")); 126 | 127 | //bot.connector("cisco", cisco); 128 | 129 | bot.use({ 130 | botbuilder: function (session, next) { 131 | session.error = function (err) { 132 | session.endDialog("An error occured. Please report this, along with the chat history, to \"im@austinhuang.me\".\n\n"+err); 133 | console.error(err.stack); 134 | }; 135 | next(); 136 | } 137 | }); 138 | 139 | function f2c(f) { 140 | var c = (parseInt(f) - 32) / 1.8; 141 | return c.toFixed(); 142 | } 143 | function shuffle(array) { 144 | var currentIndex = array.length, temporaryValue, randomIndex; 145 | while (0 !== currentIndex) { 146 | randomIndex = Math.floor(Math.random() * currentIndex); 147 | currentIndex -= 1; 148 | temporaryValue = array[currentIndex]; 149 | array[currentIndex] = array[randomIndex]; 150 | array[randomIndex] = temporaryValue; 151 | } 152 | return array; 153 | } 154 | 155 | bot.on('conversationUpdate', function (message) { 156 | if (message.address.conversation.isGroup) { 157 | if (message.membersAdded) { 158 | message.membersAdded.forEach(function (identity) { 159 | if (identity.id === message.address.bot.id) { 160 | var reply = new builder.Message() 161 | .address(message.address) 162 | .text("Hello everyone! This is Metagon. You can reply \"start\" to start using me! For more info, visit http://metagon.austinhuang.me."); 163 | bot.send(reply); 164 | } 165 | }); 166 | } 167 | if (message.membersRemoved) { 168 | message.membersRemoved.forEach(function (identity) { 169 | if (identity.id === message.address.bot.id) { 170 | var reply = new builder.Message() 171 | .address(message.address) 172 | .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."); 173 | bot.send(reply); 174 | } 175 | }); 176 | } 177 | } 178 | }); 179 | bot.on('contactRelationUpdate', function (message) { 180 | if (message.action === 'add') { 181 | var name = message.user ? message.user.name : null; 182 | var reply = new builder.Message() 183 | .address(message.address) 184 | .text("Hello there! This is Metagon. You can reply \"start\" to start using me! For more info, visit http://metagon.austinhuang.me."); 185 | bot.send(reply); 186 | } 187 | }); 188 | 189 | // Menus 190 | bot.dialog('/menu', [ 191 | function (session) { 192 | if (session.message.source === "groupme" || session.message.source === "skypeforbusiness" || session.message.source === "ciscospark") { 193 | session.send("Keyboard Mode is not available on GroupMe / Skype for Business. Please use only commands.\nFor more information, type \"help\"."); 194 | } 195 | else if (session.message.source !== "line" && session.message.source !== "facebook") { 196 | builder.Prompts.choice(session, "What would you like to do right now?", "Images|Utility|Fun|About|Feedback|Quit", { listStyle: 3 }); 197 | } 198 | else { 199 | var msg = new builder.Message(session); 200 | msg.attachmentLayout(builder.AttachmentLayout.carousel); 201 | msg.attachments([ 202 | new builder.HeroCard(session) 203 | .text("What would you like to do right now?") 204 | .buttons([ 205 | builder.CardAction.imBack(session, "Images", "Images"), 206 | builder.CardAction.imBack(session, "Utility", "Utility"), 207 | builder.CardAction.imBack(session, "Fun", "Fun") 208 | ]), 209 | new builder.HeroCard(session) 210 | .text("What would you like to do right now?") 211 | .buttons([ 212 | builder.CardAction.imBack(session, "About", "About"), 213 | builder.CardAction.imBack(session, "Feedback", "Feedback"), 214 | builder.CardAction.imBack(session, "Quit", "Quit") 215 | ]) 216 | ]); 217 | builder.Prompts.choice(session, msg, "Images|Utility|Fun|About|Feedback|Quit"); 218 | } 219 | }, function (session, results) { 220 | switch (results.response.entity) { 221 | case "Images": 222 | session.replaceDialog("/image"); 223 | break; 224 | case "Utility": 225 | session.replaceDialog("/utility"); 226 | break; 227 | case "Fun": 228 | session.replaceDialog("/fun"); 229 | break; 230 | case "About": 231 | session.replaceDialog("/about"); 232 | break; 233 | case "Feedback": 234 | session.replaceDialog("/feedback"); 235 | break; 236 | case "Quit": 237 | session.endDialog("You have quit the keyboard mode. You can start again by typing \"start\"."); 238 | break; 239 | } 240 | } 241 | ]).triggerAction({ matches: /^(\/|Metagon |)start/gi}); 242 | bot.dialog('/image', [ 243 | function (session) { 244 | switch (session.message.source) { 245 | case "kik": 246 | 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 }); 247 | break; 248 | case "line": 249 | case "facebook": 250 | var msg = new builder.Message(session); 251 | msg.attachmentLayout(builder.AttachmentLayout.carousel); 252 | msg.attachments([ 253 | new builder.HeroCard(session) 254 | .text("What would you like to do right now?") 255 | .buttons([ 256 | builder.CardAction.imBack(session, "Imgur", "Imgur"), 257 | builder.CardAction.imBack(session, "Flickr", "Flickr"), 258 | ]), 259 | new builder.HeroCard(session) 260 | .text("What would you like to do right now?") 261 | .buttons([ 262 | builder.CardAction.imBack(session, "DeviantArt", "DeviantArt"), 263 | builder.CardAction.imBack(session, "Anime actions", "Anime actions"), 264 | builder.CardAction.imBack(session, "Cat", "Cat") 265 | ]), 266 | new builder.HeroCard(session) 267 | .text("What would you like to do right now?") 268 | .buttons([ 269 | builder.CardAction.imBack(session, "Dog", "Dog"), 270 | builder.CardAction.imBack(session, "Snake", "Snake"), 271 | builder.CardAction.imBack(session, "Bunny", "Bunny") 272 | ]), 273 | new builder.HeroCard(session) 274 | .text("What would you like to do right now?") 275 | .buttons([ 276 | builder.CardAction.imBack(session, "Duck", "Duck"), 277 | builder.CardAction.imBack(session, "Birb", "Birb"), 278 | builder.CardAction.imBack(session, "Back to Start Menu", "Back to Start Menu"), 279 | ]) 280 | ]); 281 | builder.Prompts.choice(session, msg, "Imgur|Flickr|DeviantArt|Anime actions|Cat|Dog|Snake|Bunny|Duck|Birb|Back to Start Menu|Quit"); 282 | break; 283 | default: 284 | 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 }); 285 | break; 286 | } 287 | }, 288 | function (session, results) { 289 | switch (results.response.entity) { 290 | case "Imgur": 291 | session.replaceDialog("/imgur1"); 292 | break; 293 | case "Flickr": 294 | session.replaceDialog("/flickr1"); 295 | break; 296 | case "DeviantArt": 297 | session.replaceDialog("/deviantart1"); 298 | break; 299 | case "Anime actions": 300 | session.replaceDialog("/anime"); 301 | break; 302 | 303 | case "Back to Start Menu": 304 | session.beginDialog("/menu"); 305 | break; 306 | case "Quit": 307 | session.endDialog("You have quit the keyboard mode. You can start again by typing \"start\"."); 308 | break; 309 | default: 310 | session.replaceDialog("/"+results.response.entity.toLowerCase()); 311 | break; 312 | } 313 | } 314 | ]); 315 | bot.dialog('/utility', [ 316 | function (session) { 317 | switch (session.message.source) { 318 | case "line": 319 | case "facebook": 320 | var msg = new builder.Message(session); 321 | msg.attachmentLayout(builder.AttachmentLayout.carousel); 322 | msg.attachments([ 323 | new builder.HeroCard(session) 324 | .text("What would you like to do right now?") 325 | .buttons([ 326 | builder.CardAction.imBack(session, "Weather", "Weather"), 327 | builder.CardAction.imBack(session, "Dictionary", "Dictionary"), 328 | builder.CardAction.imBack(session, "Shorten URLs", "Shorten URLs") 329 | ]), 330 | new builder.HeroCard(session) 331 | .text("What would you like to do right now?") 332 | .buttons([ 333 | builder.CardAction.imBack(session, "Expand Bitly URLs", "Expand Bitly URLs"), 334 | builder.CardAction.imBack(session, "Minecraft User Lookup", "Minecraft User"), 335 | builder.CardAction.imBack(session, "Minecraft Server Ping", "Minecraft Server") 336 | ]), 337 | new builder.HeroCard(session) 338 | .text("What would you like to do right now?") 339 | .buttons([ 340 | builder.CardAction.imBack(session, "Pastebin", "Pastebin"), 341 | builder.CardAction.imBack(session, "Back to Start Menu", "Back to Start Menu"), 342 | builder.CardAction.imBack(session, "Quit", "Quit") 343 | ]) 344 | ]); 345 | 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 }); 346 | break; 347 | default: 348 | 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 }); 349 | break; 350 | } 351 | }, 352 | function (session, results) { 353 | switch (results.response.entity) { 354 | case "Shorten URLs": 355 | session.replaceDialog("/shorten1"); 356 | break; 357 | case "Expand Bitly URLs": 358 | session.replaceDialog("/expand1"); 359 | break; 360 | case "Minecraft User Lookup": 361 | session.replaceDialog("/mcuser1"); 362 | break; 363 | case "Minecraft Server Status": 364 | session.replaceDialog("/mcserver1"); 365 | break; 366 | case "Back to Start Menu": 367 | session.beginDialog("/menu"); 368 | break; 369 | case "Quit": 370 | session.endDialog("You have quit the keyboard mode. You can start again by typing \"start\"."); 371 | break; 372 | default: 373 | session.replaceDialog("/"+results.response.entity.toLowerCase()+"1"); 374 | break; 375 | } 376 | } 377 | ]); 378 | bot.dialog('/fun', [ 379 | function (session) { 380 | switch (session.message.source) { 381 | case "line": 382 | case "facebook": 383 | var msg = new builder.Message(session); 384 | msg.attachmentLayout(builder.AttachmentLayout.carousel); 385 | msg.attachments([ 386 | new builder.HeroCard(session) 387 | .text("What would you like to do right now?") 388 | .buttons([ 389 | builder.CardAction.imBack(session, "9gag", "9gag"), 390 | builder.CardAction.imBack(session, "Urban Dictionary", "Urban Dictionary"), 391 | builder.CardAction.imBack(session, "Cat Facts", "Cat Facts") 392 | ]), 393 | new builder.HeroCard(session) 394 | .text("What would you like to do right now?") 395 | .buttons([ 396 | builder.CardAction.imBack(session, "Trivia", "Trivia"), 397 | builder.CardAction.imBack(session, "Chuck Norris", "Chuck Norris"), 398 | builder.CardAction.imBack(session, "Yoda Quote", "Yoda Quote") 399 | ]), 400 | new builder.HeroCard(session) 401 | .text("What would you like to do right now?") 402 | .buttons([ 403 | builder.CardAction.imBack(session, "Quote on Design", "Quote on Design"), 404 | builder.CardAction.imBack(session, "Back to Start Menu", "Back to Start Menu"), 405 | builder.CardAction.imBack(session, "Quit", "Quit") 406 | ]) 407 | ]); 408 | builder.Prompts.choice(session, msg, "9gag|Urban Dictionary|Cat Facts|Trivia|Chuck Norris|Yoda Quote|Quote on Design|Back to Start Menu|Quit"); 409 | break; 410 | default: 411 | 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 }); 412 | break; 413 | } 414 | }, 415 | function (session, results) { 416 | switch (results.response.entity) { 417 | case "9gag": 418 | session.replaceDialog("/9gag1"); 419 | break; 420 | case "Urban Dictionary": 421 | session.replaceDialog("/ud1"); 422 | break; 423 | case "Chuck Norris": 424 | session.replaceDialog("/joke"); 425 | break; 426 | case "Cat Facts": 427 | session.replaceDialog("/catfact"); 428 | break; 429 | case "Trivia": 430 | session.replaceDialog("/trivia1"); 431 | break; 432 | case "Yoda Quote": 433 | session.replaceDialog("/yoda"); 434 | break; 435 | case "Quote on Design": 436 | session.replaceDialog("/design"); 437 | break; 438 | case "Back to Start Menu": 439 | session.beginDialog("/menu"); 440 | break 441 | case "Quit": 442 | session.endDialog("You have quit the keyboard mode. You can start again by typing \"start\"."); 443 | break; 444 | } 445 | } 446 | ]); 447 | 448 | bot.dialog('/about', function (session) { 449 | if (session.message.source === "kik") { 450 | 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\"."); 451 | } 452 | else if (session.message.source === "telegram") { 453 | 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\"."); 454 | } 455 | else if (session.message.source === "line") { 456 | 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\"."); 457 | } 458 | else if (session.message.source === "skype") { 459 | 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\"."); 460 | } 461 | else if (session.message.source === "slack" && session.message.address.conversation.isGroup) { 462 | session.send(); 463 | } 464 | else { 465 | 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\"."); 466 | } 467 | if (session.message.source !== "groupme" && session.message.source !== "skypeforbusiness" && session.message.source !== "ciscospark" && session.message.text !== ("/help")) { 468 | session.replaceDialog("/menu"); 469 | } 470 | else { 471 | session.endDialog(); 472 | } 473 | }).triggerAction({ matches: /^(\/|)help/i}); 474 | bot.dialog('/feedback', function (session) { 475 | session.send("https://feedback.austinhuang.me"); 476 | session.replaceDialog("/menu"); 477 | }); 478 | 479 | // Image 480 | bot.dialog('/cat', function (session) { 481 | if (session.message.source !== "line") {session.sendTyping();} 482 | request('http://aws.random.cat/meow', {json: true}, function(error, response, body) { 483 | if (!error && response.statusCode === 200) { 484 | var type = body.file.endsWith(".gif") ? "gif" : "jpeg"; 485 | session.send({ 486 | attachments: [ 487 | { 488 | contentType: "image/"+type, 489 | contentUrl: body.file, 490 | name: "cat."+type.replace("jpeg", "jpg") 491 | } 492 | ] 493 | }); 494 | if (!session.message.text.includes("/cat")) session.beginDialog("/image"); 495 | } 496 | else { 497 | session.endDialog("ERROR! I could not connect to http://aws.random.cat/meow. Please retry. If the problem persists, please contact im@austinhuang.me"); 498 | } 499 | }); 500 | }).triggerAction({ matches: /^( ||Metagon )\/cat/g}); 501 | bot.dialog('/snake', function (session) { 502 | if (session.message.source !== "line") {session.sendTyping();} 503 | request('http://fur.im/snek', {json: true}, function(error, response, body) { 504 | if (!error && response.statusCode === 200) { 505 | session.send({ 506 | attachments: [ 507 | { 508 | contentType: "image/*", 509 | contentUrl: body.file.replace("http://", "https://") 510 | } 511 | ] 512 | }); 513 | if (!session.message.text.includes("/snake")) { 514 | session.replaceDialog("/image"); 515 | } 516 | else { 517 | session.endDialog(); 518 | } 519 | } 520 | else { 521 | 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"); 522 | } 523 | }); 524 | }).triggerAction({ matches: /^( ||Metagon )\/snake/g}); 525 | bot.dialog('/dog', function (session) { 526 | if (session.message.source !== "line") {session.sendTyping();} 527 | request('https://random.dog/woof.json', function(error, response, body) { 528 | if (!error && response.statusCode === 200) { 529 | body = JSON.parse(body); 530 | if (body.url.endsWith("mp4") || body.url.endsWith("webm")) { session.send({ 531 | attachments: [ 532 | { 533 | contentType: "video/*", 534 | contentUrl: body.url 535 | } 536 | ] 537 | }); 538 | } 539 | else { session.send({ 540 | attachments: [ 541 | { 542 | contentType: "image/*", 543 | contentUrl: body.url 544 | } 545 | ] 546 | }); 547 | } 548 | if (!session.message.text.includes("/dog")) { 549 | session.replaceDialog("/image"); 550 | } 551 | else { 552 | session.endDialog(); 553 | } 554 | } 555 | else { 556 | session.endDialog("ERROR! I could not connect to https://random.dog/woof.json. Please retry. If the problem persists, please contact im@austinhuang.me"); 557 | } 558 | }); 559 | }).triggerAction({ matches: /^( ||Metagon )\/dog/g}); 560 | bot.dialog('/bunny', function (session) { 561 | if (session.message.source !== "line") {session.sendTyping();} 562 | request('https://api.bunnies.io/v2/loop/random/?media=gif,mp4', function(error, response, body) { 563 | if (!error && response.statusCode === 200 && session.message.source.includes("skype") && session.message.source.includes("kik")) { 564 | body = JSON.parse(body); 565 | session.send({ 566 | attachments: [ 567 | { 568 | contentType: "video/*", 569 | contentUrl: body.media.mp4 570 | } 571 | ] 572 | }); 573 | if (!session.message.text.includes("/bunny")) { 574 | session.replaceDialog("/image"); 575 | } 576 | else { 577 | session.endDialog(); 578 | } 579 | } 580 | else if (!error && response.statusCode === 200) { 581 | body = JSON.parse(body); 582 | session.send({ 583 | attachments: [ 584 | { 585 | contentType: "image/gif", 586 | contentUrl: body.media.gif 587 | } 588 | ] 589 | }); 590 | if (!session.message.text.includes("/bunny")) { 591 | session.replaceDialog("/image"); 592 | } 593 | else { 594 | session.endDialog(); 595 | } 596 | } 597 | else { 598 | 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"); 599 | } 600 | }); 601 | }).triggerAction({ matches: /^( ||Metagon )\/bunny/g}); 602 | bot.dialog('/birb', function (session) { 603 | if (session.message.source !== "line") {session.sendTyping();} 604 | request('https://random.birb.pw/tweet', function(error, response, body) { 605 | if (!error && response.statusCode === 200) { 606 | var type = body.endsWith(".gif") ? "gif" : "*"; 607 | session.endDialog({ 608 | attachments: [ 609 | { 610 | contentType: "image/" + type, 611 | contentUrl: "https://random.birb.pw/img/"+body 612 | } 613 | ] 614 | }); 615 | if (!session.message.text.includes("/bir")) session.beginDialog("/image"); 616 | } 617 | else { 618 | session.endDialog("ERROR! I could not connect to https://random.birb.pw/tweet. Please retry. If the problem persists, please contact im@austinhuang.me"); 619 | } 620 | }); 621 | }).triggerAction({ matches: /^( ||Metagon )\/bir(b|d)/g}); 622 | bot.dialog('/duck', function (session) { 623 | if (session.message.source !== "line") {session.sendTyping();} 624 | request('https://random-d.uk/api/v1/random', function(error, response, body) { 625 | if (!error && response.statusCode === 200) { 626 | body = JSON.parse(body); 627 | var type = body.url.endsWith(".gif") ? "gif" : "jpeg"; 628 | session.endDialog({ 629 | attachments: [ 630 | { 631 | contentType: "image/" + type, 632 | contentUrl: body.url 633 | } 634 | ] 635 | }); 636 | if (!session.message.text.includes("/duck")) session.beginDialog("/image"); 637 | } 638 | else { 639 | 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"); 640 | } 641 | }); 642 | }).triggerAction({ matches: /^( ||Metagon )\/duck/g}); 643 | 644 | bot.dialog('/anime', [ 645 | function (session) { 646 | 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 }); 647 | else { 648 | var msg = new builder.Message(session); 649 | msg.attachmentLayout(builder.AttachmentLayout.carousel); 650 | msg.attachments([ 651 | new builder.HeroCard(session) 652 | .text("What would you like to do right now?") 653 | .buttons([ 654 | builder.CardAction.imBack(session, "Kiss", "Kiss"), 655 | builder.CardAction.imBack(session, "Pat", "Pat"), 656 | builder.CardAction.imBack(session, "Hug", "Hug") 657 | ]), 658 | new builder.HeroCard(session) 659 | .text("What would you like to do right now?") 660 | .buttons([ 661 | builder.CardAction.imBack(session, "Poke", "Pole"), 662 | builder.CardAction.imBack(session, "Slap", "Slap"), 663 | builder.CardAction.imBack(session, "Cuddle", "Cuddle") 664 | ]), 665 | new builder.HeroCard(session) 666 | .text("Due to Line API restrictions, all GIFs will NOT be displayed properly.") 667 | .buttons([ 668 | builder.CardAction.imBack(session, "Feed", "Feed"), 669 | builder.CardAction.imBack(session, "Tickle", "Tickle"), 670 | builder.CardAction.imBack(session, "Back to Image Menu", "Back to Image Menu"), 671 | ]) 672 | ]); 673 | builder.Prompts.choice(session, msg, "Kiss|Pat|Hug|Feed|Poke|Slap|Cuddle|Tickle|Back to Image Menu|Quit"); 674 | } 675 | 676 | }, 677 | function (session, results) { 678 | switch (results.response.entity) { 679 | case "Back to Image Menu": 680 | session.beginDialog("/image"); 681 | break; 682 | case "Quit": 683 | session.endDialog("You have quit the keyboard mode. You can start again by typing \"start\"."); 684 | break; 685 | default: 686 | session.beginDialog("/kph"); 687 | break; 688 | } 689 | } 690 | ]); 691 | bot.dialog('/kph', function (session) { 692 | var endpoint = "hug"; 693 | if (session.message.text.search(/kiss/gi) > -1) {endpoint = "kiss";} 694 | else if (session.message.text.search(/pat/gi) > -1) {endpoint = "pat"} 695 | else if (session.message.text.search(/poke/gi) > -1) {endpoint = "poke"} 696 | else if (session.message.text.search(/slap/gi) > -1) {endpoint = "slap"} 697 | else if (session.message.text.search(/cuddle/gi) > -1) {endpoint = "cuddle"} 698 | else if (session.message.text.search(/feed/gi) > -1) {endpoint = "feed"} 699 | request('https://nekos.life/api/v2/img/'+endpoint, function(error, response, body) { 700 | if (!error && response.statusCode === 200) { 701 | body = JSON.parse(body); 702 | session.send({ 703 | attachments: [ 704 | { 705 | contentType: "image/gif", 706 | contentUrl: body.url 707 | } 708 | ] 709 | }); 710 | if (!session.message.text.includes("/")) { 711 | session.replaceDialog("/anime"); 712 | } 713 | } 714 | else { 715 | session.endDialog("ERROR! I could not connect to https://nekos.life/api. Please retry. If the problem persists, please contact im@austinhuang.me"); 716 | } 717 | }); 718 | }).triggerAction({ matches: /^( ||Metagon )\/(kiss|pat|hug|poke|slap|cuddle|feed|tickle)/g}); 719 | 720 | bot.dialog('/imgur1',[ 721 | function (session) { 722 | var msg = new builder.Message(session); 723 | msg.attachmentLayout(builder.AttachmentLayout.list); 724 | msg.attachments([ 725 | new builder.HeroCard(session) 726 | .title("Input a search query.") 727 | .subtitle("ProTip: Supports boolean operators (AND, OR, NOT) and indices (tag: user: title: ext: subreddit: album: meme:).") 728 | .buttons([ 729 | builder.CardAction.imBack(session, "Back to Image Menu", "Back to Image Menu") 730 | ]) 731 | ]); 732 | builder.Prompts.text(session, msg); 733 | }, 734 | function (session, results) { 735 | if (results.response.replace(/^Metagon /g, "") !== "Back to Image Menu") { 736 | 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) { 737 | if (!error && response.statusCode === 200) { 738 | body = JSON.parse(body); 739 | if (body.data.length === 0) { 740 | session.send("No results. Change your query?"); 741 | session.replaceDialog("/image"); 742 | } 743 | else { 744 | session.send(body.data[Math.floor(Math.random() * body.data.length)].link); 745 | session.replaceDialog("/image"); 746 | } 747 | } 748 | else { 749 | session.send("Failed to connect to http://imgur.com"); 750 | session.replaceDialog("/image"); 751 | } 752 | }); 753 | } 754 | else { 755 | session.replaceDialog("/image"); 756 | } 757 | }]); 758 | bot.dialog('/imgur2', function (session) { 759 | if (session.message.source === "kik") { 760 | session.endDialog('It seems like you\'re confused. Maybe try typing \"help\". Alternatively, type \"start\" to start the bot up.'); 761 | return; 762 | } 763 | if (session.message.text.replace("/imgur", "").replace(" ", "") !== "") { 764 | 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) { 765 | if (!error && response.statusCode === 200) { 766 | body = JSON.parse(body); 767 | if (body.data.length === 0) {session.endDialog("No results. Change your query?");} 768 | else {session.endDialog(body.data[Math.floor(Math.random() * body.data.length)].link);} 769 | } 770 | else {session.endDialog("Failed to connect to http://imgur.com");} 771 | }); 772 | } 773 | else { 774 | session.endDialog("Missing search query! Correct usage: \"/imgur (Query)\""); 775 | } 776 | }).triggerAction({ matches: /^( ||Metagon )\/imgur/g}); 777 | 778 | bot.dialog('/flickr1',[ 779 | function (session) { 780 | var msg = new builder.Message(session); 781 | msg.attachmentLayout(builder.AttachmentLayout.list); 782 | msg.attachments([ 783 | new builder.HeroCard(session) 784 | .title("Input a search query.") 785 | .buttons([ 786 | builder.CardAction.imBack(session, "Back to Image Menu", "Back to Image Menu") 787 | ]) 788 | ]); 789 | builder.Prompts.text(session, msg); 790 | }, 791 | function (session, results, next) { 792 | if (results.response.replace(/^Metagon /g, "") !== "Back to Image Menu") { 793 | if (session.message.source !== "line") {session.sendTyping();} 794 | 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) { 795 | if (!error && response.statusCode === 200) { 796 | body = JSON.parse(body); 797 | var photo = body.photos.photo[Math.floor(Math.random() * body.photos.photo.length)]; 798 | if (photo === undefined) { 799 | session.send("No results."); 800 | session.replaceDialog("/image"); 801 | return; 802 | } 803 | 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) { 804 | if (!error && response.statusCode === 200) { 805 | body = JSON.parse(body); 806 | if (!body.sizes) { 807 | 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\"."); 808 | } 809 | else { 810 | session.send({ 811 | text: photo.title, 812 | attachments: [ 813 | { 814 | contentType: "image/*", 815 | contentUrl: body.sizes.size[body.sizes.size.length - 1].source 816 | } 817 | ] 818 | }); 819 | } 820 | session.replaceDialog("/image"); 821 | } 822 | else { 823 | session.send("Failed to connect to http://flickr.com"); 824 | session.replaceDialog("/image"); 825 | } 826 | }); 827 | } 828 | else { 829 | session.send("Failed to connect to http://flickr.com"); 830 | session.replaceDialog("/image"); 831 | } 832 | }); 833 | } 834 | else { 835 | session.replaceDialog("/image"); 836 | } 837 | }]); 838 | bot.dialog('/flickr2', function (session) { 839 | if (session.message.source === "kik") { 840 | session.endDialog('It seems like you\'re confused. Maybe try typing \"help\". Alternatively, type \"start\" to start the bot up.'); 841 | return; 842 | } 843 | if (session.message.source !== "line") {session.endDialogTyping();} 844 | if (session.message.text.replace(/( |)\/flickr/, "") !== "") { 845 | 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) { 846 | if (!error && response.statusCode === 200) { 847 | body = JSON.parse(body); 848 | var photo = body.photos.photo[Math.floor(Math.random() * body.photos.photo.length)]; 849 | if (photo === undefined) { 850 | session.endDialog("No results."); 851 | return; 852 | } 853 | 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) { 854 | if (!error && response.statusCode === 200) { 855 | body = JSON.parse(body); 856 | if (!body.sizes) { 857 | 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\"."); 858 | } 859 | else { 860 | session.endDialog({ 861 | text: photo.title, 862 | attachments: [ 863 | { 864 | contentType: "image/*", 865 | contentUrl: body.sizes.size[body.sizes.size.length - 1].source 866 | } 867 | ] 868 | }); 869 | } 870 | } 871 | else {session.endDialog("Failed to connect to http://flickr.com");} 872 | }); 873 | } 874 | else {session.endDialog("Failed to connect to http://flickr.com");} 875 | }); 876 | } 877 | else { 878 | session.endDialog("Missing search query! Correct usage: \"/flickr (Query)\""); 879 | } 880 | }).triggerAction({ matches: /^( ||Metagon )\/flickr/g}); 881 | 882 | bot.dialog('/deviantart1',[ 883 | function (session) { 884 | var msg = new builder.Message(session); 885 | msg.attachmentLayout(builder.AttachmentLayout.list); 886 | msg.attachments([ 887 | new builder.HeroCard(session) 888 | .title("Input a search query.") 889 | .buttons([ 890 | builder.CardAction.imBack(session, "Back to Image Menu", "Back to Image Menu") 891 | ]) 892 | ]); 893 | builder.Prompts.text(session, msg); 894 | }, 895 | function (session, results) { 896 | if (results.response.replace(/^Metagon /g, "") !== "Back to Image Menu") { 897 | if (session.message.source !== "line") {session.sendTyping();} 898 | request("https://backend.deviantart.com/rss.xml?type=deviation&q="+results.response.replace(/^Metagon /g, ""), function(error, response, body) { 899 | if (!error && response.statusCode === 200) { 900 | parseString(body, function (err, result) { 901 | if (!result.rss.channel[0].item) { 902 | session.send("No results!"); 903 | session.replaceDialog("/image"); 904 | return; 905 | } 906 | var things = result.rss.channel[0].item.filter(r => {return r["media:content"][0]["$"].medium === "image";}); 907 | var thing = things[Math.floor(Math.random() * things.length)]; 908 | session.send({ 909 | text: thing.title[0], 910 | attachments: [ 911 | { 912 | contentType: "image/*", 913 | contentUrl: thing["media:content"][0]["$"].url 914 | } 915 | ] 916 | }); 917 | session.replaceDialog("/image"); 918 | }); 919 | } 920 | else { 921 | session.send("Failed to connect to https://backend.deviantart.com/rss.xml"); 922 | session.replaceDialog("/image"); 923 | } 924 | }); 925 | } 926 | else { 927 | session.replaceDialog("/image"); 928 | } 929 | }]); 930 | bot.dialog('/deviantart2', function (session) { 931 | if (session.message.source === "kik") { 932 | session.send('It seems like you\'re confused. Maybe try typing \"help\". Alternatively, type \"start\" to start the bot up.'); 933 | return; 934 | } 935 | if (session.message.source !== "line") {session.sendTyping();} 936 | if (session.message.text.replace(/( |)\/deviantart/, "") !== "") { 937 | request("https://backend.deviantart.com/rss.xml?type=deviation&q="+session.message.text.replace(/( |)\/deviantart/, ""), function(error, response, body) { 938 | if (!error && response.statusCode === 200) { 939 | parseString(body, function (err, result) { 940 | if (!result.rss.channel[0].item) { 941 | session.send("No results!"); 942 | session.replaceDialog("/image"); 943 | return; 944 | } 945 | var thing = result.rss.channel[0].item[Math.floor(Math.random() * result.rss.channel[0].item.length)]; 946 | session.endDialog({ 947 | text: thing.title[0], 948 | attachments: [ 949 | { 950 | contentType: "image/*", 951 | contentUrl: thing["media:content"][0]["$"].url 952 | } 953 | ] 954 | }); 955 | }); 956 | } 957 | else { 958 | console.log(body); 959 | session.endDialog("Failed to connect to https://backend.deviantart.com/rss.xml"); 960 | } 961 | }); 962 | } 963 | else { 964 | session.endDialog("Missing search query! Correct usage: \"/deviantart (Query)\""); 965 | } 966 | }).triggerAction({ matches: /^( ||Metagon )\/deviantart/g}); 967 | 968 | // Utility 969 | bot.dialog('/shorten1',[ 970 | function (session) { 971 | var msg = new builder.Message(session); 972 | msg.attachmentLayout(builder.AttachmentLayout.list); 973 | msg.attachments([ 974 | new builder.HeroCard(session) 975 | .title("Input the URL you'd like to shorten.") 976 | .subtitle("ProTip: Does not need http://") 977 | .buttons([ 978 | builder.CardAction.imBack(session, "Back to Utility Menu", "Back to Utility Menu") 979 | ]) 980 | ]); 981 | builder.Prompts.text(session, msg); 982 | }, 983 | function (session, results) { 984 | if (results.response.replace(/^Metagon /g, "").endsWith("Back to Utility Menu")) { 985 | 986 | session.replaceDialog("/utility"); 987 | return; 988 | } 989 | if (results.response.replace(/^Metagon /g, "").startsWith("<") && results.response.replace(/^Metagon /g, "").includes("|")) { 990 | var site = results.response.replace(/^Metagon /g, "").split("|")[0].replace("<", ""); 991 | } 992 | else if (results.response.replace(/^Metagon /g, "").startsWith("<")) { 993 | var site = results.response.replace(/^Metagon /g, "").replace("<", "").replace(">", "").replace(";", ""); 994 | } 995 | else { 996 | var site = results.response.replace(/^Metagon /g, ""); 997 | } 998 | if (!site.startsWith("http")) { 999 | site = "http://"+results.response.replace(/^Metagon /g, ""); 1000 | } 1001 | request("https://api-ssl.bitly.com/v4/shorten", 1002 | { 1003 | headers: {Authorization: "Bearer "+process.env.bitly_token}, 1004 | json: {long_url: site} 1005 | }, 1006 | function(error, response, body) { 1007 | if (!error && response.statusCode === 200) { 1008 | session.endDialog("Done! "+body.link); 1009 | session.replaceDialog("/utility"); 1010 | } 1011 | else { 1012 | session.endDialog("An error occured. Invalid address, or retry?"); 1013 | session.replaceDialog("/utility"); 1014 | } 1015 | }); 1016 | } 1017 | ]); 1018 | bot.dialog('/shorten2', function (session) { 1019 | if (session.message.text.replace("/shorten", "").replace(" ", "") === "") { 1020 | session.send("Missing query! /shorten (URL)") 1021 | } 1022 | if (session.message.text.replace("/shorten", "").replace(" ", "").startsWith("<") && session.message.text.replace("/shorten", "").replace(" ", "").includes("|")) { 1023 | var site = session.message.text.replace("/shorten", "").replace(" ", "").split("|")[0].replace("<", ""); 1024 | } 1025 | else if (session.message.text.replace("/shorten", "").replace(" ", "").startsWith("<")) { 1026 | var site = session.message.text.replace("/shorten", "").replace(" ", "").replace("<", "").replace(">", "").replace(";", ""); 1027 | } 1028 | else { 1029 | var site = session.message.text.replace("/shorten", "").replace(" ", ""); 1030 | } 1031 | if (!site.startsWith("http")) { 1032 | site = "http://"+session.message.text.replace("/shorten", "").replace(" ", ""); 1033 | } 1034 | request("https://api-ssl.bitly.com/v4/shorten", 1035 | { 1036 | headers: {Authorization: "Bearer "+process.env.bitly_token}, 1037 | json: {long_url: site} 1038 | }, 1039 | function(error, response, body) { 1040 | if (!error && response.statusCode === 200) { 1041 | session.endDialog("Done! "+body.link); 1042 | } 1043 | else { 1044 | session.endDialog("An error occured. Invalid address, or retry?\n\n/shorten (URL)"); 1045 | } 1046 | }); 1047 | }).triggerAction({ matches: /^( ||Metagon )\/shorten/g}); 1048 | 1049 | bot.dialog('/expand1',[ 1050 | function (session) { 1051 | var msg = new builder.Message(session); 1052 | msg.attachmentLayout(builder.AttachmentLayout.list); 1053 | msg.attachments([ 1054 | new builder.HeroCard(session) 1055 | .title("Input the URL you'd like to expand.") 1056 | .subtitle("ProTip: Does not need http://") 1057 | .buttons([ 1058 | builder.CardAction.imBack(session, "Back to Utility Menu", "Back to Utility Menu") 1059 | ]) 1060 | ]); 1061 | builder.Prompts.text(session, msg); 1062 | }, 1063 | function (session, results) { 1064 | if (results.response.replace(/^Metagon /g, "").endsWith("Back to Utility Menu")) { 1065 | 1066 | session.replaceDialog("/utility"); 1067 | return; 1068 | } 1069 | if (results.response.replace(/^Metagon /g, "").startsWith("<") && results.response.replace(/^Metagon /g, "").includes("|")) { 1070 | var site = results.response.replace(/^Metagon /g, "").split("|")[0].replace("<", ""); 1071 | } 1072 | else if (results.response.replace(/^Metagon /g, "").startsWith("<")) { 1073 | var site = results.response.replace(/^Metagon /g, "").replace("<", "").replace(">", "").replace(";", ""); 1074 | } 1075 | else { 1076 | var site = results.response.replace(/^Metagon /g, ""); 1077 | } 1078 | site = site.replace(/^http(|s):\/\//, ""); 1079 | request("https://api-ssl.bitly.com/v4/expand", 1080 | { 1081 | headers: {Authorization: "Bearer "+process.env.bitly_token}, 1082 | json: {bitlink_id: site} 1083 | }, 1084 | function(error, response, body) { 1085 | if (!error && response.statusCode === 200) { 1086 | session.endDialog("Done! "+body.long_url); 1087 | session.replaceDialog("/utility"); 1088 | } 1089 | else { 1090 | session.endDialog("An error occured. Invalid address, or retry?"); 1091 | session.replaceDialog("/utility"); 1092 | } 1093 | }); 1094 | } 1095 | ]); 1096 | bot.dialog('/expand2', function (session){ 1097 | if (session.message.text.replace("/expand", "").replace(" ", "") === "") { 1098 | session.send("Missing query! /expand (Bitly URL)") 1099 | } 1100 | if (session.message.text.replace("/expand", "").replace(" ", "").startsWith("<") && session.message.text.replace("/expand", "").replace(" ", "").includes("|")) { 1101 | var site = session.message.text.replace("/expand", "").replace(" ", "").split("|")[0].replace("<", ""); 1102 | } 1103 | else if (session.message.text.replace("/expand", "").replace(" ", "").startsWith("<")) { 1104 | var site = session.message.text.replace("/expand", "").replace(" ", "").replace("<", "").replace(">", "").replace(";", ""); 1105 | } 1106 | else { 1107 | var site = session.message.text.replace("/expand", "").replace(" ", ""); 1108 | } 1109 | site = site.replace(/^http(|s):\/\//, ""); 1110 | request("https://api-ssl.bitly.com/v4/expand", 1111 | { 1112 | headers: {Authorization: "Bearer "+process.env.bitly_token}, 1113 | json: {bitlink_id: site} 1114 | }, 1115 | function(error, response, body) { 1116 | if (!error && response.statusCode === 200) { 1117 | session.endDialog("Done! "+body.long_url); 1118 | } 1119 | else { 1120 | session.endDialog("An error occured. Invalid address, or retry?\n\n/expand (URL)"); 1121 | } 1122 | }); 1123 | 1124 | }).triggerAction({ matches: /^( ||Metagon )\/expand/g}); 1125 | 1126 | bot.dialog('/mcuser1',[ 1127 | function (session) { 1128 | var msg = new builder.Message(session); 1129 | msg.attachmentLayout(builder.AttachmentLayout.list); 1130 | msg.attachments([ 1131 | new builder.HeroCard(session) 1132 | .title("Input the username or UUID you'd like to look up.") 1133 | .buttons([ 1134 | builder.CardAction.imBack(session, "Back to Utility Menu", "Back to Utility Menu") 1135 | ]) 1136 | ]); 1137 | builder.Prompts.text(session, msg); 1138 | }, 1139 | function (session, results) { 1140 | if (results.response.replace(/^Metagon /g, "").endsWith("Back to Utility Menu")) { 1141 | session.replaceDialog("/utility"); 1142 | return; 1143 | } 1144 | let username = results.response.replace(/^Metagon /g, "").replace(/-/g, ""); 1145 | request('https://api.mojang.com/users/profiles/minecraft/' + username, {json: true}, function(error, response, body) { 1146 | if (response.statusCode === 204 && username.length !== 32) { 1147 | session.send("This is not a valid Minecraft username."); 1148 | } 1149 | else if (!error) { 1150 | username = username.length !== 32 ? body.id : username; 1151 | request("https://api.mojang.com/user/profiles/"+username+"/names", {json: true}, (e1, r1, b1) => { 1152 | let names = !e1 ? body.map(r => r.name).join(", ") : "*Not available*"; 1153 | session.send("* UUID: " + username + "\n* Name history: " + names + "\n\n== Appearance ==\n* Body: https://crafatar.com/renders/body/"+username+"\n* Skin: https://crafatar.com/skins/"+username+"\n* Cape: https://crafatar.com/cape/"+username); 1154 | }); 1155 | } 1156 | else { 1157 | session.send("An error occurred."); 1158 | } 1159 | session.replaceDialog("/utility"); 1160 | }); 1161 | } 1162 | ]); 1163 | bot.dialog('/mcuser2', function (session) { 1164 | if (session.message.text.replace("/mcuser ", "").replace(/^Metagon /g, "").replace(/-/g, "") === "") { 1165 | session.send("Missing search query! /mcuser (Username or UUID)"); 1166 | return; 1167 | } 1168 | let username = session.message.text.replace("/mcuser ", "").replace(/^Metagon /g, "").replace(/-/g, ""); 1169 | request('https://api.mojang.com/users/profiles/minecraft/' + username, {json: true}, function(error, response, body) { 1170 | if (response.statusCode === 204 && username.length !== 32) { 1171 | session.send("This is not a valid Minecraft username."); 1172 | } 1173 | else if (!error) { 1174 | username = username.length !== 32 ? body.id : username; 1175 | request("https://api.mojang.com/user/profiles/"+username+"/names", {json: true}, (e1, r1, b1) => { 1176 | let names = !e1 ? body.map(r => r.name).join(", ") : "*Not available*"; 1177 | session.send("* UUID: " + username + "\n* Name history: " + names + "\n\n== Appearance ==\n* Body: https://crafatar.com/renders/body/"+username+"\n* Skin: https://crafatar.com/skins/"+username+"\n* Cape: https://crafatar.com/cape/"+username); 1178 | }); 1179 | } 1180 | else { 1181 | session.send("An error occurred."); 1182 | } 1183 | }); 1184 | }).triggerAction({ matches: /^( ||Metagon )\/mcuser/g}); 1185 | 1186 | bot.dialog('/mcserver1',[ 1187 | function (session) { 1188 | var msg = new builder.Message(session); 1189 | msg.attachmentLayout(builder.AttachmentLayout.list); 1190 | msg.attachments([ 1191 | new builder.HeroCard(session) 1192 | .title("Input the server IP/address you'd like to look up.") 1193 | .buttons([ 1194 | builder.CardAction.imBack(session, "Back to Utility Menu", "Back to Utility Menu") 1195 | ]) 1196 | ]); 1197 | builder.Prompts.text(session, msg); 1198 | }, 1199 | function (session, results) { 1200 | if (results.response.replace(/^Metagon /g, "").endsWith("Back to Utility Menu")) { 1201 | session.replaceDialog("/utility"); 1202 | return; 1203 | } 1204 | if (session.message.source !== "line") {session.sendTyping();} 1205 | request.get('https://api.mcsrvstat.us/1/'+results.response.replace(/^Metagon /g, ""), {json: true}, function(error, response, body) { 1206 | if (!error) { 1207 | if (body.offline) { 1208 | session.send("This server seems to be offline. \n\nIP: " + (!body.ip ? "Cannot detect" : body.ip) + ", Port: " + (!body.port ? "Cannot detect" : body.port) + ", Hostname: " + (!body.hostname ? "Cannot detect" : body.hostname)); 1209 | } 1210 | else { 1211 | session.send({ 1212 | text: body.ip+":"+body.port+" ("+body.hostname+")\n* Players: "+body.players.online+"/"+body.players.max+"\n* Software: "+body.software+", Version: "+body.version+"\n* MOTD: "+body.motd.clean.join("\n\n"), 1213 | attachments: [ 1214 | { 1215 | contentType: "image/*", 1216 | contentUrl: "https://api.minetools.eu/favicon/"+results.response.replace(/^Metagon /g, "").replace(":", "/") 1217 | } 1218 | ] 1219 | }); 1220 | } 1221 | session.replaceDialog("/utility"); 1222 | } 1223 | else { 1224 | session.send("An error occurred."); 1225 | session.replaceDialog("/utility"); 1226 | } 1227 | }); 1228 | } 1229 | ]); 1230 | bot.dialog('/mcserver2', function (session) { 1231 | if (session.message.text.replace("/mcserver", "").replace(" ", "") === "") { 1232 | session.send("Missing search query! /mcserver (Hostname or IP)"); 1233 | return; 1234 | } 1235 | if (session.message.source !== "line") {session.sendTyping();} 1236 | request.get('https://api.mcsrvstat.us/1/'+session.message.text.replace(/^Metagon /g, "").replace("/mcserver ", ""), {json: true}, function(error, response, body) { 1237 | if (!error) { 1238 | if (body.offline) { 1239 | session.send("This server seems to be offline. \n\nIP: " + (!body.ip ? "Cannot detect" : body.ip) + ", Port: " + (!body.port ? "Cannot detect" : body.port) + ", Hostname: " + (!body.hostname ? "Cannot detect" : body.hostname)); 1240 | } 1241 | else { 1242 | session.send({ 1243 | text: body.ip+":"+body.port+" ("+body.hostname+")\n* Players: "+body.players.online+"/"+body.players.max+"\n* Software: "+body.software+", Version: "+body.version+"\n* MOTD: "+body.motd.clean.join("\n\n"), 1244 | attachments: [ 1245 | { 1246 | contentType: "image/*", 1247 | contentUrl: "https://api.minetools.eu/favicon/"+session.message.text.replace(/^Metagon /g, "").replace("/mcserver ", "").replace(":", "/") 1248 | } 1249 | ] 1250 | }); 1251 | } 1252 | } 1253 | else { 1254 | session.endDialog("An error occurred."); 1255 | } 1256 | }); 1257 | }).triggerAction({ matches: /^( ||Metagon )\/mcserver/g}); 1258 | 1259 | bot.dialog('/pastebin1',[ 1260 | function (session) { 1261 | var msg = new builder.Message(session); 1262 | msg.attachmentLayout(builder.AttachmentLayout.list); 1263 | msg.attachments([ 1264 | new builder.HeroCard(session) 1265 | .title("Input the content you'd like to paste.") 1266 | .buttons([ 1267 | builder.CardAction.imBack(session, "Back to Utility Menu", "Back to Utility Menu") 1268 | ]) 1269 | ]); 1270 | builder.Prompts.text(session, msg); 1271 | }, 1272 | function (session, results) { 1273 | if (results.response.replace(/^Metagon /g, "").endsWith("Back to Utility Menu")) { 1274 | session.replaceDialog("/utility"); 1275 | return; 1276 | } 1277 | request.post('https://pastebin.com/api/api_post.php', {form: {api_dev_key: process.env.pastebin, api_option: "paste", api_paste_code: results.response.replace(/^Metagon /g, "")}}, function(error, response, body) { 1278 | if (!error && response.statusCode === 200) { 1279 | session.send("Done! "+body); 1280 | session.replaceDialog("/utility"); 1281 | } 1282 | else { 1283 | session.send("An error occurred."); 1284 | session.replaceDialog("/utility"); 1285 | } 1286 | }); 1287 | } 1288 | ]); 1289 | bot.dialog('/pastebin2', function (session) { 1290 | if (session.message.text.replace("/mcserver", "").replace(" ", "") === "") { 1291 | session.send("Nothing to paste! /paste (Stuff)"); 1292 | return; 1293 | } 1294 | request.post('https://pastebin.com/api/api_post.php', {form: {api_dev_key: process.env.pastebin, api_option: "paste", api_paste_code: session.message.text.substring(7).replace(" ", "")}}, function(error, response, body) { 1295 | if (!error && response.statusCode === 200) { 1296 | session.endDialog("Done! "+body); 1297 | } 1298 | else { 1299 | session.endDialog("An error occurred."); 1300 | } 1301 | }); 1302 | }).triggerAction({ matches: /^( ||Metagon )\/paste/g}); 1303 | 1304 | bot.dialog('/dictionary1', [ 1305 | function (session) { 1306 | var msg = new builder.Message(session); 1307 | msg.attachmentLayout(builder.AttachmentLayout.list); 1308 | msg.attachments([ 1309 | new builder.HeroCard(session) 1310 | .title("Input the word you'd like to look up.") 1311 | .buttons([ 1312 | builder.CardAction.imBack(session, "Back to Utility Menu", "Back to Utility Menu") 1313 | ]) 1314 | ]); 1315 | builder.Prompts.text(session, msg); 1316 | }, function (session, results) { 1317 | session.replaceDialog("/dictionary2"); 1318 | } 1319 | ]); 1320 | bot.dialog('/dictionary2', function (session) { 1321 | if (session.message.text.replace("/dictionary ", "").trim() === "") { 1322 | session.send("Nothing to look up! /dictionary (Stuff)"); 1323 | return; 1324 | } 1325 | else if (session.message.text.includes("Back to Utility Menu")) { 1326 | session.replaceDialog("/utility"); 1327 | return; 1328 | } 1329 | let headword = session.message.text.replace(/^((Metagon | |)\/dictionary |Metagon )/g, "").toLowerCase(); 1330 | request("http://api.pearson.com/v2/dictionaries/ldoce5/entries?headword="+headword, {json: true}, function(error, response, body) { 1331 | if (!error && body.results.length === 0) { 1332 | session.send("No results! Is this a word?") 1333 | } 1334 | else if (!error) { 1335 | let defs = body.results.filter(e => {return e.headword === headword && e.senses[0].definition !== undefined;}); 1336 | session.send(defs.length !== 0 1337 | ? defs.map(r => "* " + r.headword + ": " + r.senses[0].definition).join("\n\n") 1338 | : "No results for this exact word. Did you mean any of the following?\n" + body.results.filter(r => {return !r.homnum || r.homnum === 1}).map(r => r.headword).slice(0, 3).join(", ") 1339 | ); 1340 | } 1341 | else { 1342 | session.send("An error occurred."); 1343 | } 1344 | if (!session.message.text.match(/^(Metagon | |)\/dictionary/g)) session.replaceDialog("/utility"); 1345 | else session.endDialog(); 1346 | }); 1347 | }).triggerAction({ matches: /^( ||Metagon )\/dictionary/g}); 1348 | 1349 | bot.dialog('/weather1',[ 1350 | function (session) { 1351 | var msg = new builder.Message(session); 1352 | msg.attachmentLayout(builder.AttachmentLayout.list); 1353 | msg.attachments([ 1354 | new builder.HeroCard(session) 1355 | .title("Enter the name of the city to check.") 1356 | .buttons([ 1357 | builder.CardAction.imBack(session, "Back to Utility Menu", "Back to Utility Menu") 1358 | ]) 1359 | ]); 1360 | builder.Prompts.text(session, msg); 1361 | }, 1362 | function (session, results) { 1363 | if (results.response.replace(/^Metagon /g, "").endsWith("Back to Utility Menu")) { 1364 | session.replaceDialog("/utility"); 1365 | return; 1366 | } 1367 | request('https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22'+results.response.replace(/^Metagon /g, "")+'%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys', {json: true}, function(error, response, body) { 1368 | if (!error && response.statusCode === 200) { 1369 | var weather = body.query.results.channel.item; 1370 | session.send(weather.title+"\n\n== Condition ==\n\n"+weather.condition.text+", "+weather.condition.temp+"ºF ("+f2c(weather.condition.temp)+"ºC)\n\n== Forecast ==\n\n* Today: "+weather.forecast[0].text+", "+weather.forecast[0].low+"ºF ("+f2c(weather.forecast[0].low)+"ºC) ~ "+weather.forecast[0].high+"ºF ("+f2c(weather.forecast[0].high)+"ºC)\n* Tomorrow: "+weather.forecast[1].text+", "+weather.forecast[1].low+"ºF ("+f2c(weather.forecast[1].low)+"ºC) ~ "+weather.forecast[1].high+"ºF ("+f2c(weather.forecast[1].high)+"ºC)\n* "+weather.forecast[2].day+": "+weather.forecast[2].text+", "+weather.forecast[2].low+"ºF ("+f2c(weather.forecast[2].low)+"ºC) ~ "+weather.forecast[2].high+"ºF ("+f2c(weather.forecast[2].high)+"ºC)\n== Misc ==\n\n* Sunrise: "+body.query.results.channel.astronomy.sunrise+", Sunset: "+body.query.results.channel.astronomy.sunset); 1371 | session.replaceDialog("/utility"); 1372 | } 1373 | else { 1374 | session.send("An error occurred."); 1375 | session.replaceDialog("/utility"); 1376 | } 1377 | }); 1378 | } 1379 | ]); 1380 | bot.dialog('/weather2', function (session) { 1381 | request('https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22'+session.message.text.replace("/weather", "").replace(" ", "")+'%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys', {json: true}, function(error, response, body) { 1382 | if (!error && response.statusCode === 200) { 1383 | var weather = body.query.results.channel.item; 1384 | session.endDialog(weather.title+"\n\n== Condition ==\n\n"+weather.condition.text+", "+weather.condition.temp+"ºF ("+f2c(weather.condition.temp)+"ºC)\n\n== Forecast ==\n\n* Today: "+weather.forecast[0].text+", "+weather.forecast[0].low+"ºF ("+f2c(weather.forecast[0].low)+"ºC) ~ "+weather.forecast[0].high+"ºF ("+f2c(weather.forecast[0].high)+"ºC)\n* Tomorrow: "+weather.forecast[1].text+", "+weather.forecast[1].low+"ºF ("+f2c(weather.forecast[1].low)+"ºC) ~ "+weather.forecast[1].high+"ºF ("+f2c(weather.forecast[1].high)+"ºC)\n* "+weather.forecast[2].day+": "+weather.forecast[2].text+", "+weather.forecast[2].low+"ºF ("+f2c(weather.forecast[2].low)+"ºC) ~ "+weather.forecast[2].high+"ºF ("+f2c(weather.forecast[2].high)+"ºC)\n== Misc ==\n\n* Sunrise: "+body.query.results.channel.astronomy.sunrise+", Sunset: "+body.query.results.channel.astronomy.sunset); 1385 | } 1386 | else { 1387 | session.endDialog("An error occurred."); 1388 | } 1389 | }); 1390 | }).triggerAction({ matches: /^( ||Metagon )\/weather/g}); 1391 | 1392 | // Fun 1393 | bot.dialog('/ud1',[ 1394 | function (session) { 1395 | var msg = new builder.Message(session); 1396 | msg.attachmentLayout(builder.AttachmentLayout.list); 1397 | msg.attachments([ 1398 | new builder.HeroCard(session) 1399 | .title("Type the word you'd like to search for.") 1400 | .buttons([ 1401 | builder.CardAction.imBack(session, "Back to Fun Menu", "Back to Fun Menu") 1402 | ]) 1403 | ]); 1404 | builder.Prompts.text(session, msg); 1405 | }, 1406 | function (session, results) { 1407 | if (results.response.replace(/^Metagon /g, "").endsWith("Back to Fun Menu")) { 1408 | session.replaceDialog("/fun"); 1409 | return; 1410 | } 1411 | request('http://api.urbandictionary.com/v0/define?term='+results.response.replace(/^Metagon /g, ""), {json: true}, function(error, response, body) { 1412 | if (!error && response.statusCode === 200 && body.list.length !== 0) { 1413 | session.send("Top UD result for "+results.response.replace(/^Metagon /g, "")+"\n\n== Definition ==\n\n"+body.list[0].definition+"\n\n == Example ==\n\n"+body.list[0].example+"\n\n* "+body.list[0].thumbs_up+"\uD83D\uDC4D / "+body.list[0].thumbs_down+"\uD83D\uDC4E"); 1414 | session.replaceDialog("/fun"); 1415 | } 1416 | else if (!error && response.statusCode === 200) { 1417 | session.send("No results!"); 1418 | session.replaceDialog("/fun"); 1419 | } 1420 | else { 1421 | session.send("An error occurred."); 1422 | session.replaceDialog("/fun"); 1423 | } 1424 | }); 1425 | } 1426 | ]); 1427 | bot.dialog('/ud2', function (session) { 1428 | request('http://api.urbandictionary.com/v0/define?term='+session.message.text.replace("/ud", "").replace(" ", ""), {json: true}, function(error, response, body) { 1429 | if (!error && response.statusCode === 200 && body.list.length !== 0) { 1430 | session.endDialog("Top UD result for "+session.message.text.replace("/ud", "").replace(" ", "")+"\n\n== Definition ==\n\n"+body.list[0].definition+"\n\n == Example ==\n\n"+body.list[0].example+"\n\n* "+body.list[0].thumbs_up+"\uD83D\uDC4D / "+body.list[0].thumbs_down+"\uD83D\uDC4E"); 1431 | } 1432 | else if (!error && response.statusCode === 200) { 1433 | session.endDialog("No results!"); 1434 | } 1435 | else { 1436 | session.endDialog("An error occurred."); 1437 | } 1438 | }); 1439 | }).triggerAction({ matches: /^( ||Metagon )\/ud/g}); 1440 | 1441 | bot.dialog('/joke', function (session) { 1442 | if (session.message.source === "kik") { 1443 | request('http://api.icndb.com/jokes/random?escape=javascript?exclude=[explicit]', function(error, response, body) { 1444 | if (!error && response.statusCode === 200) { 1445 | body = JSON.parse(body); 1446 | session.send(body.value.joke); 1447 | if (!session.message.text.includes("/")) session.replaceDialog("/fun"); 1448 | } 1449 | else { 1450 | session.send("ERROR! I could not connect to http://api.icndb.com/jokes/random. Please retry. If the problem persists, please contact im@austinhuang.me"); 1451 | } 1452 | }); 1453 | } 1454 | else { 1455 | request('http://api.icndb.com/jokes/random?escape=javascript', function(error, response, body) { 1456 | if (!error && response.statusCode === 200) { 1457 | body = JSON.parse(body); 1458 | session.send(body.value.joke); 1459 | if (!session.message.text.includes("/")) session.replaceDialog("/fun"); 1460 | } 1461 | else { 1462 | session.endDialog("ERROR! I could not connect to http://api.icndb.com/jokes/random. Please retry. If the problem persists, please contact im@austinhuang.me"); 1463 | } 1464 | }); 1465 | } 1466 | }).triggerAction({ matches: /^( ||Metagon )\/joke/g}); 1467 | bot.dialog('/yoda', function (session) { 1468 | session.send(yoda_said[Math.floor(Math.random() * yoda_said.length)]); 1469 | if (!session.message.text.includes("/")) session.replaceDialog("/fun"); 1470 | }).triggerAction({ matches: /^( ||Metagon )\/yoda/g}); 1471 | bot.dialog('/design', function (session) { 1472 | request('https://quotesondesign.com/wp-json/wp/v2/posts?orderby=rand&posts_per_page=1', function(error, response, body) { 1473 | if (!error && response.statusCode === 200) { 1474 | body = JSON.parse(body); 1475 | session.send(body[0].content.rendered.replace("

", "").replace("

", "")+"\n--- "+body[0].title.rendered); 1476 | if (!session.message.text.includes("/")) session.replaceDialog("/fun"); 1477 | } 1478 | else { 1479 | session.endDialog("ERROR! I could not connect to https://quotesondesign.com/wp-json/wp/v2/posts. Please retry. If the problem persists, please contact im@austinhuang.me"); 1480 | } 1481 | }); 1482 | }).triggerAction({ matches: /^( ||Metagon )\/design/g}); 1483 | bot.dialog('/catfact', function (session) { 1484 | request('https://catfact.ninja/fact', function(error, response, body) { 1485 | if (!error && response.statusCode === 200) { 1486 | body = JSON.parse(body); 1487 | session.send(body.fact); 1488 | if (!session.message.text.includes("/")) session.replaceDialog("/fun"); 1489 | } 1490 | else { 1491 | session.endDialog("ERROR! I could not connect to http://catfact.ninja/fact. Please retry. If the problem persists, please contact im@austinhuang.me"); 1492 | } 1493 | }); 1494 | }).triggerAction({ matches: /^( ||Metagon )\/catfact/g}); 1495 | 1496 | bot.dialog('/trivia1', [ 1497 | function(session) { 1498 | request("https://opentdb.com/api.php?amount=1", (error, response, body) => { 1499 | if (!error && response.statusCode === 200) { 1500 | body = JSON.parse(body); 1501 | nsfw.push({user: session.message.address.user.id, answer: decode(body.results[0].correct_answer.replace("&‌#039;", "'").replace("π", "π"))}); 1502 | if (body.results[0].type === "multiple") { 1503 | var choices = body.results[0].incorrect_answers; 1504 | choices.push(body.results[0].correct_answer); 1505 | builder.Prompts.choice(session, "Category: "+body.results[0].category+"\n\n"+decode(body.results[0].question.replace("&‌#039;", "'").replace("π", "π")), decode(shuffle(choices).map(c => c.replace("&‌#039;", "'").replace("π", "π")).join("|")), {listStyle: 3}); 1506 | } 1507 | else if (body.results[0].type === "boolean") builder.Prompts.confirm(session, "Category: "+body.results[0].category+"\n\n"+decode(body.results[0].question), {listStyle: 3}); 1508 | } 1509 | else { 1510 | session.endDialog("ERROR! I could not connect to https://opentdb.com/api.php. Please retry. If the problem persists, please contact im@austinhuang.me"); 1511 | } 1512 | }); 1513 | }, 1514 | function(session, results) { 1515 | var game = results.response.entity === nsfw.find(r => r.user === session.message.address.user.id).answer ? "You're right!" : "Oops... The answer is "+nsfw.find(r => r.user === session.message.address.user.id).answer+"."; 1516 | if (typeof results.response === "boolean") game = results.response.toString() === nsfw.find(r => r.user === session.message.address.user.id).answer.toLowerCase() ? "You're right!" : "Oops... The answer is "+nsfw.find(r => r.user === session.message.address.user.id).answer+"."; 1517 | var msg = new builder.Message(session); 1518 | msg.attachmentLayout(builder.AttachmentLayout.carousel); 1519 | msg.attachments([ 1520 | new builder.HeroCard(session) 1521 | .text(game+" Wanna play again?") 1522 | .buttons([ 1523 | builder.CardAction.imBack(session, "Yes", "Yes"), 1524 | builder.CardAction.imBack(session, "No", "No") 1525 | ]) 1526 | ]); 1527 | 1528 | builder.Prompts.confirm(session, session.message.source === "line" ? msg : (game+" Wanna play again?"), {listStyle: 3}); 1529 | setTimeout(() => nsfw.splice(nsfw.indexOf(nsfw.find(r => r.user === session.message.address.user.id)), 1), 100); 1530 | }, 1531 | function(session, results) { 1532 | if (results.response === true) session.reset("/trivia1"); 1533 | else session.replaceDialog("/fun"); 1534 | } 1535 | ]); 1536 | bot.dialog('/trivia2', function (session) { 1537 | request("https://opentdb.com/api.php?amount=1", (error, response, body) => { 1538 | if (!error && response.statusCode === 200) { 1539 | body = JSON.parse(body); 1540 | session.endDialog("Category: "+body.results[0].category+"\n\n"+body.results[0].question.replace("&‌#039;", "'").replace("π", "π")+"\n\nAnswer: "+body.results[0].correct_answer.replace("&‌#039;", "'").replace("π", "π")); 1541 | } 1542 | else { 1543 | session.endDialog("ERROR! I could not connect to https://opentdb.com/api.php. Please retry. If the problem persists, please contact im@austinhuang.me"); 1544 | } 1545 | }); 1546 | }).triggerAction({ matches: /^( ||Metagon )\/trivia/g}); 1547 | 1548 | bot.dialog('/9gag1',[ 1549 | function (session) { 1550 | if (session.message.source === "line" || session.message.source === "facebook") { 1551 | var msg = new builder.Message(session); 1552 | msg.attachmentLayout(builder.AttachmentLayout.carousel); 1553 | msg.attachments([ 1554 | new builder.HeroCard(session) 1555 | .text("Select a section to visit, or \"Search\" to search for posts.") 1556 | .buttons([ 1557 | builder.CardAction.imBack(session, "Search", "Search"), 1558 | builder.CardAction.imBack(session, "cute", "Animals"), 1559 | builder.CardAction.imBack(session, "anime-manga", "Anime & Manga") 1560 | ]), 1561 | new builder.HeroCard(session) 1562 | .text("Due to Line's API limitations, not all sections are shown.") 1563 | .buttons([ 1564 | builder.CardAction.imBack(session, "ask9gag", "Ask 9GAG"), 1565 | builder.CardAction.imBack(session, "awesome", "Awesome"), 1566 | builder.CardAction.imBack(session, "car", "Car") 1567 | ]), 1568 | new builder.HeroCard(session) 1569 | .text("However, the correct code of hidden sections will still work.") 1570 | .buttons([ 1571 | builder.CardAction.imBack(session, "comic", "Comic"), 1572 | builder.CardAction.imBack(session, "country", "Country"), 1573 | builder.CardAction.imBack(session, "food", "Food") 1574 | ]), 1575 | new builder.HeroCard(session) 1576 | .text("Here are the hidden sections: Type \"crafts\" for Crafts,") 1577 | .buttons([ 1578 | builder.CardAction.imBack(session, "funny", "Funny"), 1579 | builder.CardAction.imBack(session, "gaming", "Gaming"), 1580 | builder.CardAction.imBack(session, "gif", "GIF") 1581 | ]), 1582 | new builder.HeroCard(session) 1583 | .text("\"horror\" for Horror, \"overwatch\" for Overwatch,") 1584 | .buttons([ 1585 | builder.CardAction.imBack(session, "girl", "Girl"), 1586 | builder.CardAction.imBack(session, "girly", "Girly Things"), 1587 | builder.CardAction.imBack(session, "got", "Game of Thrones") 1588 | ]), 1589 | new builder.HeroCard(session) 1590 | .text("\"nsfw\" for NFK-Not for Kids, \"pcmr\" for PC Master Race,") 1591 | .buttons([ 1592 | builder.CardAction.imBack(session, "history", "Historical Images"), 1593 | builder.CardAction.imBack(session, "imadedis", "I Made Dis"), 1594 | builder.CardAction.imBack(session, "movie-tv", "Movie & TV") 1595 | ]), 1596 | new builder.HeroCard(session) 1597 | .text("\"darkhumor\" for Dark Humor, \"wallpaper\" for Wallpaper,") 1598 | .buttons([ 1599 | builder.CardAction.imBack(session, "music", "Music"), 1600 | builder.CardAction.imBack(session, "politics", "Politics"), 1601 | builder.CardAction.imBack(session, "relationship", "Relationship") 1602 | ]), 1603 | new builder.HeroCard(session) 1604 | .text("\"starwars\" for Star Wars, \"travel\" for Travel,") 1605 | .buttons([ 1606 | builder.CardAction.imBack(session, "satisfying", "Satisfying"), 1607 | builder.CardAction.imBack(session, "savage", "Savage"), 1608 | builder.CardAction.imBack(session, "school", "School") 1609 | ]), 1610 | new builder.HeroCard(session) 1611 | .text("\"surrealmemes\" for Surreal Memes,") 1612 | .buttons([ 1613 | builder.CardAction.imBack(session, "science", "Sci-Tech"), 1614 | builder.CardAction.imBack(session, "sport", "Sport"), 1615 | builder.CardAction.imBack(session, "timely", "Timely") 1616 | ]), 1617 | new builder.HeroCard(session) 1618 | .text("And \"classicalartmemes\" for Classical Art Memes.") 1619 | .buttons([ 1620 | builder.CardAction.imBack(session, "video", "Video"), 1621 | builder.CardAction.imBack(session, "wtf", "WTF"), 1622 | builder.CardAction.imBack(session, "Back to Fun Menu", "Back to Fun Menu") 1623 | ]) 1624 | ]); 1625 | builder.Prompts.choice(session, msg, "Search|"+gagbrds.join("|")+"|Back to Fun Menu", { listStyle: 0 }); 1626 | } 1627 | else builder.Prompts.choice(session, "Select a section to visit, or \"Search\" to search for posts.\n\n* \"got\" = Game of Thrones\n* \"imadedis\" = I made dis\n* \"pcmr\" = PC Master Race", "Search|"+gagbrds.join("|")+"|Back to Fun Menu", { listStyle: 3 }); 1628 | }, 1629 | function (session, results) { 1630 | if (results.response.entity.endsWith("Back to Fun Menu")) { 1631 | session.replaceDialog("/fun"); 1632 | } 1633 | else if (results.response.entity.endsWith("nsfw") && session.message.source === "kik") { 1634 | session.send("Function unavailable due to Kik regulations. Visit https://metagon.austinhuang.me/kik-disabled for details."); 1635 | session.replaceDialog("/fun"); 1636 | return; 1637 | } 1638 | else if (results.response.entity.endsWith("Search")) { 1639 | nsfw.push({user: session.message.address.user.id, gag: "search"}); 1640 | var msg = new builder.Message(session); 1641 | msg.attachmentLayout(builder.AttachmentLayout.list); 1642 | msg.attachments([ 1643 | new builder.HeroCard(session) 1644 | .title("Input a search query.") 1645 | .buttons([ 1646 | builder.CardAction.imBack(session, "Back to Fun Menu", "Back to Fun Menu") 1647 | ]) 1648 | ]); 1649 | builder.Prompts.text(session, msg); 1650 | } 1651 | else if (gagbrds.indexOf(results.response.entity) > -1) { 1652 | nsfw.push({user: session.message.address.user.id, gag: results.response.entity}); 1653 | builder.Prompts.choice(session, "Select a subsection to visit.", "Hot|Fresh", { listStyle: 3 }); 1654 | } 1655 | }, 1656 | function (session, results) { 1657 | if (nsfw.find(i => {return i.user === session.message.address.user.id;}).gag === "search") { 1658 | request("https://9gag.com/search?query="+results.response.replace(/^Metagon /g, ""), function(err, response, body) { 1659 | var res = JSON.parse(body.split("\n\n\n\n