Last active
March 4, 2016 03:25
-
-
Save vihanb/21f15a5118fa52e0f05a to your computer and use it in GitHub Desktop.
respond with lmgtfy link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Chatbot Plugin | |
function _toConsumableArray(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var Talk=function(t){document.getElementById("input").value=t,document.getElementById("sayit-button").click()},Data=function(t,e){return t.replace(/\$([A-Za-z$_]+[A-Za-z$_0-9]*)/g,function(t,n){return e[n]})},Chatbot=function t(e,n,a){void 0===e&&(e="a Chatbot");var r=this,u=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],s=u.Startup,o=void 0===s?"Hi my name is $Name!":s,i=u.UID,l=void 0===i?0:i;_classCallCheck(this,t),this.Name=e,this.Options={Startup:Data(o,this),UID:l},this.onmessage=a||function(){return void 0},this.Queue=[];var c=Symbol("Called");this[c]=new Set,Talk(this.Options.Startup),setInterval(function(){[].concat(_toConsumableArray(document.getElementsByClassName("message"))).filter(function(t,e,n){return r[c].has(t)?!1:(r[c].add(t),(t.parentElement.parentElement.className.match(/user-(\d+)/)||[0,l])[1]!=l&&e>n.map(function(t){return t.textContent.trim()}).lastIndexOf(r.Options.Startup))}).forEach(function(t){return r.onmessage.call({Text:t.textContent.trim(),HTML:t.innerHTML,Raw:t,User:t.parentElement.parentElement.getElementsByClassName("username")[0].textContent.trim(),Mentions:[].concat(_toConsumableArray(t.querySelectorAll(".mention"))).map(function(t){return(t.textContext||"").slice(1)}),Speak:function(t){return r.Queue.push(t)},Reply:function(e){return r.Queue.push(":"+t.id.split("-")[1]+" "+e)},"super":r})})},2100),setInterval(function(){r.Queue[0]&&Talk(r.Queue.shift())},2500)}; | |
new Chatbot("LMGTFY", { UID: CHAT.CURRENT_USER_ID }, function() { | |
var question = /^(?:.*\.)*\s*([^?]*\?)/.exec(this.Text) || []; | |
if (question[1]) this.Reply("http://lmgtfy.com/?q=" + encodeURIComponent(question[1])) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment