Added testmode functionality. Created experimental branch

pull/1/head
Astoria Floyd 3 years ago
parent 250ad85bbe
commit fe16508fe1

@ -17,6 +17,13 @@ function tools.initialize()
return commands return commands
end end
--Reads testmode.lua
function tools.testModeDetection()
return dofile("./docs/testmode.lua")
end
--
--Reads an entire file, outputs as string. --Reads an entire file, outputs as string.
function tools.printFile(file) function tools.printFile(file)
local rawFile = io.open(file, r) local rawFile = io.open(file, r)
@ -51,7 +58,7 @@ end
--Now deprecated --Now deprecated
function tools.messageDectection(message, search) function tools.messageDectection(message, search)
local distinctMessage = string.lower(message.content) local distinctMessage = string.lower(message.content)
local key = require("./docs/settings.lua") local key = dofile("./docs/key.lua")
local keyedSearch = key .. search local keyedSearch = key .. search
if string.find(distinctMessage, keyedSearch) == 1 then if string.find(distinctMessage, keyedSearch) == 1 then
return true return true

@ -12,28 +12,35 @@ end)
--Command handler --Command handler
client:on('messageCreate', function(message) client:on('messageCreate', function(message)
if message.author.bot then return end if message.author.bot then return end
local args = message.content:split(" ") if Tools.testModeDetection() == true then
local lowerArgs = args[1]:lower() Commands = Tools.initialize()
local command = Commands[lowerArgs] Tools = dofile("./API/tools.lua")
if command then end
command.exec(message, args) local args = message.content:split(" ")
end local lowerArgs = args[1]:lower()
local command = Commands[lowerArgs]
if command then
command.exec(message, args)
elseif Tools.testModeDetection() == false and Tools.messageDectection(message, "reinitialize") == true then
reinitialize(message)
elseif Tools.testModeDetection() == true and Tools.messageDectection(message, "reinitialize") == true then
message:reply("You cannot preform this command because testMode is on!")
end
end) end)
--Re-Init detector. Only command that itself cannot be fully re-initialized function reinitialize(message)
client:on('messageCreate', function(message)
local user = message.guild:getMember(message.author.id) local user = message.guild:getMember(message.author.id)
if Tools.messageDectection(message, "reinitialize") == true then if Tools.messageDectection(message, "reinitialize") == true then
if not user:hasPermission("administrator") then if not user:hasPermission("administrator") then
message:reply("You cannot re-initialize this bot!") message:reply("You cannot re-initialize this bot!")
else else
Commands = Tools.initialize() Commands = Tools.initialize()
Tools = dofile("./API/tools.lua") Tools = dofile("./API/tools.lua")
message:reply("Re-Initialized!") message:reply("Re-Initialized!")
end
end end
end end
end)
--When a user is banned, post a lenney. --When a user is banned, post a lenney.
client:on('userBan', function() client:on('userBan', function()

@ -2,57 +2,62 @@ local tools = dofile("./API/tools.lua")
local rng = dofile("./API/rng.lua") local rng = dofile("./API/rng.lua")
local complexCommands = {} local complexCommands = {}
local prefix = dofile("./docs/settings.lua") local prefix = dofile("./docs/key.lua")
local commands = { -- Define commands its a table that will contain our commands 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. [prefix..'helpme'] = { -- Dumps docs/help to chat, took me forever to figure out.
exec = function (message) exec = function (message)
message.channel:send(tools.printFile("docs/help")) message.channel:send(tools.printFile("docs/help"))
end end
}; };
[prefix..'roll'] = { -- Rolls a d20, check RNG for more info. [prefix..'roll'] = { -- Rolls a d20, check RNG for more info.
exec = function (message, arg) exec = function (message, arg)
if not arg[2] then if not arg[2] then
message.channel:send(rng.d20()) message.channel:send(rng.d20())
else else
message.channel:send(rng.roll(arg)) message.channel:send(rng.roll(arg))
end end
end end
}; };
[prefix..'figlet'] = { -- Parrots input to figlet, then echos it to the same channel you are in. [prefix..'figlet'] = { -- Parrots input to figlet, then echos it to the same channel you are in.
exec = function (message) exec = function (message)
local prefixLength = string.len(prefix) local prefixLength = string.len(prefix)
local figletthis = string.sub(message.content, 7+prefixLength) local figletthis = string.sub(message.content, 7+prefixLength)
local figlet = tools.figlet(figletthis) local figlet = tools.figlet(figletthis)
local result = "```fix" .. "\n" .. figlet .. "```" local result = "```fix" .. "\n" .. figlet .. "```"
message.channel:send(result) message.channel:send(result)
message:delete() message:delete()
end end
}; };
[prefix..'cowsay'] = { -- Parrots input to cowsay, then echos it to the same channel you are in. [prefix..'cowsay'] = { -- Parrots input to cowsay, then echos it to the same channel you are in.
exec = function (message) exec = function (message)
local prefixLength = string.len(prefix) local prefixLength = string.len(prefix)
local cowsay = string.sub(message.content, 7+prefixLength) local cowsay = string.sub(message.content, 7+prefixLength)
local cowsaid = tools.cowsay(cowsay) local cowsaid = tools.cowsay(cowsay)
local result = "```fix" .. "\n" .. cowsaid .. "```" local result = "```fix" .. "\n" .. cowsaid .. "```"
message.channel:send(result) message.channel:send(result)
message:delete() message:delete()
end end
}; };
[prefix..'echo'] = { -- Echo's what you said back out, in a fix codeblock. Could be against TOS. [prefix..'echo'] = { -- Echo's what you said back out, in a fix codeblock. Could be against TOS.
exec = function (message) exec = function (message)
local prefixLength = string.len(prefix) local prefixLength = string.len(prefix)
local echo = string.sub(message.content, 5+prefixLength) local echo = string.sub(message.content, 5+prefixLength)
local echoed = tools.echo(echo) local echoed = tools.echo(echo)
local result = "```fix" .. "\n" .. echoed .. "```" local result = "```fix" .. "\n" .. echoed .. "```"
message.channel:send(result) message.channel:send(result)
message:delete() message:delete()
end end
}; };
} }
function complexCommands.initialize() function complexCommands.initialize()
return commands return commands
end end
return complexCommands return complexCommands
-- This project is libre, and licenced under the terms of the -- This project is libre, and licenced under the terms of the

