From 62713950ef5ac9538016ee55ccaa40de46bc3473 Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Fri, 6 Aug 2021 15:00:30 -0500 Subject: [PATCH] A proper, functional message detection function --- bot.lua | 23 +++++++++++++++++++++-- gateway.json | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/bot.lua b/bot.lua index 70134f3..91670b8 100644 --- a/bot.lua +++ b/bot.lua @@ -3,18 +3,28 @@ local client = discordia.Client() seed = os.time() math.randomseed(seed) +function messageDectection (message, search) + distinctMessage = message.content + if string.find(distinctMessage, search) == 1 then + return true + else + return false +end +end + + client:on('ready', function() print('Logged in as '.. client.user.username) end) client:on('messageCreate', function(message) - if message.content == '!ping' then + if messageDectection(message, "!ping") == true then message.channel:send('Pong!') end end) client:on('messageCreate', function(message) - if message.content == '!roll' then + if messageDectection(message, "!roll") == true then dice = math.random(20) message.channel:send('You rolled a ' .. dice .. ' out of 20') if dice==20 then @@ -26,11 +36,20 @@ client:on('messageCreate', function(message) end end) +--[[ client:on('messageCreate', function(message) if message.content == '!time' then message.channel:send('The current time in military time is ' .. os.date() .. ', atleast in Chicago!') end end) +]] + +--Replacing the above with a more tolerant version +client:on('messageCreate', function(message) + if messageDectection(message, "!time") == true then + message.channel:send('The current time in military time is ' .. os.date() .. ' atleast in Chicago!') + end +end) client:run('Bot ODczMjU1Mjk2MDI0MzIyMDU5.YQ1wXg.BbXq1fu-4nlG95EkLkHujVEObG4') diff --git a/gateway.json b/gateway.json index 447da71..8d23268 100644 --- a/gateway.json +++ b/gateway.json @@ -1 +1 @@ -{"url":"wss://gateway.discord.gg","873255296024322059":{"shards":1,"timestamp":1628272516,"owner":{"avatar":null,"discriminator":"0000","id":"872299874857676820","public_flags":1024,"username":"team872299874857676820","flags":1024}}} \ No newline at end of file +{"873255296024322059":{"timestamp":1628279979,"owner":{"username":"team872299874857676820","id":"872299874857676820","public_flags":1024,"flags":1024,"discriminator":"0000","avatar":null},"shards":1},"url":"wss://gateway.discord.gg"} \ No newline at end of file