From 1a897507c4110bd844add8bab1272dbeaf1f11a1 Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Sat, 7 Aug 2021 16:56:17 -0500 Subject: [PATCH] Minor refractoring, allows hot-refreshing. --- bot.lua | 16 ++++++++-------- complexCommands.lua | 6 +++--- rng.lua | 2 +- simpleCommands.lua | 9 ++------- tools.lua | 10 ++++++++++ 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/bot.lua b/bot.lua index 3c59153..8de1fe1 100644 --- a/bot.lua +++ b/bot.lua @@ -3,18 +3,11 @@ local client = discordia.Client() local tools = require("./tools.lua") discordia.extensions() -local simpleCommands = require("./simpleCommands.lua") -local complexCommands = require("./complexCommands.lua") - ---Initialize commands, CLEAN THIS UP, MAKE IT DO MORE THEN TWO, CURRENTLY WE NEED TO JUST DO THIS OVER AND OVER -local complexCommands = complexCommands.initialize() -local simpleCommands = simpleCommands.initialize() -local commands = tools.tableMerge(simpleCommands, complexCommands) - --Setup bot here, initializes bot client:once("ready", function() client:setGame("Astoria's bot, very sad!") print('Logged in as '.. client.user.username) + commands = tools.initialize() end) --Command handler @@ -28,6 +21,13 @@ client:on('messageCreate', function(message) end end) +client:on('messageCreate', function(message) + if tools.messageDectection(message, "reinitialize") == true then + commands = tools.initialize() + message:reply("Re-Initialized!") + end +end) + --When a user is banned, post a lenney. client:on('userBan', function() local banChannel, err = client:getChannel("872283716486066200") diff --git a/complexCommands.lua b/complexCommands.lua index f946d24..0acd591 100644 --- a/complexCommands.lua +++ b/complexCommands.lua @@ -1,8 +1,8 @@ -local tools = require("./tools.lua") -local rng = require("./rng.lua") +local tools = dofile("./tools.lua") +local rng = dofile("./rng.lua") local complexCommands = {} -local prefix = require("./settings.lua") +local prefix = dofile("./settings.lua") local commands = { -- Define commands its a table that will contain our commands [prefix..'helpme'] = { -- Dumps docs/help to chat, took me forever to figure out. diff --git a/rng.lua b/rng.lua index 478048e..0e8d71f 100644 --- a/rng.lua +++ b/rng.lua @@ -1,5 +1,5 @@ local rng = {} -local tools = require("./tools.lua") +local tools = dofile("./tools.lua") --Rolls a d20, if output is 1, Critical miss(or Shit), if output is 20, critical hit. function rng.d20() diff --git a/simpleCommands.lua b/simpleCommands.lua index 6c988a6..aa8c90b 100644 --- a/simpleCommands.lua +++ b/simpleCommands.lua @@ -1,5 +1,5 @@ local basicCommands = {} -local prefix = require("./settings.lua") +local prefix = dofile("./settings.lua") local commands = { -- Define commands its a table that will contain our commands [prefix..'lenny'] = { -- Creates a lenny face @@ -34,17 +34,12 @@ local commands = { -- Define commands its a table that will contain our commands p(message.attachments) end }; -[prefix..'welsh'] = { -- +[prefix..'welsh'] = { -- Welsh. exec = function (message) message.channel:send("https://cdn.discordapp.com/attachments/748713417489252503/770289379586867231/image0.gif") message:delete() end }; -[prefix..'testArgs'] = { -- - exec = function (message, args) - message.channel:send(args[2]) - end - }; } diff --git a/tools.lua b/tools.lua index c0c1ab4..9b5c91c 100644 --- a/tools.lua +++ b/tools.lua @@ -7,6 +7,16 @@ function tools.seed() math.randomseed(seed) end +--Initializes commands. +function tools.initialize() + local simpleCommands = dofile("./simpleCommands.lua") + local complexCommands = dofile("./complexCommands.lua") + local complexCommands = complexCommands.initialize() + local simpleCommands = simpleCommands.initialize() + local commands = tools.tableMerge(simpleCommands, complexCommands) + return commands + end + --Reads an entire file, outputs as string. function tools.printFile(file) local rawFile = io.open(file, r)