diff --git a/Onequestionmark.hx b/Onequestionmark.hx index 3d2147a..92f9f28 100644 --- a/Onequestionmark.hx +++ b/Onequestionmark.hx @@ -71,6 +71,9 @@ class Onequestionmark { Sys.println('[${timestamp()}] Did not find echobox-db.json, generating'); File.saveContent("echobox-db.json", Json.stringify(echoboxDB, "\t")); } + if (!FileSystem.exists("export")) { + FileSystem.createDirectory("export"); + } saveSystem(); @@ -223,6 +226,16 @@ class Onequestionmark { 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);} + case "ytdebug": + if (FileSystem.exists("export/ytlookup_result.txt")) { + var debugRename = 'export/${datestamp()}_${StringTools.lpad(Std.string(Date.now().getHours()), "0", 2)}-${StringTools.lpad(Std.string(Date.now().getMinutes()), "0", 2)}-${StringTools.lpad(Std.string(Date.now().getSeconds()), "0", 2)}_ytdebug.txt'; + FileSystem.rename("export/ytlookup_result.txt", debugRename); + Sys.println('[${timestamp()}] ytdebug: Created debug file ${debugRename}'); + m.react('✅'); + } else { + Sys.println('[${timestamp()}] ytdebug: No result to debug'); + m.reply({content:"ytdebug: No result to debug"}, false); + } // Gaming functions case "coin": if ((msg.length == 0) || (Std.parseInt(msg) == null) || (Std.parseInt(msg) == 1)) { @@ -464,9 +477,11 @@ class Onequestionmark { * @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}'); + var http = new haxe.Http('https://www.youtube.com/results?search_query=${query.urlEncode()}'); + Sys.println('[${timestamp()}] ytlookup: URL - https://www.youtube.com/results?search_query=${query.urlEncode()}'); http.onData = function (request) { + File.saveContent("export/ytlookup_result.txt", request); var data = new HtmlDocument(request); var search = data.find("script"); // YouTube obfuscates everything into JS garbage so we have to check every