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 compromise from 'fr-compromise';
|
||||
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 = [
|
||||
', mon gars',
|
||||
', mec',
|
||||
", je crois",
|
||||
...Array(10).fill('')
|
||||
];
|
||||
|
|
@ -22,38 +9,43 @@ const suffixes = [
|
|||
export default class SuffixPrefixDetector extends Detector {
|
||||
async createSpecificReply(message) {
|
||||
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 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 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) {
|
||||
const parsed = compromiseMatch.json();
|
||||
const result = parsed[0];
|
||||
createResponse(prefixBrut, isSelfTarget = false) {
|
||||
// 2. On applique ta logique de nettoyage (trimPrefix) pour gérer le "ça"
|
||||
let replyPrefix = trimPrefix(prefixBrut);
|
||||
|
||||
let replyPrefix = trimPrefix(compromiseMatch.groups('prefix')?.text().trim() ?? '');
|
||||
const numberOfWordsInPrefix = replyPrefix.split(' ').length;
|
||||
if (numberOfWordsInPrefix > 7) {
|
||||
return null; // Too long, pass to next detector
|
||||
}
|
||||
const replysuffixToPrefix = compromiseMatch.groups('suffix2prefix')?.text().trim() ?? '';
|
||||
const replySuffix = compromiseMatch.groups('suffix')?.text().trim() ?? '';
|
||||
|
||||
if (result == null) {
|
||||
return '';
|
||||
// 3. Sécurité anti-spam (> 7 mots)
|
||||
// On vérifie qu'il reste quelque chose après le trim
|
||||
if (!replyPrefix || replyPrefix.split(' ').length > 7) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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) {
|
||||
return (prefix
|
||||
.split(/(?=(?:ç|c)a)/).at(-1) ?? '')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue