Added comments, removed potential vulnerability by using Echo function, when could just parrot input to output. Possibly less efficient then just doing that in main, but could have more uses?

pull/1/head
Astoria Floyd 3 years ago
parent 6cf424ca08
commit d1b8ac24fa

@ -1,25 +1,27 @@
local basicCommands = {} local basicCommands = {}
--Hello World!
function basicCommands.helloWorld() function basicCommands.helloWorld()
return("Hello world!") return("Hello world!")
end end
--Executes Figlet on the host machine.
function basicCommands.figlet(string) function basicCommands.figlet(string)
local figleted = io.popen("figlet ".. string) local figleted = io.popen("figlet ".. string)
local result = figleted:read("*all") local result = figleted:read("*all")
return result return result
end end
--Executes Cowsay on the host machine.
function basicCommands.cowsay(string) function basicCommands.cowsay(string)
local cowsaid = io.popen("cowsay ".. string) local cowsaid = io.popen("cowsay ".. string)
local result = cowsaid:read("*all") local result = cowsaid:read("*all")
return result return result
end end
--Takes input and makes it output. GIGO.
function basicCommands.echo(string) function basicCommands.echo(string)
local echoed = io.popen("echo ".. string) return string
local result = echoed:read("*all")
return result
end end
return basicCommands return basicCommands

