let user can set the number of buttons per column in config.js
This commit is contained in:
parent
a3b0c2c9bb
commit
2b05a01a94
|
@ -23,5 +23,5 @@ const AUTH = { // 如果您拥有service account的json授权文件,可将其
|
||||||
|
|
||||||
//-------------------MOD-------------------
|
//-------------------MOD-------------------
|
||||||
const SA_PATH = '../sa' //sa路徑配置, 給定絕對路徑或是以src為當前路徑給定相對路徑, 預設為'../sa'
|
const SA_PATH = '../sa' //sa路徑配置, 給定絕對路徑或是以src為當前路徑給定相對路徑, 預設為'../sa'
|
||||||
|
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 }
|
module.exports = { AUTH, PARALLEL_LIMIT, RETRY_LIMIT, TIMEOUT_BASE, TIMEOUT_MAX, LOG_DELAY, PAGE_SIZE, DEFAULT_TARGET, SA_PATH, BUTTON_LEVEL }
|
||||||
|
|
30
src/tg.js
30
src/tg.js
|
@ -92,7 +92,8 @@ function get_target_by_alias (alias) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function send_choice ({ fid, chat_id }) {
|
function send_choice ({ fid, chat_id }) {
|
||||||
return sm({
|
if(BUTTON_LEVEL == 1){
|
||||||
|
return sm({
|
||||||
chat_id,
|
chat_id,
|
||||||
text: `辨識到分享ID ${fid},請選擇動作`,
|
text: `辨識到分享ID ${fid},請選擇動作`,
|
||||||
reply_markup: {
|
reply_markup: {
|
||||||
|
@ -105,16 +106,41 @@ function send_choice ({ fid, chat_id }) {
|
||||||
]
|
]
|
||||||
].concat(gen_bookmark_choices(fid))
|
].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())
|
// console.log(gen_bookmark_choices())
|
||||||
function gen_bookmark_choices (fid) {
|
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 gen_choice = v => ({text: `複製到 ${v.alias}`, callback_data: `copy ${fid} ${v.alias}`})
|
||||||
const records = db.prepare('select * from bookmark').all()
|
const records = db.prepare('select * from bookmark').all()
|
||||||
|
db.close()
|
||||||
const result = []
|
const result = []
|
||||||
for (let i = 0; i < records.length; i++) {
|
for (let i = 0; i < records.length; i++) {
|
||||||
const line = [gen_choice(records[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)
|
result.push(line)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in New Issue