Added ?trace command
This commit is contained in:
parent
d3801b48e0
commit
384dcc6416
@ -1,6 +1,7 @@
|
||||
# Changelog
|
||||
|
||||
## Release Version 1.2
|
||||
- Added `?trace` debug tool
|
||||
- New aliases: `?fineart`, `?artishard`, `?indeed`, `?florida`, `?stop`
|
||||
- Added YouTube search command
|
||||
- Fixed reconnection starting duplicate timers
|
||||
|
@ -236,6 +236,13 @@ class Onequestionmark {
|
||||
Sys.println('[${timestamp()}] ytdebug: No result to debug');
|
||||
m.reply({content:"ytdebug: No result to debug"}, false);
|
||||
}
|
||||
case "trace":
|
||||
if (m.referenced_message == null) {
|
||||
Sys.println('[${timestamp()}] trace: ${Json.stringify(getMessage(m.channel_id, m.id))}');
|
||||
} else {
|
||||
Sys.println('[${timestamp()}] trace: ${Json.stringify(getMessage(m.referenced_message.channel_id, m.referenced_message.id))}');
|
||||
}
|
||||
m.react('✅');
|
||||
// Gaming functions
|
||||
case "coin":
|
||||
if ((msg.length == 0) || (Std.parseInt(msg) == null) || (Std.parseInt(msg) == 1)) {
|
||||
@ -487,10 +494,10 @@ 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.urlEncode()}');
|
||||
var req = 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) {
|
||||
req.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 <script>
|
||||
@ -521,12 +528,41 @@ class Onequestionmark {
|
||||
m.reply({content:"-# YouTube Lookup is still in beta. If the result seems inaccurate, please use the command `?ytdebug` so the developer can review the data that was received."}, false);
|
||||
}
|
||||
|
||||
http.onError = function (error) {
|
||||
req.onError = function (error) {
|
||||
m.reply({content:'Error in YouTube Lookup: $error'}, false);
|
||||
Sys.println('[${timestamp()}] ytlookup: Error - $error, request was $query');
|
||||
}
|
||||
|
||||
http.request();
|
||||
req.request();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves a specific message in the channel and returns it as a JSON object.
|
||||
* @param channel_id Numerical ID of the channel.
|
||||
* @param m_id Numerical ID of the message.
|
||||
*/
|
||||
public static function getMessage(channel_id:String, m_id:String) {
|
||||
var req:hxdiscord.utils.Http = new hxdiscord.utils.Http("https://discord.com/api/v"+hxdiscord.gateway.Gateway.API_VERSION+"/channels/"+channel_id+"/messages/"+m_id);
|
||||
|
||||
req.addHeader("User-Agent", "hxdiscord (https://github.com/FurretDev/hxdiscord)");
|
||||
req.addHeader("Authorization", DiscordClient.authHeader);
|
||||
req.setMethod("GET");
|
||||
|
||||
var msg:Dynamic = null;
|
||||
|
||||
req.onData = function(data:String) {
|
||||
msg = haxe.Json.parse(data);
|
||||
}
|
||||
|
||||
req.onError = function(error) {
|
||||
Sys.println('[${timestamp()}] getMessage: Error - $error');
|
||||
Sys.println('[${timestamp()}] getMessage: ${req.responseData}');
|
||||
}
|
||||
|
||||
req.send();
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user