refactoring several functions into smaller forms

pull/1/head
Astoria Floyd 3 years ago
parent 256ee5125d
commit 7639c9309c

@ -1,7 +1,10 @@
local basicCommands = {}
function helloWorld()
function basicCommands.helloWorld()
return("Hello world!")
end
return basicCommands

@ -1,61 +1,35 @@
local discordia = require('discordia')
local client = discordia.Client()
basic = require("./basicCommands.lua")
seed = os.time()
math.randomseed(seed)
local basicCommands = require("./basicCommands.lua")
local tools = require("./tools.lua")
local rng = require("./rng.lua")
function messageDectection(message, search)
distinctMessage = message.content
key = "!"
keyedSearch = key .. search
if string.find(distinctMessage, keyedSearch) == 1 then
return true
else
return false
end
end
function printFile(file)
rawFile = io.open(file, r)
message = rawFile:read("*all")
rawFile:close()
return message
end
client:once("ready", function()
client:setGame("Astoria's bot, very sad!")
print('Logged in as '.. client.user.username)
end)
client:on('messageCreate', function(message)
if messageDectection(message, "lenny") == true then
if tools.messageDectection(message, "lenny") == true then
message.channel:send("( ͡° ͜ʖ ͡°)")
end
end)
client:once("ready", function()
client:setGame("Astoria's bot, very sad!")
print('Logged in as '.. client.user.username)
end)
client:on('messageCreate', function(message)
if messageDectection(message, "ping") == true then
if tools.messageDectection(message, "ping") == true then
message.channel:send('Pong!')
end
end)
client:on('messageCreate', function(message)
if messageDectection(message, "ThemHelp") == true then
message.channel:send(printFile("docs/help"))
if tools.messageDectection(message, "ThemHelp") == true then
message.channel:send(tools.printFile("docs/help"))
end
end)
client:on('messageCreate', function(message)
if messageDectection(message, "roll") == true then
dice = math.random(20)
message.channel:send('You rolled a ' .. dice .. ' out of 20')
if dice==20 then
message.channel:send('Nat 20! Crititcal Hit')
else if dice==1 then
message.channel:send('Nat 1! Critical Shit!')
end
end
if tools.messageDectection(message, "roll") == true then
message.channel:send(rng.d20())
end
end)
--[[
@ -68,14 +42,14 @@ end)
--Replacing the above with a more tolerant version
client:on('messageCreate', function(message)
if 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!')
end
end)
client:on('messageCreate', function(message)
if messageDectection(message, "hiddentest") == true then
message.channel:send(basic.helloWorld())
if tools.messageDectection(message, "moduleTest") == true then
message.channel:send(basicCommands.helloWorld())
end
end)

@ -117,3 +117,87 @@
2021-08-06 16:55:50 | [INFO] | Shard 0 : Connected to wss://gateway.discord.gg
2021-08-06 16:55:50 | [INFO] | Shard 0 : Received HELLO
2021-08-06 16:55:50 | [INFO] | Shard 0 : Received READY
2021-08-06 17:31:16 | [INFO] | Discordia 2.9.1
2021-08-06 17:31:16 | [INFO] | Connecting to Discord...
2021-08-06 17:31:16 | [INFO] | Authenticated as Thembot#2260
2021-08-06 17:31:16 | [INFO] | Launching shard 0 (1 out of 1)...
2021-08-06 17:31:16 | [INFO] | Shard 0 : Connected to wss://gateway.discord.gg
2021-08-06 17:31:16 | [INFO] | Shard 0 : Received HELLO
2021-08-06 17:31:16 | [INFO] | Shard 0 : Received READY
2021-08-06 17:31:46 | [INFO] | Discordia 2.9.1
2021-08-06 17:31:46 | [INFO] | Connecting to Discord...
2021-08-06 17:31:46 | [INFO] | Authenticated as Thembot#2260
2021-08-06 17:31:46 | [INFO] | Launching shard 0 (1 out of 1)...
2021-08-06 17:31:46 | [INFO] | Shard 0 : Connected to wss://gateway.discord.gg
2021-08-06 17:31:46 | [INFO] | Shard 0 : Received HELLO
2021-08-06 17:31:46 | [INFO] | Shard 0 : Received READY
2021-08-06 17:31:54 | [INFO] | Discordia 2.9.1
2021-08-06 17:31:54 | [INFO] | Connecting to Discord...
2021-08-06 17:31:54 | [INFO] | Authenticated as Thembot#2260
2021-08-06 17:31:54 | [INFO] | Launching shard 0 (1 out of 1)...
2021-08-06 17:31:54 | [INFO] | Shard 0 : Connected to wss://gateway.discord.gg
2021-08-06 17:31:54 | [INFO] | Shard 0 : Received HELLO
2021-08-06 17:31:54 | [INFO] | Shard 0 : Received READY
2021-08-06 17:32:09 | [INFO] | Discordia 2.9.1
2021-08-06 17:32:09 | [INFO] | Connecting to Discord...
2021-08-06 17:32:09 | [INFO] | Authenticated as Thembot#2260
2021-08-06 17:32:09 | [INFO] | Launching shard 0 (1 out of 1)...
2021-08-06 17:32:10 | [INFO] | Shard 0 : Connected to wss://gateway.discord.gg
2021-08-06 17:32:10 | [INFO] | Shard 0 : Received HELLO
2021-08-06 17:32:10 | [INFO] | Shard 0 : Received READY
2021-08-06 17:32:25 | [INFO] | Discordia 2.9.1
2021-08-06 17:32:25 | [INFO] | Connecting to Discord...
2021-08-06 17:32:25 | [INFO] | Authenticated as Thembot#2260
2021-08-06 17:32:25 | [INFO] | Launching shard 0 (1 out of 1)...
2021-08-06 17:32:25 | [INFO] | Shard 0 : Connected to wss://gateway.discord.gg
2021-08-06 17:32:25 | [INFO] | Shard 0 : Received HELLO
2021-08-06 17:32:25 | [INFO] | Shard 0 : Received READY
2021-08-06 17:32:37 | [INFO] | Discordia 2.9.1
2021-08-06 17:32:37 | [INFO] | Connecting to Discord...
2021-08-06 17:32:37 | [INFO] | Authenticated as Thembot#2260
2021-08-06 17:32:37 | [INFO] | Launching shard 0 (1 out of 1)...
2021-08-06 17:32:37 | [INFO] | Shard 0 : Connected to wss://gateway.discord.gg
2021-08-06 17:32:37 | [INFO] | Shard 0 : Received HELLO
2021-08-06 17:32:38 | [INFO] | Shard 0 : Received READY
2021-08-06 17:33:02 | [INFO] | Discordia 2.9.1
2021-08-06 17:33:02 | [INFO] | Connecting to Discord...
2021-08-06 17:33:02 | [INFO] | Authenticated as Thembot#2260
2021-08-06 17:33:02 | [INFO] | Launching shard 0 (1 out of 1)...
2021-08-06 17:33:02 | [INFO] | Shard 0 : Connected to wss://gateway.discord.gg
2021-08-06 17:33:02 | [INFO] | Shard 0 : Received HELLO
2021-08-06 17:33:02 | [INFO] | Shard 0 : Received READY
2021-08-06 17:38:00 | [INFO] | Discordia 2.9.1
2021-08-06 17:38:00 | [INFO] | Connecting to Discord...
2021-08-06 17:38:00 | [INFO] | Authenticated as Thembot#2260
2021-08-06 17:38:00 | [INFO] | Launching shard 0 (1 out of 1)...
2021-08-06 17:38:00 | [INFO] | Shard 0 : Connected to wss://gateway.discord.gg
2021-08-06 17:38:00 | [INFO] | Shard 0 : Received HELLO
2021-08-06 17:38:00 | [INFO] | Shard 0 : Received READY
2021-08-06 17:51:35 | [INFO] | Discordia 2.9.1
2021-08-06 17:51:35 | [INFO] | Connecting to Discord...
2021-08-06 17:51:35 | [INFO] | Authenticated as Thembot#2260
2021-08-06 17:51:35 | [INFO] | Launching shard 0 (1 out of 1)...
2021-08-06 17:51:35 | [INFO] | Shard 0 : Connected to wss://gateway.discord.gg
2021-08-06 17:51:35 | [INFO] | Shard 0 : Received HELLO
2021-08-06 17:51:35 | [INFO] | Shard 0 : Received READY
2021-08-06 18:02:09 | [INFO] | Discordia 2.9.1
2021-08-06 18:02:09 | [INFO] | Connecting to Discord...
2021-08-06 18:02:14 | [INFO] | Authenticated as Thembot#2260
2021-08-06 18:02:14 | [INFO] | Launching shard 0 (1 out of 1)...
2021-08-06 18:02:14 | [INFO] | Shard 0 : Connected to wss://gateway.discord.gg
2021-08-06 18:02:14 | [INFO] | Shard 0 : Received HELLO
2021-08-06 18:02:14 | [INFO] | Shard 0 : Received READY
2021-08-06 18:02:55 | [INFO] | Discordia 2.9.1
2021-08-06 18:02:55 | [INFO] | Connecting to Discord...
2021-08-06 18:02:55 | [INFO] | Authenticated as Thembot#2260
2021-08-06 18:02:55 | [INFO] | Launching shard 0 (1 out of 1)...
2021-08-06 18:02:56 | [INFO] | Shard 0 : Connected to wss://gateway.discord.gg
2021-08-06 18:02:56 | [INFO] | Shard 0 : Received HELLO
2021-08-06 18:02:56 | [INFO] | Shard 0 : Received READY
2021-08-06 18:03:29 | [INFO] | Discordia 2.9.1
2021-08-06 18:03:29 | [INFO] | Connecting to Discord...
2021-08-06 18:03:30 | [INFO] | Authenticated as Thembot#2260
2021-08-06 18:03:30 | [INFO] | Launching shard 0 (1 out of 1)...
2021-08-06 18:03:30 | [INFO] | Shard 0 : Connected to wss://gateway.discord.gg
2021-08-06 18:03:30 | [INFO] | Shard 0 : Received HELLO
2021-08-06 18:03:30 | [INFO] | Shard 0 : Received READY

@ -1 +1 @@
{"873255296024322059":{"timestamp":1628283774,"owner":{"discriminator":"0000","avatar":null,"id":"872299874857676820","flags":1024,"public_flags":1024,"username":"team872299874857676820"},"shards":1},"url":"wss://gateway.discord.gg"}
{"873255296024322059":{"shards":1,"timestamp":1628289076,"owner":{"avatar":null,"discriminator":"0000","public_flags":1024,"id":"872299874857676820","username":"team872299874857676820","flags":1024}},"url":"wss://gateway.discord.gg"}

@ -0,0 +1,20 @@
local rng = {}
local tools = require("./tools.lua")
function rng.d20()
tools.reseed()
dice = math.random(20)
messagePart1 = ('You rolled a ' .. dice .. ' out of 20')
if dice==20 then
messagePart2 = ('Nat 20! Crititcal Hit')
else if dice==1 then
messagePart2 = ('Nat 1! Critical Shit!')
else
messagePart2 = ""
end
end
message = messagePart1 .. '\n' .. messagePart2
return message
end
return rng

@ -0,0 +1,26 @@
local tools = {}
function tools.reseed()
seed = os.time()
math.randomseed(seed)
end
function tools.printFile(file)
rawFile = io.open(file, r)
message = rawFile:read("*all")
rawFile:close()
return message
end
function tools.messageDectection(message, search)
distinctMessage = message.content
key = "!"
keyedSearch = key .. search
if string.find(distinctMessage, keyedSearch) == 1 then
return true
else
return false
end
end
return tools
Loading…
Cancel
Save