From 7639c9309c8a49fa421b80a286dcfa19315cd528 Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Fri, 6 Aug 2021 18:15:48 -0500 Subject: [PATCH] refactoring several functions into smaller forms --- basicCommands.lua | 5 ++- bot.lua | 58 +++++++++----------------------- discordia.log | 84 +++++++++++++++++++++++++++++++++++++++++++++++ gateway.json | 2 +- rng.lua | 20 +++++++++++ tools.lua | 26 +++++++++++++++ 6 files changed, 151 insertions(+), 44 deletions(-) create mode 100644 rng.lua create mode 100644 tools.lua diff --git a/basicCommands.lua b/basicCommands.lua index 58be018..2f2cf13 100644 --- a/basicCommands.lua +++ b/basicCommands.lua @@ -1,7 +1,10 @@ local basicCommands = {} -function helloWorld() +function basicCommands.helloWorld() return("Hello world!") end + + + return basicCommands diff --git a/bot.lua b/bot.lua index 8c0cd94..29528aa 100644 --- a/bot.lua +++ b/bot.lua @@ -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) diff --git a/discordia.log b/discordia.log index 9ca080f..16dadde 100644 --- a/discordia.log +++ b/discordia.log @@ -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 diff --git a/gateway.json b/gateway.json index 0a25eb3..31a4d60 100644 --- a/gateway.json +++ b/gateway.json @@ -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"} \ No newline at end of file +{"873255296024322059":{"shards":1,"timestamp":1628289076,"owner":{"avatar":null,"discriminator":"0000","public_flags":1024,"id":"872299874857676820","username":"team872299874857676820","flags":1024}},"url":"wss://gateway.discord.gg"} \ No newline at end of file diff --git a/rng.lua b/rng.lua new file mode 100644 index 0000000..1a604b6 --- /dev/null +++ b/rng.lua @@ -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 \ No newline at end of file diff --git a/tools.lua b/tools.lua new file mode 100644 index 0000000..bab73ff --- /dev/null +++ b/tools.lua @@ -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 \ No newline at end of file