From 8e02892df084567b9e679b2418c795819a965117 Mon Sep 17 00:00:00 2001 From: Flummi Date: Tue, 2 May 2023 02:27:35 +0200 Subject: [PATCH] buttons fix --- src/inc/events/callback_query.mjs | 26 ++++++++++++++++++++------ src/inc/trigger/debug.mjs | 1 + src/inc/trigger/parser.mjs | 4 ++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/inc/events/callback_query.mjs b/src/inc/events/callback_query.mjs index 1a07e48..2bbe9c5 100644 --- a/src/inc/events/callback_query.mjs +++ b/src/inc/events/callback_query.mjs @@ -110,7 +110,7 @@ export default async bot => { if(!id) return; - if(!(await lib.getTags(id)).filter(tag => tag.id == 1).length) { + if(!await lib.hasTag(id, 1)) { // insert await db` insert into "tags_assign" ${ @@ -121,6 +121,13 @@ export default async bot => { }) } `; + if(await lib.hasTag(id, 2)) { + await db` + delete from "tags_assign" + where tag_id = 2 + and item_id = ${id} + `; + } } else { // delete @@ -134,8 +141,8 @@ export default async bot => { return await e.editMessageText(e.raw.chat.id, e.raw.message_id, e.message, { reply_markup: JSON.stringify({ inline_keyboard: [[ - { text: '✓ sfw', callback_data: `b_sfw:${id}` }, - { text: 'nsfw', callback_data: `b_nsfw:${id}` }, + { text: (await lib.hasTag(id, 1) ? '✓ ' : '') + 'sfw', callback_data: `b_sfw:${id}` }, + { text: (await lib.hasTag(id, 2) ? '✓ ' : '') + 'nsfw', callback_data: `b_nsfw:${id}` }, { text: 'tags', callback_data: `b_tags:${id}` }, { text: '❌ delete', callback_data: `b_delete:${id}` } ], [ @@ -149,7 +156,7 @@ export default async bot => { if(!id) return; - if(!(await lib.getTags(id)).filter(tag => tag.id == 2).length) { + if(!await lib.hasTag(id, 2)) { // insert await db` insert into "tags_assign" ${ @@ -160,6 +167,13 @@ export default async bot => { }) } `; + if(await lib.hasTag(id, 1)) { + await db` + delete from "tags_assign" + where tag_id = 1 + and item_id = ${id} + `; + } } else { // delete @@ -173,8 +187,8 @@ export default async bot => { return await e.editMessageText(e.raw.chat.id, e.raw.message_id, e.message, { reply_markup: JSON.stringify({ inline_keyboard: [[ - { text: 'sfw', callback_data: `b_sfw:${id}` }, - { text: '✓ nsfw', callback_data: `b_nsfw:${id}` }, + { text: (await lib.hasTag(id, 1) ? '✓ ' : '') + 'sfw', callback_data: `b_sfw:${id}` }, + { text: (await lib.hasTag(id, 2) ? '✓ ' : '') + 'nsfw', callback_data: `b_nsfw:${id}` }, { text: 'tags', callback_data: `b_tags:${id}` }, { text: '❌ delete', callback_data: `b_delete:${id}` } ], [ diff --git a/src/inc/trigger/debug.mjs b/src/inc/trigger/debug.mjs index 7d1c6a6..7e5222e 100644 --- a/src/inc/trigger/debug.mjs +++ b/src/inc/trigger/debug.mjs @@ -9,6 +9,7 @@ let context = vm.createContext({ bot: null, admins: null, fetch: fetch, + lib: lib, a: null, resolve: null diff --git a/src/inc/trigger/parser.mjs b/src/inc/trigger/parser.mjs index 766708e..3b153ce 100644 --- a/src/inc/trigger/parser.mjs +++ b/src/inc/trigger/parser.mjs @@ -209,8 +209,8 @@ export default async bot => { await e.reply(outputmsgtg, { reply_markup: JSON.stringify({ inline_keyboard: [[ - { text: 'sfw', callback_data: `b_sfw:${itemid}` }, - { text: 'nsfw', callback_data: `b_nsfw:${itemid}` }, + { text: (await lib.hasTag(itemid, 1) ? '✓ ' : '') + 'sfw', callback_data: `b_sfw:${itemid}` }, + { text: (await lib.hasTag(itemid, 2) ? '✓ ' : '') + 'nsfw', callback_data: `b_nsfw:${itemid}` }, { text: 'tags', callback_data: `b_tags:${itemid}` }, { text: '❌ delete', callback_data: `b_delete:${itemid}` } ], [