tagkeyboard
All checks were successful
fetch npm modules / f0ck the f0cker (push) Successful in 41s

This commit is contained in:
Flummi 2023-05-01 17:21:26 +02:00
parent 4e6b337d4f
commit 9ccf17ac54

View File

@ -5,23 +5,7 @@ import cfg from "../config.mjs";
import db from "../sql.mjs";
import lib from "../lib.mjs";
export default async bot => {
return [{
name: "callback_query",
listener: "callback_query",
f: async e => {
logger.info(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}`);
let [ cmd, id ] = e.opt.data.split(':');
let f0ck;
id = +id;
switch(cmd) {
case "b_tags":
if(!id)
return;
const tagkeyboard = id => {
const tags = [{
tag: 'music',
id: 115
@ -35,7 +19,64 @@ export default async bot => {
tag: 'doggo',
id: 5
}];
const keyboard = await Promise.all(tags.map(async t => ({ text: `${await lib.hasTag(id, t.id) ? '✓ ' : ''}${t.tag}`, callback_data: `b_${t.tag}:${id}` })));
return Promise.all(tags.map(async t => ({ text: `${await lib.hasTag(id, t.id) ? '✓ ' : ''}${t.tag}`, callback_data: `b_settag_${t.id}:${id}` })));
};
export default async bot => {
return [{
name: "callback_query",
listener: "callback_query",
f: async e => {
logger.info(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}`);
let [ cmd, id ] = e.opt.data.split(':');
let f0ck;
id = +id;
if(cmd.startsWith('b_settag_')) {
const tagid = +cmd.replace('b_settag_', '');
if(!(await lib.getTags(id)).filter(tag => tag.id == tagid).length) {
// insert
await db`
insert into "tags_assign" ${
db({
item_id: id,
tag_id: tagid,
user_id: 1
})
}
`;
}
else {
// delete
await db`
delete from "tags_assign"
where tag_id = ${tagid}
and item_id = ${id}
`;
}
const keyboard = await tagkeyboard(id);
return await e.editMessageText(e.raw.chat.id, e.raw.message_id, e.message, {
reply_markup: JSON.stringify({
inline_keyboard: [[
...keyboard
], [
{ text: 'back', callback_data: `b_back:${id}` }
]]
})
});
}
switch(cmd) {
case "b_tags":
if(!id)
return;
const keyboard = await tagkeyboard(id);
await e.editMessageText(e.raw.chat.id, e.raw.message_id, e.message, {
reply_markup: JSON.stringify({
@ -69,7 +110,7 @@ export default async bot => {
if(!id)
return;
if(!(await lib.getTags(id)).filter(tag => [1,2].includes(tag.id)).length) {
if(!(await lib.getTags(id)).filter(tag => tag.id == 1).length) {
// insert
await db`
insert into "tags_assign" ${
@ -82,16 +123,15 @@ export default async bot => {
`;
}
else {
// update
// delete
await db`
update "tags_assign" set tag_id = 1
where
tag_id = 2 and
item_id = ${id}
delete from "tags_assign"
where tag_id = 1
and item_id = ${id}
`;
}
await e.editMessageText(e.raw.chat.id, e.raw.message_id, e.message, {
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}` },
@ -109,7 +149,7 @@ export default async bot => {
if(!id)
return;
if(!(await lib.getTags(id)).filter(tag => [1,2].includes(tag.id)).length) {
if(!(await lib.getTags(id)).filter(tag => tag.id == 2).length) {
// insert
await db`
insert into "tags_assign" ${
@ -122,16 +162,15 @@ export default async bot => {
`;
}
else {
// update
// delete
await db`
update "tags_assign" set tag_id = 2
where
tag_id = 1 and
item_id = ${id}
delete from "tags_assign"
where tag_id = 2
and item_id = ${id}
`;
}
await e.editMessageText(e.raw.chat.id, e.raw.message_id, e.message, {
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}` },