onequestionmark-chat/Onequestionmark.hx

116 lines
3.7 KiB
Haxe
Raw Normal View History

2023-02-26 14:46:18 -06:00
import hxdiscord.DiscordClient;
import hxdiscord.types.*;
import hxdiscord.endpoints.Endpoints;
import haxe.Json;
import sys.io.File;
import sys.FileSystem;
class Onequestionmark {
static var Bot:DiscordClient;
static var settings:Dynamic;
static function main() {
// Init
Sys.println("onequestionmark-chat startup\r\n");
if (FileSystem.exists("settings.json")) {
Sys.println("Found settings.json, loading.\r\n");
settings = Json.parse(File.getContent("settings.json"));
} else {
Sys.println("Did not find settings.json, exiting.");
Sys.exit(0);
}
// Start the bot
Bot = new DiscordClient(settings.token, [3276799], settings.debug);
Bot.onReady = onReady;
Bot.onMessageCreate = onMessageCreate;
}
public static function onReady() {
Sys.println("onequestionmark is online.");
2023-02-26 16:11:00 -06:00
//Endpoints.sendMessage(settings.devchannel, {content:"onequestionmark-chat alpha test is now running"}, null, false);
2023-02-26 14:46:18 -06:00
}
public static function onMessageCreate(m:Message) {
2023-02-26 16:11:00 -06:00
// DevMode check
if ((!settings.devmode) || (m.guild_id == settings.devserver)) {
var msg = m.content;
// Command processor
if (msg.charAt(0) == "?") {
var command = "";
if (msg.indexOf(" ") != -1) {
// Separate command from rest of message, if necessary
command = msg.substring(1, msg.indexOf(" ")).toLowerCase();
msg = msg.substring(msg.indexOf(" ")+1);
} else {
// Otherwise, remove msg
command = msg.substring(1).toLowerCase();
msg = "";
}
switch (command) {
// Commands that require authorization
case "quit":
if (m.author.id == settings.botowner) {
m.reply({content:"Shutdown command received from botowner, exiting."}, false);
Sys.println("Shutdown command received from botowner, exiting.");
2023-02-26 17:41:40 -06:00
shutdown();
2023-02-26 16:11:00 -06:00
}
2023-02-26 17:43:36 -06:00
case "devmode":
if (m.author.id == settings.botowner) {
if (!settings.devmode) {
settings.devmode = true;
m.reply({content:"DevMode enabled."}, false);
} else {
settings.devmode = false;
m.reply({content:"DevMode disabled."}, false);
}
}
case "motd":
if (m.author.id == settings.botowner) {
if (!settings.motd.channels.contains(m.channel_id)) {
settings.motd.channels.push(m.channel_id);
m.reply({content:'MOTD has been enabled for <#${m.channel_id}>'}, false);
} else {
settings.motd.channels.remove(m.channel_id);
m.reply({content:'MOTD has been disabled for <#${m.channel_id}>'}, false);
}
}
2023-02-26 16:11:00 -06:00
// System for WIP commands that only work in testing server
case "wipcommand":
if (m.guild_id == settings.devserver) {
m.reply({content:"Dev Server response."}, true);
}
// Basic response commands
case "chk":
m.reply({content:'<@${m.author.id}>: ack'}, false);
case "slap":
if (msg.length != 0) {m.reply({content:'*onequestionmark slaps ${msg} around a bit with a large trout*'}, false);}
case "angery":
m.reply({content:"https://cdn.discordapp.com/attachments/1071547517847732305/1079518504413311108/angery.jpg"}, false);
case "subway":
m.reply({content:"https://www.youtube.com/watch?v=y3VRXVvr6XU"}, false);
2023-02-26 17:41:40 -06:00
// Image database commands
case "hug":
m.reply({content:'🫂 *hugs ${msg}*\n<insert randomized hug image here>'}, false);
2023-02-26 16:11:00 -06:00
}
}
// Non-command responses
if ((msg.charAt(0) == ".") && (msg.length == 1)) {m.reply({content:"omg a meteor"}, true);}
}
2023-02-26 14:46:18 -06:00
}
2023-02-26 17:41:40 -06:00
public static function saveSettings() {
File.saveContent("settings.json", Json.stringify(settings, "\t"));
}
public static function shutdown() {
saveSettings();
Sys.exit(0);
}
2023-02-26 14:46:18 -06:00
}