BANGER DIFF
This commit is contained in:
parent
4bc1a9fb74
commit
7bd846f277
1 changed files with 23 additions and 31 deletions
|
|
@ -1,20 +1,7 @@
|
||||||
import Detector from "./Detector.js";
|
import Detector from "./Detector.js";
|
||||||
import compromise from 'fr-compromise';
|
|
||||||
import { cleanMessageContent } from "../utils/strings.js";
|
import { cleanMessageContent } from "../utils/strings.js";
|
||||||
|
|
||||||
/*if the beginning of the sentence (before trigger) is less than 7 words then drop
|
|
||||||
otherwise copy the sentence and adjust
|
|
||||||
exemple : on mange quoi ce midi ? on mange feur ce midi
|
|
||||||
|
|
||||||
does not conjugate
|
|
||||||
|
|
||||||
cut to "ça" or "ca" if used
|
|
||||||
exemple : c'est quoi ce truc ? c'est feur ce truc
|
|
||||||
*/
|
|
||||||
|
|
||||||
const suffixes = [
|
const suffixes = [
|
||||||
', mon gars',
|
|
||||||
', mec',
|
|
||||||
", je crois",
|
", je crois",
|
||||||
...Array(10).fill('')
|
...Array(10).fill('')
|
||||||
];
|
];
|
||||||
|
|
@ -22,38 +9,43 @@ const suffixes = [
|
||||||
export default class SuffixPrefixDetector extends Detector {
|
export default class SuffixPrefixDetector extends Detector {
|
||||||
async createSpecificReply(message) {
|
async createSpecificReply(message) {
|
||||||
const reference = await message.fetchReference().catch(() => null);
|
const reference = await message.fetchReference().catch(() => null);
|
||||||
// check if it's a reply to the bot
|
|
||||||
const isSelfTarget = (reference && reference.author.id === message.client.user?.id) ?? false;
|
const isSelfTarget = (reference && reference.author.id === message.client.user?.id) ?? false;
|
||||||
|
|
||||||
const compromiseMatch = compromise(cleanMessageContent(message).toLowerCase()).match(`[<prefix>(!quoi){0,2} (#Verb|faire)? #Preposition?] quoi [<suffix2prefix>#Verb]? [<suffix>(#Determiner !quoi|!quoi)?]?$`);
|
const text = cleanMessageContent(message);
|
||||||
|
|
||||||
if (compromiseMatch == null || compromiseMatch.length === 0) {
|
// 1. Regex simple : On capture TOUT ce qu'il y a avant le mot "quoi" (Groupe 1)
|
||||||
|
// (?:^|\s) assure qu'on ne coupe pas "pourquoi"
|
||||||
|
const match = text.match(/^(.*)(?:^|\s)quoi(?:\W|$)/i);
|
||||||
|
|
||||||
|
if (!match) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.conjugateResponse(compromiseMatch, isSelfTarget);
|
// match[1] contient tout le texte avant le "quoi"
|
||||||
|
const prefixBrut = match[1];
|
||||||
|
|
||||||
|
return this.createResponse(prefixBrut, isSelfTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
conjugateResponse(compromiseMatch, isSelfTarget = false) {
|
createResponse(prefixBrut, isSelfTarget = false) {
|
||||||
const parsed = compromiseMatch.json();
|
// 2. On applique ta logique de nettoyage (trimPrefix) pour gérer le "ça"
|
||||||
const result = parsed[0];
|
let replyPrefix = trimPrefix(prefixBrut);
|
||||||
|
|
||||||
let replyPrefix = trimPrefix(compromiseMatch.groups('prefix')?.text().trim() ?? '');
|
// 3. Sécurité anti-spam (> 7 mots)
|
||||||
const numberOfWordsInPrefix = replyPrefix.split(' ').length;
|
// On vérifie qu'il reste quelque chose après le trim
|
||||||
if (numberOfWordsInPrefix > 7) {
|
if (!replyPrefix || replyPrefix.split(' ').length > 7) {
|
||||||
return null; // Too long, pass to next detector
|
return null;
|
||||||
}
|
|
||||||
const replysuffixToPrefix = compromiseMatch.groups('suffix2prefix')?.text().trim() ?? '';
|
|
||||||
const replySuffix = compromiseMatch.groups('suffix')?.text().trim() ?? '';
|
|
||||||
|
|
||||||
if (result == null) {
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (`${replyPrefix} ${replysuffixToPrefix} feur ${replySuffix.length > 0 ? ` ${replySuffix}` : ''}${suffixes[Math.floor(Math.random() * suffixes.length)]}`).trim().replaceAll(' ', ' ').replace(' ,', ',');
|
// 4. On renvoie : Préfixe nettoyé + Feur
|
||||||
|
return (`${replyPrefix} feur ${suffixes[Math.floor(Math.random() * suffixes.length)]}`)
|
||||||
|
.trim()
|
||||||
|
.replaceAll(' ', ' ')
|
||||||
|
.replace(' ,', ',');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ta fonction (inchangée, elle sert à nettoyer le début)
|
||||||
function trimPrefix(prefix) {
|
function trimPrefix(prefix) {
|
||||||
return (prefix
|
return (prefix
|
||||||
.split(/(?=(?:ç|c)a)/).at(-1) ?? '')
|
.split(/(?=(?:ç|c)a)/).at(-1) ?? '')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue