diff --git a/config.js b/config.js index a5be9169..feace787 100644 --- a/config.js +++ b/config.js @@ -21,4 +21,8 @@ const AUTH = { // 如果您拥有service account的json授权文件,可将其 tg_whitelist: ['your_tg_username'] // 你的tg username(t.me/username),bot只会执行这个列表里的用户所发送的指令 } -module.exports = { AUTH, PARALLEL_LIMIT, RETRY_LIMIT, TIMEOUT_BASE, TIMEOUT_MAX, LOG_DELAY, PAGE_SIZE, DEFAULT_TARGET } +const BUTTON_LEVEL = 1 // Default as 1, all number large than 2 will be judge as 2. + +const SA_PATH = '../sa' // Default as '../sa' + +module.exports = { AUTH, PARALLEL_LIMIT, RETRY_LIMIT, TIMEOUT_BASE, TIMEOUT_MAX, LOG_DELAY, PAGE_SIZE, DEFAULT_TARGET, BUTTON_LEVEL, SA_PATH } diff --git a/src/gd.js b/src/gd.js index 73262685..de3849f9 100644 --- a/src/gd.js +++ b/src/gd.js @@ -8,7 +8,7 @@ const HttpsProxyAgent = require('https-proxy-agent') const { GoogleToken } = require('gtoken') const handle_exit = require('signal-exit') -const { AUTH, RETRY_LIMIT, PARALLEL_LIMIT, TIMEOUT_BASE, TIMEOUT_MAX, LOG_DELAY, PAGE_SIZE, DEFAULT_TARGET } = require('../config') +const { AUTH, RETRY_LIMIT, PARALLEL_LIMIT, TIMEOUT_BASE, TIMEOUT_MAX, LOG_DELAY, PAGE_SIZE, DEFAULT_TARGET, SA_PATH } = require('../config') const { db } = require('../db') const { make_table, make_tg_table, make_html, summary } = require('./summary') @@ -18,7 +18,7 @@ const { https_proxy } = process.env const axins = axios.create(https_proxy ? { httpsAgent: new HttpsProxyAgent(https_proxy) } : {}) const SA_BATCH_SIZE = 1000 -const SA_FILES = fs.readdirSync(path.join(__dirname, '../sa')).filter(v => v.endsWith('.json')) +const SA_FILES = fs.readdirSync(path.join(__dirname, SA_PATH)).filter(v => v.endsWith('.json')) SA_FILES.flag = 0 let SA_TOKENS = get_sa_batch() diff --git a/src/tg.js b/src/tg.js index 5677fd1e..1e0e7ac3 100644 --- a/src/tg.js +++ b/src/tg.js @@ -9,7 +9,7 @@ const { AUTH, DEFAULT_TARGET, USE_PERSONAL_AUTH } = require('../config') const { tg_token } = AUTH const gen_link = (fid, text) => `${text || fid}` -if (!tg_token) throw new Error('请先在auth.js里设置tg_token') +if (!tg_token) throw new Error('请先在config.js里设置tg_token') const { https_proxy } = process.env const axins = axios.create(https_proxy ? { httpsAgent: new HttpsProxyAgent(https_proxy) } : {}) @@ -92,7 +92,23 @@ function get_target_by_alias (alias) { } function send_choice ({ fid, chat_id }) { - return sm({ + if(BUTTON_LEVEL == 1){ + return sm({ + chat_id, + text: `识别出分享ID ${fid},请选择动作`, + reply_markup: { + inline_keyboard: [ + [ + { text: '文件统计', callback_data: `count ${fid}` } + ], + [ + { text: '开始复制', callback_data: `copy ${fid}` } + ] + ].concat(gen_bookmark_choices(fid)) + } + }) + }else{ + return sm({ chat_id, text: `识别出分享ID ${fid},请选择动作`, reply_markup: { @@ -103,7 +119,31 @@ function send_choice ({ fid, chat_id }) { ] ].concat(gen_bookmark_choices(fid)) } - }) + }) + } +} + +// console.log(gen_bookmark_choices()) +function gen_bookmark_choices (fid) { + let level = 1 + if (BUTTON_LEVEL > 2){ + level = 2 + }else{ + level = BUTTON_LEVEL + } + const gen_choice = v => ({text: `复制到 ${v.alias}`, callback_data: `copy ${fid} ${v.alias}`}) + const records = db.prepare('select * from bookmark').all() + db.close() + const result = [] + for (let i = 0; i < records.length; i++) { + const line = [gen_choice(records[i])] + for(let j = 0; j < level-1; j ++){ + if (records[i+1]) line.push(gen_choice(records[i+1])) + i++ + } + result.push(line) + } + return result } // console.log(gen_bookmark_choices())