iwestlin / gd-utils

Google Drive 百宝箱
1.31k stars 425 forks source link

[Feature Request] More Options in Tg bot #196

Open roshanconnor123 opened 4 years ago

roshanconnor123 commented 4 years ago

Hi there, Hope you are doing well I have a feature Request for Tg bot

  1. Is it possible to add dedupe feature in Tg bot as well?
  2. Is it possible to add snap2html and tree function in bot as well? Like,If i run my command this way
    /count FolderID -S -t snap -o Index.html

    Can it reply to me with a Index.html File

Thank you

PS: I added instructions for Windows as well as Android system in readme (English Repo) In case if you want to check it out

Thanks once again for this wonderful tool

iwestlin commented 4 years ago
  • Is it possible to add dedupe feature in Tg bot as well?
  • Is it possible to add snap2html and tree function in bot as well?

It is...However I don't want add too much functions to Tg bot. For me, bot is normally used to copy folders others shared. To do other things, using command line is more comfortable.

But a PR is always welcome, if anyone is insterested...


Also if its alright with you,could you please explain how aria2 works (in brief)

I made a screen record earlier: https://drive.google.com/file/d/1lzN7R9Klw66C5UttUUDN3_EsN3pNs62q/view

Feel free to ask if the record isn't clear.


I added instructions for Windows as well as Android system in readme (English Repo) In case if you want to check it out

Thank you for your contribution👍, I added it to readme: https://github.com/iwestlin/gd-utils/commit/9defd5b59bb57de1f7fca44412f225cc16c666f7

roshanconnor123 commented 4 years ago

Thank you for your response Just tested aria2,its very good About the bot thing..If i wanted to do add those features for my personal use Which file should i be editing ? Thanks for all the insights

iwestlin commented 4 years ago

Which file should i be editing?

You could add two buttons, for example snap2html and tree2html here: https://github.com/iwestlin/gd-utils/blob/9defd5b59bb57de1f7fca44412f225cc16c666f7/src/tg.js#L137

then handle the callback data of user clicking those buttons here: https://github.com/iwestlin/gd-utils/blob/9defd5b59bb57de1f7fca44412f225cc16c666f7/src/router.js#L64

then call tree_tpl or snap2html function to generate html file, and send the file to tg api by: https://core.telegram.org/bots/api#sending-files (there are some limitations)

iwestlin commented 4 years ago

send file to bot can be a little tricky, so I wrote a function, tested good:

const fs = require('fs')
const FormData = require('form-data') // need to run `npm i form-data` first

function send_file ({file_path, chat_id}) {
  const url = `https://api.telegram.org/bot${tg_token}/sendDocument`
  const form = new FormData()
  form.append('chat_id', chat_id)
  form.append('document', fs.createReadStream(file_path))
  axins.post(url, form, {
    headers: form.getHeaders()
  }).then(r => console.log(r.data)).catch(console.error)
}

// use like this:
send_file({chat_id, file_path: 'html file location'})
roshanconnor123 commented 4 years ago

Thank you I will try to add this my own to the bot I am sure i will fail haha Will update here Thanks also..i should add the above function in gd.js yes?

iwestlin commented 4 years ago

better put it in tg.js, because it used a global variable tg_token then export this function in module.exports = {send_file} and require and use it in router.js (handle the callback data part)