@ -3,12 +3,14 @@ local client = discordia.Client()
local basicCommands = require("./basicCommands.lua") local basicCommands = require("./basicCommands.lua")
local tools = require("./tools.lua") local tools = require("./tools.lua")
local rng = require("./rng.lua") local rng = require("./rng.lua")
--Setup bot here, initializes bot
client:once("ready", function() client:once("ready", function()
client:setGame("Astoria's bot, very sad!") client:setGame("Astoria's bot, very sad!")
print('Logged in as '.. client.user.username) print('Logged in as '.. client.user.username)
end) end)
--Everything past this point is commands, initialized here in bot.lua, but its good practise to have the actual functions outside, may be converted to one main call. May be laggier that way, but less cluttered. Perhaps a table?
--Creates a lenny face
client:on('messageCreate', function(message) client:on('messageCreate', function(message)
if tools.messageDectection(message, "lenny") == true then if tools.messageDectection(message, "lenny") == true then
message.channel:send("( ͡° ͜ʖ ͡°)") message.channel:send("( ͡° ͜ʖ ͡°)")
@ -16,12 +18,14 @@ client:on('messageCreate', function(message)
end end
end) end)
--Posts an image of glomping, may add RNG later.
client:on('messageCreate', function(message) client:on('messageCreate', function(message)
if tools.messageDectection(message, "glomp") == true then if tools.messageDectection(message, "glomp") == true then
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
end) end)
--Every time someone says "gif" or some varient of that, often in gifs themselves, it pastes that text. May replace with a copypasta.
client:on('messageCreate', function(message) client:on('messageCreate', function(message)
if message.author.bot then return end if message.author.bot then return end
if tools.messageDectectionAnywhere(message, "gif") == true then if tools.messageDectectionAnywhere(message, "gif") == true then
@ -29,45 +33,42 @@ client:on('messageCreate', function(message)
end end
end) end)
--Ping Pong function, generally just to see if its on or not without triggering a more complex function. Also tests if its really borked.
client:on('messageCreate', function(message) client:on('messageCreate', function(message)
if tools.messageDectection(message, "ping") == true then if tools.messageDectection(message, "ping") == true then
message.channel:send('Pong!') message.channel:send('Pong!')
end end
end) end)
client:on('userBan', function() --Places elmo on fire in chat.
local banChannel, err = client:getChannel("872283716486066200")
if not banChannel then
p("Attempt to fetch the channel object: ", err)
return
end
banChannel:send("User was banned ( ͡° ͜ʖ ͡°)")
end)
client:on('messageCreate', function(message) client:on('messageCreate', function(message)
if tools.messageDectection(message, "fire") == true then if tools.messageDectection(message, "fire") == true then
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
end) end)
--Dumps docs/help to chat, took me forever to figure out.
client:on('messageCreate', function(message) client:on('messageCreate', function(message)
if tools.messageDectection(message, "helpme") == true then if tools.messageDectection(message, "helpme") == true then
message.channel:send(tools.printFile("docs/help")) message.channel:send(tools.printFile("docs/help"))
end end
end) end)
--Rolls a d20, check RNG for more info.
client:on('messageCreate', function(message) client:on('messageCreate', function(message)
if tools.messageDectection(message, "roll") == true then if tools.messageDectection(message, "roll") == true then
message.channel:send(rng.d20()) message.channel:send(rng.d20())
end end
end) end)
--Posts time to channel, stuck in military time, perhaps use a io.popen() to get actual system time in a more human readable format?
client:on('messageCreate', function(message) client:on('messageCreate', function(message)
if tools.messageDectection(message, "time") == true then if tools.messageDectection(message, "time") == true then
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
end) end)
--Prints contents and attachments to console.
client:on('messageCreate', function(message) client:on('messageCreate', function(message)
if tools.messageDectection(message, "analyze") == true then if tools.messageDectection(message, "analyze") == true then
print(message.content) print(message.content)
@ -75,6 +76,7 @@ client:on('messageCreate', function(message)
end end
end) end)
--Parrots input to cowsay, then echos it to the same channel you are in.
client:on('messageCreate', function(message) client:on('messageCreate', function(message)
if tools.messageDectection(message, "figlet ") == true then if tools.messageDectection(message, "figlet ") == true then
local figletthis = string.sub(message.content, 9) local figletthis = string.sub(message.content, 9)
@ -84,6 +86,7 @@ client:on('messageCreate', function(message)
end end
end) end)
--Parrots input to cowsay, then echos it to the same channel you are in.
client:on('messageCreate', function(message) client:on('messageCreate', function(message)
if tools.messageDectection(message, "cowsay ") == true then if tools.messageDectection(message, "cowsay ") == true then
local cowsay = string.sub(message.content, 9) local cowsay = string.sub(message.content, 9)
@ -93,6 +96,7 @@ client:on('messageCreate', function(message)
end end
end) end)
--Echo's what you said back out, in a fix codeblock. Could be against TOS.
client:on('messageCreate', function(message) client:on('messageCreate', function(message)
if tools.messageDectection(message, "echo ") == true then if tools.messageDectection(message, "echo ") == true then
local echo = string.sub(message.content, 7) local echo = string.sub(message.content, 7)
@ -103,6 +107,7 @@ client:on('messageCreate', function(message)
end end
end) end)
--When anyone preforms welsh, send gif. You know the drill
client:on('messageCreate', function(message) client:on('messageCreate', function(message)
if tools.messageDectection(message, "welsh") == true then if tools.messageDectection(message, "welsh") == true then
image = "https://cdn.discordapp.com/attachments/748713417489252503/770289379586867231/image0.gif" image = "https://cdn.discordapp.com/attachments/748713417489252503/770289379586867231/image0.gif"
@ -110,6 +115,17 @@ client:on('messageCreate', function(message)
message:delete() message:delete()
end end
end) end)
--Non command stuff past this line
--When a user is banned, post a lenney.
client:on('userBan', function()
local banChannel, err = client:getChannel("872283716486066200")
if not banChannel then
p("Attempt to fetch the channel object: ", err)
return
end
banChannel:send("User was banned ( ͡° ͜ʖ ͡°)")
end)
--Insert Token in a .lua file with simply returns it as a string. --Insert Token in a .lua file with simply returns it as a string.
local token = require("./token.lua") local token = require("./token.lua")

@ -1,6 +1,7 @@
local rng = {} local rng = {}
local tools = require("./tools.lua") local tools = require("./tools.lua")
--Rolls a d20, if output is 1, Critical miss(or Shit), if output is 20, critical hit.
function rng.d20() function rng.d20()
tools.reseed() tools.reseed()
local dice = math.random(20) local dice = math.random(20)

@ -1,11 +1,13 @@
---@diagnostic disable: undefined-global ---@diagnostic disable: undefined-global
local tools = {} local tools = {}
function tools.reseed() --initializes or re-initializes the seed of RNG, based on Unix Time.
function tools.seed()
local seed = os.time() local seed = os.time()
math.randomseed(seed) math.randomseed(seed)
end end
--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)
local message = rawFile:read("*all") local message = rawFile:read("*all")
@ -13,6 +15,7 @@ function tools.printFile(file)
return message return message
end end
--Message detection logic. If string.find detects both the desired string, and the key, starting at position 1, do the thing.
function tools.messageDectection(message, search) function tools.messageDectection(message, search)
local distinctMessage = string.lower(message.content) local distinctMessage = string.lower(message.content)
local key = "!" local key = "!"
@ -24,6 +27,7 @@ function tools.messageDectection(message, search)
end end
end end
--Special message detection logic. If string.find detects both the desired string, do the thing. Useful for chat filers.
function tools.messageDectectionAnywhere(message, search) function tools.messageDectectionAnywhere(message, search)
local distinctMessage = string.lower(message.content) local distinctMessage = string.lower(message.content)
if string.find(distinctMessage, search) ~= nil then if string.find(distinctMessage, search) ~= nil then

Loading…
Cancel
Save