-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
1 lines (1 loc) · 3.1 KB
/
server.js
1
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){const n=r(1),o=n(),a=(r(2),r(3),r(4),r(5)),s=r(6),c=(r(7),r(8),r(9),r(10));const i=e=>{try{return e=(e=(e=(e=(e=(e=(e=(e=(e=e.text["*"]).replace(/\n/g,"").replace(/\r/g,"")).replace(/<table(.*?)<\/table>/g,"")).replace(/\n/g,"").replace(/\r/g,"")).replace(/<p class="mw-empty(.*?)<\/p>/g,"")).match(/<p>(.+?)<\/p>/)[0]).replace(/<sup id="cite_ref(.*?)<\/sup>/g,"")).replace(/<[^>]+>/g," ")).replace(/#(.*?);/g,"")}catch(e){a.speak("Sorry, but that information could not be found.")}};e.exports=class{constructor(...e){e.length&&(this.commands=e[0].concat([{commands:["who is"],onMatch:(e,t)=>{s.page.data(t.replace("who is a ","").replace("who is ","").replace("who are ","").replace("whos ","").replace(/ /g,"_"),{content:!0},e=>{a.speak(i(e))})}},{commands:["what is"],onMatch:(e,t)=>{s.page.data(t.replace("what is a ","").replace("what is ","").replace("what are ","").replace("whats ","").replace(/ /g,"_"),{content:!0},e=>{a.speak(i(e))})}},{commands:["calculator"],onMatch:(e,t)=>{a.speak("equals "+c.toWords(t))}}]),this.options=Object.assign({url:"/",base:"/",port:"8025"},e[1]?e[1]:{}),this.commands.length&&this.init())}init(){o.use(n.json()),o.get(this.options.url,(e,t,r)=>{t.header("Access-Control-Allow-Origin","*"),t.header("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Accept");let n=t.req.query.task,o=t.req.query.data;if("say"===n)return void a.speak(o,null,null,()=>{t.send(),r()});let s=!1,c=[],i=[];Object.keys(this.commands).map(e=>{c=this.commands[e],i=c.commands,!0!==s&&(Object.keys(i).map(e=>{!0!==s&&-1!==n.indexOf(i[e])&&("function"==typeof c.onMatch&&(a.stop(),c.onMatch(t.req.query.task,t.req.query.data)),s=!0)}),!1===s&&t.send())})}),o.listen(this.options.port,()=>{console.log("Alex server now running at localhost:8025.")})}}},function(e,t){e.exports=require("express")},function(e,t){e.exports=require("fs")},function(e,t){e.exports=require("opn")},function(e,t){e.exports=require("path")},function(e,t){e.exports=require("say")},function(e,t){e.exports=require("node-wikipedia")},function(e,t){e.exports=require("recursive-readdir")},function(e,t){e.exports=require("child_process")},function(e,t){e.exports=require("find-in-files")},function(e,t){e.exports=require("number-to-words")}]);