@ -1,45 +1,58 @@
local basicCommands = {} local basicCommands = {}
local prefix = dofile("./docs/settings.lua") local prefix = dofile("./docs/key.lua")
local commands = { -- Define commands its a table that will contain our commands local commands = { -- Define commands its a table that will contain our commands
[prefix..'lenny'] = { -- Creates a lenny face [prefix..'lenny'] = { -- Creates a lenny face
exec = function (message) exec = function (message)
message.channel:send('( ͡° ͜ʖ ͡°)') message.channel:send('( ͡° ͜ʖ ͡°)')
end end
}; };
[prefix..'glomp'] = { -- Posts an image of glomping, may add RNG later. [prefix..'glomp'] = { -- Posts an image of glomping, may add RNG later.
exec = function (message) exec = function (message)
message.channel:send('https://tenor.com/view/tv-shows-television-tackle-hug-hug-glomping-gif-14859564') message.channel:send('https://tenor.com/view/tv-shows-television-tackle-hug-hug-glomping-gif-14859564')
end end
}; };
[prefix..'ping'] = { -- Ping Pong function, generally just to see if its on or not without triggering a more complex function. Also tests if its really borked. [prefix..'ping'] = { -- Ping Pong function, generally just to see if its on or not without triggering a more complex function. Also tests if its really borked.
exec = function (message) exec = function (message)
message.channel:send("Pong!") message.channel:send("Pong!")
end end
}; };
[prefix..'fire'] = { -- Places elmo on fire in chat. [prefix..'fire'] = { -- Places elmo on fire in chat.
exec = function (message) exec = function (message)
message.channel:send("https://tenor.com/view/elmo-fire-burn-flame-gif-5042503") message.channel:send("https://tenor.com/view/elmo-fire-burn-flame-gif-5042503")
end end
}; };
[prefix..'time'] = { -- Posts time to channel, stuck in military time, perhaps use a io.popen() to get actual system time in a more human readable format? [prefix..'time'] = { -- Posts time to channel, stuck in military time, perhaps use a io.popen() to get actual system time in a more human readable format?
exec = function (message) exec = function (message)
message.channel:send('The current time in military time is ' .. os.date() .. ' atleast in Chicago!') message.channel:send('The current time in military time is ' .. os.date() .. ' atleast in Chicago!')
end end
}; };
[prefix..'analyze'] = { -- Prints contents and attachments to console. [prefix..'analyze'] = { -- Prints contents and attachments to console.
exec = function (message) exec = function (message)
p(message.content) p(message.content)
p(message.attachments) p(message.attachments)
end end
}; };
[prefix..'welsh'] = { -- Welsh. [prefix..'welsh'] = { -- Welsh.
exec = function (message) exec = function (message)
message.channel:send("https://cdn.discordapp.com/attachments/748713417489252503/770289379586867231/image0.gif") message.channel:send("https://cdn.discordapp.com/attachments/748713417489252503/770289379586867231/image0.gif")
message:delete() message:delete()
end end
}; };
[prefix..'test'] = { -- Test Command.
exec = function (message)
message.channel:send("I can add new commands on the fly, probably just going to be for testing purposes. Probably a security hole. Hence why this is the _experimental_ branch")
message:delete()
end
};
} }

@ -1,5 +1,5 @@
--Litterally just the prefix right now --Litterally just the prefix right now
return "!" return "exp!"
-- This project is libre, and licenced under the terms of the -- This project is libre, and licenced under the terms of the
-- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENCE, version 3.1, -- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENCE, version 3.1,
-- as published by dtf on July 2019. See the COPYING file or -- as published by dtf on July 2019. See the COPYING file or

@ -0,0 +1 @@
return false
Loading…
Cancel
Save