This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
sjele's profile picture

[Help] [Lua] [Message matching] [irc bot] Why does this alwways make a var true?

Started by sjele, 10 October 2012 - 12:23 PM
sjele #1
Posted 10 October 2012 - 02:23 PM
The code:
Code is from marticnobot, tho it is slightly modified by me

The problem: is_cmd is allways tru, therefor my bot allways tryes to run command, even when i don't use the **prefix.

Example:

say (text) would make him say respond (text)
I want it to only trigger when ** is used infront of command, but idk how to edit the message:match line to do so.

If you could tell me how i would be so thankful

code:

irc.register_callback("channel_msg", function(channel, from, message)
--local bleh = string.lower(message)
--if string.find(bleh, "hi") or string.find(bleh, "ey") or string.find(bleh, "hey") or string.find(bleh, "hello") then
 
  --irc.say(channel,  "Hi "..from)
  --return
--end
if from == "HBot" and string.find(message, "SjBaot: Please lower your caps usage.") then
  irc.say(channel, "I love you too HBot")
  return
end
if from == "Sjele" and string.find(string.lower(message),"lock you sjbaot") then
  if lock == nil then
   lock = true
   irc.say(channel, "State has been changed")
   return
  end
  irc.say(channel, "Locked status altred")
  lock = not lock
end
local is_cmd, cmd, arg = message:match("(**)(%w+) (.*)$")
if is_cmd and plugin[cmd] then
  if lock == true then
   if from ~="Sjele" then
    irc.say(channel, "Baot is locked")
    return
   end
  end
  plugin[cmd](channel.name, from, arg)
  end
  for k,v in pairs(callback) do
   if type(v) == "function" then
    v(channel.name, from, message)
   end
  end
  --end
--end
end)
Fatal_Exception #2
Posted 10 October 2012 - 02:49 PM
Try (%*%*)
sjele #3
Posted 10 October 2012 - 02:50 PM
Thanks to Steipen/Kilobyte i got this working, he made a function to check if it starts with **.

Allso, thanks