|
|
|
@@ -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 <script>
|
|
|
|
|
|
|
|
|
|
var gotcha = "";
|
|
|
|
|
var result = "Error: Unable to parse YouTube search result.";
|
|
|
|
|
|
|
|
|
|
for (i in search) {
|
|
|
|
|
if (i.toString().contains("https://youtu.be/")) { // Basic results link to the video like this
|
|
|
|
|
gotcha = i.toString();
|
|
|
|
|
result = gotcha.substring(gotcha.indexOf("https://youtu.be/"), gotcha.indexOf(".", gotcha.indexOf("https://youtu.be/")+17));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (i.toString().contains("watch?v=")) { // Because YouTube isn't consistent, alternative scrape
|
|
|
|
|
gotcha = i.toString();
|
|
|
|
|
|
|
|
|
|
// Detect YouTube Shorts link and clean it up
|
|
|
|
|
if (gotcha.substring(gotcha.indexOf("watch?v=")+8, gotcha.indexOf("\"", gotcha.indexOf("watch?v="))).contains("\\")) {
|
|
|
|
|
result = "https://youtu.be/" + gotcha.substring(gotcha.indexOf("watch?v=")+8, gotcha.indexOf("\\", gotcha.indexOf("watch?v=")));
|
|
|
|
|
}
|
|
|
|
|
// Normal video
|
|
|
|
|
else {
|
|
|
|
|
result = "https://youtu.be/" + gotcha.substring(gotcha.indexOf("watch?v=")+8, gotcha.indexOf("\"", gotcha.indexOf("watch?v=")));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m.reply({content:result}, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http.onError = function (error) {
|
|
|
|
|
Sys.println('[${timestamp()}] YTLOOKUP: Error - $error, request was $query');
|
|
|
|
|
|
|
|
|
|
m.reply({content:'Error in YouTube Lookup: $error'}, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http.request();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The `saveSystem()` function handles all filesystem writes. When the bot needs to save a file, it pushes data to the `saveQueue` array.
|
|
|
|
|
* The save system checks the queue regularly and operates on the first entry provided.
|
|
|
|
|