Skip to content
This repository has been archived by the owner on Oct 14, 2018. It is now read-only.

Help with plugin: Write note to txt file #368

Open
gargomoma opened this issue Feb 10, 2016 · 2 comments
Open

Help with plugin: Write note to txt file #368

gargomoma opened this issue Feb 10, 2016 · 2 comments

Comments

@gargomoma
Copy link

Hi guys, i'm in trouble.
I'm already starting coding, so i don't know if i do it OK.

The deal is that i wanted a plugin that would let my bot to get the "text" (or links) that me and my friends wrote and save them into a .txt file.

I saw few tutorials on the net about how could be possible to do it, but I'm getting stucked.

I always got the same error

./bot/bot.lua:263: attempt to call a nil value

This is the code i wrote, it's based on hello.lua to get the text and notificate it got its. but i don't know how to add the "file" editing part. Tried io.open and os.execute.

This is the code, thanks for your attention. ^^

``local _textPath = "./home/USER/textfile.txt"

do
local file = io.open( _textpath ,"a+")
file:write( ..matches[1].. \n) ----->Don't know if it would be OK like this
file:close()
end

function run(msg, matches)
return "Nota " .. matches[1] .. " añadida."
end

return {
description = "Add [link] to txt file",
usage = "!note [text/link]",
patterns = {
"^!note (.)$",
"^!note (.
)$"
},
run = run
}

end
``

@drsandro
Copy link

I do it dirty but in one line only:

os.execute("echo " ..matches[1].. " >> " _textpath"

or
os.execute("echo " ..msg.text.. " >> " _textpath"

@gargomoma
Copy link
Author

I did it!! 💃

Here you have this template to run any console command

do

function run(msg, matches)
  os.execute("nohup COMAND "..matches[1].." </dev/null &>/dev/null &")
  return "Added: " .. matches[1]
end

return {
  description = "comand", 
  usage = "comand [argument]",
  patterns = {
    "^!cmd (.*)$"
  }, 
  run = run,
  privileged = true 
}

end

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants