Merge pull request 'master' (#16) from master into f0ckv2
Reviewed-on: #16
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { getLevel } from "../admin.mjs";
|
import { getLevel } from "../admin.mjs";
|
||||||
|
import cfg from "../config.mjs";
|
||||||
|
|
||||||
export default async self => {
|
export default async self => {
|
||||||
return [{
|
return [{
|
||||||
@@ -45,10 +46,11 @@ export default async self => {
|
|||||||
// Deduplicate and sort
|
// Deduplicate and sort
|
||||||
const uniqueCommands = [...new Set(availableCommands)].sort();
|
const uniqueCommands = [...new Set(availableCommands)].sort();
|
||||||
|
|
||||||
|
const trigger = cfg.main.trigger || "!w";
|
||||||
if (uniqueCommands.length === 0) {
|
if (uniqueCommands.length === 0) {
|
||||||
availableCommands.push(e.type === 'matrix' ? "!w -sfw/nsfw -t tag1,tag2,tag3" : "!w <url> or attachment");
|
availableCommands.push(e.type === 'matrix' ? `${trigger} -sfw/nsfw -t tag1,tag2,tag3` : `${trigger} <url> or attachment`);
|
||||||
} else {
|
} else {
|
||||||
availableCommands.push(e.type === 'matrix' ? "!w -sfw/nsfw -t tag1,tag2,tag3" : "!w <url> or attachment");
|
availableCommands.push(e.type === 'matrix' ? `${trigger} -sfw/nsfw -t tag1,tag2,tag3` : `${trigger} <url> or attachment`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-sort to include manually added command
|
// Re-sort to include manually added command
|
||||||
|
|||||||
@@ -37,11 +37,14 @@ const extractJSON = (stdout) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const trigger = cfg.main.trigger || "!w";
|
||||||
|
const escapedTrigger = trigger.replace(/[.*+?^${}()|[\\]\\]/g, '\\$&');
|
||||||
|
|
||||||
export default async bot => {
|
export default async bot => {
|
||||||
|
|
||||||
return [{
|
return [{
|
||||||
name: "parser",
|
name: "parser",
|
||||||
call: new RegExp(`${regex.all.source}|^!w(0bm)?\\b`, 'i'),
|
call: new RegExp(`${regex.all.source}|^${escapedTrigger}(0bm)?\\b`, 'i'),
|
||||||
active: true,
|
active: true,
|
||||||
clients: ["irc", "tg", "slack", "discord", "matrix"],
|
clients: ["irc", "tg", "slack", "discord", "matrix"],
|
||||||
f: async e => {
|
f: async e => {
|
||||||
@@ -121,7 +124,7 @@ export default async bot => {
|
|||||||
|
|
||||||
const fileUrl = await tgClient.getFile(mediaObj.file_id);
|
const fileUrl = await tgClient.getFile(mediaObj.file_id);
|
||||||
if (fileUrl) {
|
if (fileUrl) {
|
||||||
console.log(`[PARSER] TG reply media resolved: ${fileUrl}`);
|
console.log(`[PARSER] TG reply media resolved: ${fileUrl.replace(/\/bot[0-9a-zA-Z_-]+/i, '/bot<token>')}`);
|
||||||
links.push(fileUrl);
|
links.push(fileUrl);
|
||||||
} else {
|
} else {
|
||||||
await e.reply('Could not resolve the replied-to file. It may be too large (>20MB) for the Telegram Bot API.');
|
await e.reply('Could not resolve the replied-to file. It may be too large (>20MB) for the Telegram Bot API.');
|
||||||
@@ -155,7 +158,7 @@ export default async bot => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check for !w command
|
// Check for !w command
|
||||||
const isWCommand = e.message.match(/\!w(0bm)?\b/i);
|
const isWCommand = e.message.match(new RegExp(`${escapedTrigger}(0bm)?\\b`, 'i'));
|
||||||
|
|
||||||
// Matrix / Telegram: enforce strict !w format with rating + tags
|
// Matrix / Telegram: enforce strict !w format with rating + tags
|
||||||
let botRating = null; // 'sfw' or 'nsfw'
|
let botRating = null; // 'sfw' or 'nsfw'
|
||||||
@@ -172,7 +175,7 @@ export default async bot => {
|
|||||||
|
|
||||||
// Bare !w with no arguments → show help
|
// Bare !w with no arguments → show help
|
||||||
if (!hasRating && !hasTags) {
|
if (!hasRating && !hasTags) {
|
||||||
await e.reply(`!w -sfw/-nsfw -t tag1,tag2,tag3 (at least ${getMinTags()} tags required)`);
|
await e.reply(`${trigger} -sfw/-nsfw -t tag1,tag2,tag3 (at least ${getMinTags()} tags required)`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +187,7 @@ export default async bot => {
|
|||||||
|
|
||||||
// Missing rating
|
// Missing rating
|
||||||
if (!hasRating) {
|
if (!hasRating) {
|
||||||
await e.reply('missing rating: !w -sfw/-nsfw -t tag1,tag2,tag3');
|
await e.reply(`missing rating: ${trigger} -sfw/-nsfw -t tag1,tag2,tag3`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +204,7 @@ export default async bot => {
|
|||||||
} else {
|
} else {
|
||||||
// Remove links, !w and -sfw/nsfw to get tags
|
// Remove links, !w and -sfw/nsfw to get tags
|
||||||
tagsInput = e.message.replace(regex.all, "")
|
tagsInput = e.message.replace(regex.all, "")
|
||||||
.replace(/\!w(0bm)?\b/i, "")
|
.replace(new RegExp(`${escapedTrigger}(0bm)?\\b`, 'i'), "")
|
||||||
.replace(/\s*-(nsfw|sfw)\b/gi, "")
|
.replace(/\s*-(nsfw|sfw)\b/gi, "")
|
||||||
.replace(/\s*-t\b/gi, "")
|
.replace(/\s*-t\b/gi, "")
|
||||||
.trim();
|
.trim();
|
||||||
@@ -211,7 +214,7 @@ export default async bot => {
|
|||||||
botTags = tagsInput.split(',').map(t => t.trim()).filter(t => t.length > 0);
|
botTags = tagsInput.split(',').map(t => t.trim()).filter(t => t.length > 0);
|
||||||
|
|
||||||
if (botTags.length < minTags) {
|
if (botTags.length < minTags) {
|
||||||
await e.reply(`at least ${minTags} tags required (got ${botTags.length}): !w -sfw/-nsfw -t tag1, tag2, tag3`);
|
await e.reply(`at least ${minTags} tags required (got ${botTags.length}): ${trigger} -sfw/-nsfw -t tag1, tag2, tag3`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,7 +223,8 @@ export default async bot => {
|
|||||||
const isForwarded = e.raw?.forward_from !== undefined;
|
const isForwarded = e.raw?.forward_from !== undefined;
|
||||||
const mediaGroupId = e.raw?.media_group_id;
|
const mediaGroupId = e.raw?.media_group_id;
|
||||||
|
|
||||||
if ((e.type === 'matrix' || !e.channel.includes("w0bm")) && (!isWCommand && !isForwarded)) {
|
const channelKeyword = (cfg.main.upload_channel_keyword || "w0bm").toLowerCase();
|
||||||
|
if ((e.type === 'matrix' || !e.channel.toLowerCase().includes(channelKeyword)) && (!isWCommand && !isForwarded)) {
|
||||||
console.log(`[PARSER DEBUG] Channel/Client check failed. Channel: ${e.channel}, Type: ${e.type}, IsW: ${!!isWCommand}`);
|
console.log(`[PARSER DEBUG] Channel/Client check failed. Channel: ${e.channel}, Type: ${e.type}, IsW: ${!!isWCommand}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -296,10 +300,11 @@ export default async bot => {
|
|||||||
|
|
||||||
// Use for..of to handle async await properly and serialize debugging
|
// Use for..of to handle async await properly and serialize debugging
|
||||||
for (const link of links) {
|
for (const link of links) {
|
||||||
console.log(`[PARSER LOOP] Processing link: ${link}`);
|
const sanitizedLink = link.replace(/\/bot[0-9a-zA-Z_-]+/i, '/bot<token>');
|
||||||
|
console.log(`[PARSER LOOP] Processing link: ${sanitizedLink}`);
|
||||||
// check repost (link)
|
// check repost (link)
|
||||||
try {
|
try {
|
||||||
repost = await queue.checkrepostlink(link);
|
repost = await queue.checkrepostlink(sanitizedLink);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`[PARSER LOOP] Checkrepost failed:`, e);
|
console.error(`[PARSER LOOP] Checkrepost failed:`, e);
|
||||||
}
|
}
|
||||||
@@ -739,7 +744,7 @@ export default async bot => {
|
|||||||
|
|
||||||
await db`
|
await db`
|
||||||
insert into items ${db({
|
insert into items ${db({
|
||||||
src: e.media ? "" : link,
|
src: (e.media || link.includes('api.telegram.org') || link.startsWith('mxc://')) ? "" : link,
|
||||||
dest: filename,
|
dest: filename,
|
||||||
mime: mime,
|
mime: mime,
|
||||||
size: size,
|
size: size,
|
||||||
@@ -845,7 +850,7 @@ export default async bot => {
|
|||||||
|
|
||||||
await db`
|
await db`
|
||||||
insert into items ${db({
|
insert into items ${db({
|
||||||
src: e.media ? "" : link,
|
src: (e.media || link.includes('api.telegram.org') || link.startsWith('mxc://')) ? "" : link,
|
||||||
dest: filename,
|
dest: filename,
|
||||||
mime: mime,
|
mime: mime,
|
||||||
size: size,
|
size: size,
|
||||||
|
|||||||
Reference in New Issue
Block a user