Skip to content

Commit

Permalink
feat: add +above for show_caption_above_media
Browse files Browse the repository at this point in the history
fix: disable single_caption in inline mode
  • Loading branch information
makeding committed Jun 15, 2024
1 parent a9e5cfd commit 42d893c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
7 changes: 6 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ async function tg_sender(ctx) {
if (!ctx.us) {
ctx.us = await read_user_setting(bot, ctx)
}
default_extra.show_caption_above_media = ctx.us.caption_above
let ids = ctx.ids
let illusts = []
// fetch authors' all illusts
Expand Down Expand Up @@ -342,6 +343,9 @@ async function tg_sender(ctx) {
if (ctx.us.spoiler) {
extra.has_spoiler = ctx.us.spoiler
}
if (ctx.us.caption_above) {
extra.show_caption_above_media = ctx.us.caption_above
}
if (illust.type <= 1) {
let { reply_to_message_id } = extra
await asyncForEach(illust.mediagroup, async (o, i) => {
Expand Down Expand Up @@ -404,7 +408,8 @@ async function tg_sender(ctx) {
})
let mg_extra = {
...default_extra,
has_spoiler: ctx.us.spoiler
has_spoiler: ctx.us.spoiler,
// show_caption_above_media: ctx.us.caption_above
}
if (mgs.length > 0) {
if (ctx.us.telegraph) {
Expand Down
22 changes: 12 additions & 10 deletions db.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ import config from './config.js'
import * as mongodb from 'mongodb'
const { MongoClient } = mongodb
export let db = {
collection: fake_collection
collection: dummy_collection
}
export let collection = {
illust: fake_collection(),
chat_setting: fake_collection(),
novel: fake_collection(),
ranking: fake_collection(),
author: fake_collection(),
telegraph: fake_collection()
illust: dummy_collection(),
chat_setting: dummy_collection(),
novel: dummy_collection(),
ranking: dummy_collection(),
author: dummy_collection(),
telegraph: dummy_collection()
}
export async function db_initial() {
if (!process.env.DBLESS) {
if (process.env.DBLESS) {
console.warn('WARNING','No Database Mode(DBLESS) is not recommend for production environment.')
} else {
try {
db = (await MongoClient.connect(config.mongodb.uri)).db(config.mongodb.dbname)
for (const key in collection) {
Expand Down Expand Up @@ -55,7 +57,7 @@ export async function update_setting(value, chat_id, flag) {
// throw 'e'
}
}
if (['tags', 'open', 'share', 'remove_keyboard', 'remove_caption', 'single_caption', 'album', 'album_one', 'album_equal', 'desc', 'overwrite', 'asfile', 'append_file', 'caption_extraction'].includes(i)) {
if (['tags', 'open', 'share', 'remove_keyboard', 'remove_caption', 'single_caption', 'album', 'album_one', 'album_equal', 'desc', 'overwrite', 'asfile', 'append_file', 'caption_extraction', 'caption_above'].includes(i)) {
if (typeof value.default[i] === 'boolean') {
s.default[i] = value.default[i]
}
Expand Down Expand Up @@ -140,7 +142,7 @@ export async function delete_setting(chat_id) {
* give null & modified data for dbless mode
* @returns {}
*/
function fake_collection() {
function dummy_collection() {
return {
find: () => { return null; },
findOne: () => { return null; },
Expand Down
2 changes: 2 additions & 0 deletions handlers/telegram/handle_illust.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export async function handle_illust(id, flag) {
photo_width: size.width,
photo_height: size.height,
parse_mode: 'MarkdownV2',
show_caption_above_media: flag.caption_above,
...k_os(illust.id, flag)
}
// but telegram doesn't support spoiler in inline mode
Expand All @@ -70,6 +71,7 @@ export async function handle_illust(id, flag) {
id: 'p' + illust.id,
caption: format(illust, flag, 'inline', 1),
parse_mode: 'MarkdownV2',
show_caption_above_media: flag.caption_above,
...options,
...k_os(illust.id, flag)
}
Expand Down
5 changes: 5 additions & 0 deletions handlers/telegram/pre_handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ export async function read_user_setting(bot, ctx) {
tags: (d_f.tags && !ctx.text.includes('-tag')) || ctx.text.includes('+tag'),
open: (d_f.open && !ctx.text.includes('-open')) || ctx.text.includes('+open'),
caption_extraction: (d_f.caption_extraction && !ctx.text.includes('-caption')) || ctx.text.includes('+caption'),
caption_above: (d_f.caption_above && !ctx.text.includes('-above')) || ctx.text.includes('+above'),

// can't use switch_inline_query in a channel chat, because a user will not be able to use the button without knowing bot's username
share: (ctx.type !== 'channel' && (d_f.share && !ctx.text.includes('-share')) || ctx.text.includes('+share')),
remove_keyboard: (d_f.remove_keyboard && !ctx.text.includes('+kb')) || ctx.text.includes('-kb'),
Expand Down Expand Up @@ -218,6 +220,9 @@ export async function read_user_setting(bot, ctx) {
if (ctx.us.remove_keyboard) {
ctx.us.open = ctx.us.share = false
}
if(ctx.type === 'inline'){
ctx.us.single_caption = false
}
if (ctx.message) {
let { title, author_name, author_url } = get_values(ctx.text.substring(0, 3) == '/s ' ? ctx.text.replace('/s ', '') : ctx.text)
let v = {}
Expand Down

0 comments on commit 42d893c

Please sign in to comment.