yagop / telegram-bot

UNMAINTAINED - A Telegram Bot based on plugins

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Help with plugin: Write note to txt file

gargomoma opened this issue · comments

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
``

I do it dirty but in one line only:

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

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

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