diff --git a/CHANGELOG.md b/CHANGELOG.md index 89467c2..69045de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Release Version 1.2 +- Added YouTube search command - Fixed reconnection starting duplicate timers - Added system to prevent MOTD from chosing the same daily result consecutively - Added support for MOTDs matching only the date diff --git a/Onequestionmark.hx b/Onequestionmark.hx index 6f18d85..3d2147a 100644 --- a/Onequestionmark.hx +++ b/Onequestionmark.hx @@ -1,6 +1,7 @@ import hxdiscord.DiscordClient; import hxdiscord.types.*; import hxdiscord.endpoints.Endpoints; +import htmlparser.HtmlDocument; import haxe.Timer; import haxe.Json; import sys.io.File; @@ -220,6 +221,8 @@ class Onequestionmark { if (msg.length != 0) {m.reply({content:'*onequestionmark slaps ${msg} around a bit with a large trout*'}, false);} case "tufac": m.reply({content:"*Not Teh Face, but better,*\n*Tufac to the letter!*\n*Always two faces, never one,*\n*Tufac has you on the run!*"}, false); + case "youtube": + if (msg.length > 0) {ytlookup(m,msg);} // Gaming functions case "coin": if ((msg.length == 0) || (Std.parseInt(msg) == null) || (Std.parseInt(msg) == 1)) { @@ -435,7 +438,6 @@ class Onequestionmark { special = false; } - //if (day.length > 0) {msg = day[randInt(0, day.length-1)];} if (day.length > 0) { if (update && !special && (day.length > 2)) { var today = Date.now().getDay(); @@ -456,6 +458,55 @@ class Onequestionmark { } + /** + * This function performs a YouTube search and replies with the first result. + * @param m The message data. + * @param query The string to search. + */ + public static function ytlookup(m:Message,query:String) { + var http = new haxe.Http('https://www.youtube.com/results?search_query=${query}'); + + http.onData = function (request) { + var data = new HtmlDocument(request); + var search = data.find("script"); // YouTube obfuscates everything into JS garbage so we have to check every