let user can set the number of buttons per column in config.js

This commit is contained in:
liaojack8 2020-07-07 00:55:05 +08:00
parent a3b0c2c9bb
commit 2b05a01a94
2 changed files with 30 additions and 4 deletions

View File

@ -23,5 +23,5 @@ const AUTH = { // 如果您拥有service account的json授权文件可将其
//-------------------MOD-------------------
const SA_PATH = '../sa' //sa路徑配置, 給定絕對路徑或是以src為當前路徑給定相對路徑, 預設為'../sa'
module.exports = { AUTH, PARALLEL_LIMIT, RETRY_LIMIT, TIMEOUT_BASE, TIMEOUT_MAX, LOG_DELAY, PAGE_SIZE, DEFAULT_TARGET, SA_PATH }
const BUTTON_LEVEL = 1 //預設為1, 填入大於2皆視為2
module.exports = { AUTH, PARALLEL_LIMIT, RETRY_LIMIT, TIMEOUT_BASE, TIMEOUT_MAX, LOG_DELAY, PAGE_SIZE, DEFAULT_TARGET, SA_PATH, BUTTON_LEVEL }

View File

@ -92,7 +92,8 @@ 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: {
@ -105,16 +106,41 @@ function send_choice ({ fid, chat_id }) {
]
].concat(gen_bookmark_choices(fid))
}
})
})
}else{
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))
}
})
}
}
// 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