Added new aliases

This commit is contained in:
Izwzyzx 2024-11-10 22:19:47 -06:00
parent 978f6bc932
commit d3801b48e0
2 changed files with 35 additions and 24 deletions

View File

@ -1,6 +1,7 @@
# Changelog
## Release Version 1.2
- New aliases: `?fineart`, `?artishard`, `?indeed`, `?florida`, `?stop`
- Added YouTube search command
- Fixed reconnection starting duplicate timers
- Added system to prevent MOTD from chosing the same daily result consecutively

View File

@ -10,7 +10,7 @@ import izzcomlib.IzzComLib.*;
using StringTools;
class Onequestionmark {
// Initialize vars
// Initialize vars
static var Bot:DiscordClient;
static var settings:Dynamic;
static var botInfo:Dynamic;
@ -27,7 +27,7 @@ class Onequestionmark {
static var timerInit:Bool = false;
static function main() {
static function main() {
Sys.println('[${timestamp()}] Starting onequestionmark-chat');
@ -78,17 +78,17 @@ class Onequestionmark {
saveSystem();
// Start the bot
Bot = new DiscordClient(settings.token, [3276799], settings.debug);
Bot.onReady = onReady;
Bot.onMessageCreate = onMessageCreate;
Bot = new DiscordClient(settings.token, [3276799], settings.debug);
Bot.onReady = onReady;
Bot.onMessageCreate = onMessageCreate;
Bot.connect();
}
}
/**
* The `onReady()` function is run upon a successful `Bot.connect()`
*/
public static function onReady() {
public static function onReady() {
Sys.sleep(1);
Sys.println('[${timestamp()}] Bot is online');
@ -103,16 +103,16 @@ class Onequestionmark {
timerInit = true;
startMotd();
}
}
}
/**
* The `onMessageCreate()` event provides the bulk of onequestionmark's functionality.
* This is what triggers when a new Discord message is received, and contains the bot's command processor.
*/
public static function onMessageCreate(m:Message) {
public static function onMessageCreate(m:Message) {
// DevMode check
if ((!settings.devmode) || (m.guild_id == settings.devserver)) {
if ((!settings.devmode) || (m.guild_id == settings.devserver)) {
var msg = m.content;
var sender:String;
if (m.getMember().nick == null) {sender = m.author.global_name;} else {sender = m.getMember().nick;}
@ -311,6 +311,16 @@ class Onequestionmark {
m.reply({content:"https://cdn.discordapp.com/attachments/1071547517847732305/1147590229960691742/communism.gif"}, false);
case "opinions":
m.reply({content:"https://cdn.discordapp.com/attachments/1071547517847732305/1147983375701921892/opinions.jpg"}, false);
case "fineart":
m.reply({content:"https://cdn.discordapp.com/attachments/270113422232911883/423323629116325898/unknown.png"}, false);
case "artishard":
m.reply({content:"https://cdn.discordapp.com/attachments/270113422232911883/356638565834424330/tumblr_nrxhzoF0KM1t75ioqo2_250.jpg"}, false);
case "indeed":
m.reply({content:"https://cdn.discordapp.com/attachments/1071547517847732305/1305252892491649145/indeed.gif"}, false);
case "florida":
m.reply({content:"https://cdn.discordapp.com/attachments/1071547517847732305/1305253566348529696/florida.gif"}, false);
case "stop":
m.reply({content:"https://cdn.discordapp.com/attachments/1071547517847732305/1305253985036275712/stop.jpg"}, false);
// Image database commands
case "hug":
if (hugDB.length > 0) {
@ -369,7 +379,7 @@ class Onequestionmark {
if ((iceRegex.match(msg)) && (m.author.id != botInfo.id)) {m.reply({content:"Did some carbon-based lifeform just say **I C E**?"});}
if ((m.mention_everyone == true) && (msg.charAt(0) != "?")) {m.reply({content:"https://cdn.discordapp.com/attachments/1071547517847732305/1147598637241741343/at_everyone.jpg"}, true);}
}
}
}
/**
@ -398,7 +408,7 @@ class Onequestionmark {
// Start the looped MOTD timer
motdTimer = new Timer(86400000);
motdTimer.run = function() {
motdTimer.run = function() {
settings.motd.date = datestamp();
postMotd();
saveQueue.push("settings");
@ -472,16 +482,16 @@ 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.
*/
* 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.urlEncode()}');
Sys.println('[${timestamp()}] ytlookup: URL - 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);
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>
@ -495,24 +505,24 @@ class Onequestionmark {
// Top result is a Short
result = "https://youtu.be/" + gotcha.substring(gotcha.indexOf("\"reelWatchEndpoint\":{\"videoId\":\"")+32, gotcha.indexOf("\"", gotcha.indexOf("\"reelWatchEndpoint\":{\"videoId\":\"")+32));
Sys.println('[${timestamp()}] ytlookup: Result - $result (Short)');
Sys.println('[${timestamp()}] ytlookup: Result - $result (Short)');
break;
} else {
// Top result is a normal video
result = "https://youtu.be/" + gotcha.substring(gotcha.indexOf("\"videoRenderer\":{\"videoId\":\"")+28, gotcha.indexOf("\"", gotcha.indexOf("\"videoRenderer\":{\"videoId\":\"")+28));
Sys.println('[${timestamp()}] ytlookup: Result - $result (Normal)');
Sys.println('[${timestamp()}] ytlookup: Result - $result (Normal)');
break;
}
}
}
m.reply({content:result}, false);
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);
m.reply({content:result}, false);
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) {
m.reply({content:'Error in YouTube Lookup: $error'}, false);
m.reply({content:'Error in YouTube Lookup: $error'}, false);
Sys.println('[${timestamp()}] ytlookup: Error - $error, request was $query');
}
@ -528,7 +538,7 @@ class Onequestionmark {
public static function saveSystem() {
Timer.delay(function() {
saveTimer = new Timer(60*1000);
saveTimer.run = function() {
saveTimer.run = function() {
if (saveQueue.length > 0) { // See if there's anything in the queue
switch (saveQueue.shift()) {
case "settings":