use super::{has, starts, words, THINGS};
pub fn message(text: &str) -> bool {
let t = text.trim();
again_burst(t) || bare(t) || style(t) || sarcastic(t)
}
fn again_burst(t: &str) -> bool {
t.starts_with("again?") || t.starts_with("again!")
}
fn canon(x: &str) -> &str {
if x.len() >= 2 && x.starts_with('n') && x.chars().all(|c| c == 'n' || c == 'o') {
"no"
} else if x.starts_with("nah") && x.chars().skip(2).all(|c| c == 'h') {
"nah"
} else {
x
}
}
fn trim_noise<'a>(w: &'a [&'a str]) -> &'a [&'a str] {
let mut w = w;
while let Some((f, rest)) = w.split_first() {
if matches!(*f, "dude" | "bro" | "man" | "ugh" | "hey" | "oh" | "omg" | "ffs" | "please" | "uh" | "um") {
w = rest;
} else {
break;
}
}
while let Some((l, rest)) = w.split_last() {
if matches!(*l, "please" | "now" | "man" | "dude" | "bro") {
w = rest;
} else {
break;
}
}
w
}
fn bare(t: &str) -> bool {
let all = words(t);
let w = trim_noise(&all);
if w.is_empty() || w.len() > 7 {
return false;
}
let sq: Vec<&str> = w.iter().map(|x| canon(x)).collect();
let refusal = |x: &str| matches!(x, "no" | "nope" | "nah" | "nop" | "naw");
if matches!(sq[0], "undo" | "revert" | "rollback" | "reset") && sq.len() >= 2 {
const TAIL: &[&str] = &[
"that", "this", "it", "the", "last", "previous", "change", "changes", "edit", "edits", "commit", "step", "what", "you",
"just", "did", "your", "my", "all", "everything", "back", "please", "now", "thing", "one", "work", "stuff",
];
if sq[1..].iter().all(|x| TAIL.contains(x)) {
return true;
}
}
if sq[0] == "put" && sq.len() >= 3 && matches!(sq[1], "it" | "that" | "this" | "everything" | "them") && sq[2] == "back" && sq[3..].iter().all(|x| matches!(*x, "the" | "way" | "it" | "was" | "as" | "before" | "where" | "original" | "place" | "how" | "please")) {
return true;
}
if sq[0] == "don't" && sq.len() <= 3 && sq[1..].iter().all(|x| matches!(*x, "do" | "touch" | "that" | "it" | "this" | "change" | "delete" | "move" | "push" | "commit" | "run" | "edit")) {
return true;
}
if matches!(sq.as_slice(), ["enough"] | ["enough", "already"] | ["cut", "it", "out"] | ["knock", "it", "off"] | ["quit", "it"] | ["worse"] | ["even", "worse"] | ["much", "worse"] | ["that's", "worse"] | ["nope", "that's", "worse"] | ["no", "that's", "worse"] | ["wrong", "approach"] | ["wrong", "way"]) {
return true;
}
if sq.len() == 3 && sq[0] == "not" && matches!(sq[1], "that" | "this" | "the") && THINGS.contains(&sq[2]) {
return true;
}
if matches!(sq.as_slice(), ["reverse", "that" | "it" | "this"]) {
return true;
}
if sq.len() >= 3 && sq[0] == "go" && sq[1] == "back" && sq[2..].iter().all(|x| matches!(*x, "to" | "how" | "the" | "way" | "it" | "was" | "before" | "previous" | "original" | "state" | "version" | "please")) {
return true;
}
if sq.len() >= 2 && sq.iter().all(|x| *x == sq[0]) && (refusal(sq[0]) || matches!(sq[0], "stop" | "wrong" | "undo" | "revert")) {
return true;
}
if matches!(sq.as_slice(), ["reset", "it" | "that" | "this"] | ["take", "that" | "it", "back"] | ["not", "this", "one"] | ["bad", "idea"] | ["that's", "not", "it"] | ["not", "it"] | ["no", "that", "one"] | ["wrong", "idea"] | ["not", "that", "one"] | ["not", "this"] | ["that", "was", "wrong"] | ["not", "correct"]) {
return true;
}
match sq.as_slice() {
[a] if refusal(a) || matches!(*a, "wrong" | "incorrect" | "stop" | "undo" | "revert" | "bad" | "rollback") => true,
[a, b] => {
(refusal(a) && (refusal(b) || matches!(*b, "stop" | "wait" | "wrong" | "that" | "it" | "again")))
|| (matches!(*a, "wait" | "hold") && (refusal(b) || *b == "stop"))
|| (matches!(*a, "wrong") && matches!(*b, "one" | "again" | "file" | "branch"))
|| (matches!(*a, "stop" | "undo" | "revert" | "cancel") && matches!(*b, "it" | "that" | "this" | "stop"))
|| (*a == "not" && matches!(*b, "that" | "right" | "correct"))
|| (matches!(*a, "that's" | "thats") && matches!(*b, "wrong" | "incorrect"))
|| (*a == "roll" && *b == "back")
|| (*a == "go" && *b == "back")
}
[a, b, c] => {
(matches!(*a, "hold") && *b == "on" && (refusal(c) || *c == "stop"))
|| (refusal(a) && refusal(b) && refusal(c))
|| (*a == "roll" && matches!(*b, "it" | "that") && *c == "back")
|| (*a == "not" && *b == "like" && *c == "that")
|| (*a == "not" && *b == "that" && *c == "one")
|| (matches!(*a, "that's" | "thats") && *b == "not" && matches!(*c, "right" | "correct"))
|| (*a == "that" && *b == "is" && matches!(*c, "wrong" | "incorrect"))
|| (matches!(*a, "undo" | "revert") && matches!(*b, "the") && *c == "change")
|| (refusal(a) && matches!(*b, "that" | "it") && matches!(*c, "wrong" | "again"))
|| (matches!(*a, "nope" | "no") && *b == "wrong" && *c == "again")
}
[a, b, c, d] => {
(matches!(*a, "undo" | "revert") && *b == "the" && matches!(*c, "last" | "previous") && matches!(*d, "change" | "edit" | "step" | "one"))
|| (*a == "nope" && *b == "wrong" && *c == "again")
}
_ => false,
}
}
fn style(t: &str) -> bool {
const ADJ: &[&str] = &[
"long", "verbose", "wordy", "formal", "chatty", "much", "many", "complicated", "complex", "clever", "casual",
"detailed", "technical", "lengthy", "polite", "friendly", "cute", "smart", "fancy", "dense", "vague", "abstract",
];
let w = words(t);
if w.len() > 14 {
return false;
}
if let Some(i) = w.iter().position(|x| *x == "too") {
let before_ok = w[..i].iter().all(|x| matches!(*x, "way" | "a" | "bit" | "little" | "much" | "far" | "this" | "is" | "it's" | "that's" | "its" | "that" | "it" | "just" | "really" | "so" | "wow" | "dude"));
if before_ok && i <= 4 && w.get(i + 1).is_some_and(|a| ADJ.contains(a)) && !matches!(w.get(i + 2), Some(&"to") | Some(&"for")) {
return true;
}
}
if w.len() > 7 {
return false;
}
let mut t = t;
for polite in ["can you ", "could you ", "would you ", "please ", "just ", "pls ", "now "] {
if let Some(r) = t.strip_prefix(polite) {
t = r.trim_start();
}
}
const OPENERS: &[&str] = &[
"brief please", "simpler please", "less explanation", "less detail", "less details", "fewer words", "no walls of text",
"no wall of text", "keep answers short", "keep replies short", "keep responses short", "keep answers brief",
"keep it shorter", "just give me the code", "give me the code", "only the code", "code only", "just the code", "give me the code only",
"stop explaining", "don't explain", "no need to explain", "less talking", "less words", "fewer details",
"shorter answers", "shorter replies", "shorter responses", "more brief", "more succinct", "be succinct",
"briefer", "simpler", "more concise please", "make it concise", "make it brief", "make it terse", "make that shorter",
"shorter", "shorten it", "shorten that", "make it shorter", "make it short", "make it simpler", "make it more concise",
"make it less verbose", "make it briefer", "make it tighter", "make that shorter", "keep it short", "keep it brief",
"keep it simple", "keep it tight", "keep it concise", "keep it shorter", "be more concise", "be more brief", "be brief",
"be concise", "be terse", "be shorter", "more concise", "more brief", "less verbose", "less wordy", "less fluff",
"less text", "less chatty", "less formal", "no emojis", "no emoji", "no fluff", "no essays", "dont write essays",
"don't write essays", "cut it in half", "cut it down", "cut that down", "trim it", "trim that", "drop the intro",
"drop the preamble", "drop the fluff", "drop the outro", "no explanation", "just the code", "tl;dr", "tldr",
"simplify it", "simplify that", "simplify this", "shorten this", "shorten", "trim this", "make this shorter", "stop being so verbose", "stop being so wordy", "stop being so formal", "stop the fluff",
"stop the essays", "stop writing essays", "simpler please", "shorter please", "concise please",
];
OPENERS.iter().any(|p| (starts(t, p) && (p.contains(' ') || w.len() <= 2)) || (w.len() <= 3 && has(t, p)))
|| (t.starts_with("just the code") || t.contains(", no explanation") || t.contains(", no fluff"))
}
fn sarcastic(t: &str) -> bool {
const OPENERS: &[&str] = &[
"great", "nice", "perfect", "awesome", "wow", "brilliant", "good job", "great job", "well done", "thanks", "thank you",
"amazing", "wonderful", "fantastic", "love it", "super", "cool", "oh great", "oh nice", "oh wow", "ok great", "okay great",
"oh cool", "fine", "sure", "yeah", "well", "lovely", "excellent", "impressive", "genius", "bravo", "thanks a lot",
"thanks for nothing", "oh perfect", "oh awesome", "oh brilliant", "oh good", "good", "love that", "just great",
"fucking great", "great job genius",
];
const BAD: &[&str] = &[
"broke", "broken", "breaks", "deleted", "wiped", "removed", "crash", "crashes", "crashed", "fail", "fails", "failed",
"failing", "errors", "error", "wont", "won't", "doesn't", "doesnt", "didn't", "red", "gone", "empty", "blank", "dead",
"ruined", "killed", "destroyed", "lost", "overwrote", "nuked", "trashed", "messed", "worse", "useless", "wrong",
"stuck", "hangs", "frozen", "missing", "corrupted", "panics", "panic", "mess", "disaster", "exploded", "undefined",
"breaking", "deleting", "wiping", "removing", "killing", "ruining", "destroying", "overwriting", "loops", "forever",
"infinite", "loop", "hangs", "hanging", "crashing", "failing",
"again", "everything", "nothing", "copies", "duplicates", "duplicate", "warnings", "conflicts", "break",
];
const FIXED: &[&str] = &[
"fixed", "solved", "resolved", "works", "working", "passes", "passing", "passed", "green", "clean", "fast", "faster",
"ship", "merge", "add", "next", "now add", "worked", "better",
];
let w = words(t);
if w.len() < 3 || w.len() > 24 {
return false;
}
let head = OPENERS.iter().any(|o| starts(t, o) || (starts(t, "oh") && has(&t.chars().take(14).collect::<String>(), o)));
if !head {
return false;
}
let everything = ["rewrote", "changed", "touched", "deleted", "removed", "replaced", "reformatted", "renamed", "reverted", "wiped"]
.iter()
.any(|v| w.windows(2).any(|p| p[0] == *v && p[1] == "everything"));
let nothing = everything || has(t, "now none") || has(t, "now no") || has(t, "while you're at it") || has(t, "while you are at it") || has(t, "now nobody")
|| has(t, "now nothing") || has(t, "for nothing") || has(t, "broke everything") || has(t, "nothing builds")
|| has(t, "nothing compiles") || has(t, "nothing works") || has(t, "the same bug again") || has(t, "same bug") || has(t, "same error");
let another = starts(t, "oh") && has(t, "another");
let redo = has(t, "now i have to") || has(t, "now i need to") || has(t, "now i must") || has(t, "redo") || has(t, "start over");
if nothing {
return true;
}
if w.iter().any(|x| FIXED.contains(x)) {
return false;
}
another || redo || w.iter().any(|x| BAD.contains(x) && !matches!(*x, "again" | "everything" | "nothing"))
}
pub fn blame(s: &str) -> bool {
if has(s, "curious") || has(s, "curiosity") || has(s, "wondering") || has(s, "just asking") || has(s, "out of interest") {
return false;
}
const PHRASES: &[&str] = &[
"were you even", "who said you could", "who said you can", "are you kidding", "are you serious", "are you insane", "are you blind", "are you even", "are you listening",
"not listening", "what are you doing", "what are you even doing", "what the hell are you", "what the fuck are you",
"what the actual fuck are", "wtf are you", "wtf did you", "what did you just do", "what did you do",
"what have you done", "what is wrong with you", "what's wrong with you", "how are you still", "how could you",
"what were you thinking", "did you even", "you didn't even", "you can't even", "have you even", "who told you",
"what made you think", "have to repeat", "why do i keep", "what the hell did you", "what the fuck did you",
"wtf did you just", "do you even", "can you not", "did you not read", "did you read", "who asked", "don't remember asking",
"don't recall asking", "i never requested", "i didn't request", "i didn't want", "i never wanted", "i didn't tell you to",
"i never told you to", "i didn't say to", "i never said to", "beyond what i", "outside what i", "outside of what i",
"more than i asked", "more than what i asked", "instead of what i", "went way outside", "way beyond",
"not asking you to", "not asking for", "nobody asked", "no one asked", "did not just", "didn't just", "made that up",
"made it up", "made up", "hallucinated", "hallucinating", "fabricated", "you invented", "in my message",
"in my last message", "i literally wrote", "i already wrote", "i just wrote",
];
if PHRASES.iter().any(|p| has(s, p)) && !has(s, "can you not only") {
return !has(s, "did you read the") || has(s, "did you read it") || has(s, "did you read what");
}
let w = words(s);
if let Some(k) = w.iter().position(|x| *x == "why") {
if w.get(k + 1) == Some(&"you") && w.get(k + 2).is_some_and(|v| matches!(*v, "deleted" | "removed" | "changed" | "touched" | "renamed" | "added" | "overwrote" | "reverted" | "dropped" | "broke" | "rewrote" | "edited" | "modified" | "moved" | "replaced" | "reformatted")) {
return true;
}
}
if (has(s, "end up") || has(s, "ended up")) && w.iter().any(|x| matches!(*x, "changed" | "deleted" | "removed" | "modified" | "touched" | "renamed" | "gone" | "overwritten" | "reverted" | "different" | "edited")) {
return true;
}
if let Some(k) = w.iter().position(|x| *x == "made") {
if k >= 1 && w[k - 1] == "what" && w.get(k + 1) == Some(&"you") && w.get(k + 2).is_some_and(|v| matches!(*v, "delete" | "remove" | "change" | "touch" | "rename" | "add" | "overwrite" | "revert" | "drop" | "rewrite" | "edit" | "modify" | "move" | "replace" | "reformat" | "install" | "commit" | "push")) {
return true;
}
}
if w.len() >= 5 && w[0] == "why" && w[1] == "is" && w[2] == "it" && w[3].ends_with("ing") && matches!(w.last(), Some(&"now") | Some(&"again") | Some(&"still") | Some(&"anymore")) {
return true;
}
let skip = w.iter().take(6).position(|x| *x == "why").unwrap_or(0);
let w = &w[skip..];
if w.len() >= 4 && w[0] == "why" {
const CHANGE: &[&str] = &[
"delete", "remove", "change", "touch", "rename", "add", "modify", "overwrite", "revert", "drop", "break", "skip",
"ignore", "rewrite", "edit", "push", "commit", "reformat", "install", "create", "replace", "move", "wipe", "kill",
"disable", "mock", "hardcode", "use", "bump", "pin", "unpin", "reorder", "squash", "merge", "format", "refactor", "downgrade", "upgrade",
];
const CHANGING: &[&str] = &[
"using", "adding", "deleting", "removing", "changing", "touching", "editing", "rewriting", "renaming", "installing",
"creating", "ignoring", "modifying", "mocking", "pushing", "committing", "reformatting", "replacing", "moving",
"running", "formatting", "refactoring", "rewriting", "wiping", "killing",
];
if matches!(w[1], "is" | "are" | "was" | "were") && w[2..].iter().take(5).any(|x| matches!(*x, "changed" | "deleted" | "removed" | "modified" | "touched" | "renamed" | "gone" | "missing" | "overwritten" | "reverted" | "different" | "edited" | "rewritten" | "dropped")) {
return true;
}
if matches!(w[1], "did" | "would" | "do") && w[2] == "you" && (CHANGE.contains(&w[3]) || (w[3] == "just" && w.get(4).is_some_and(|v| CHANGE.contains(v)))) {
return true;
}
if w[1] == "are" && w[2] == "you" && CHANGING.contains(&w[3]) {
return true;
}
if (w[1] == "is" && w[2] == "there" && w[3] == "a" && w.get(4) == Some(&"new")) || (w[1] == "are" && w[2] == "there" && w[3] == "new") {
return true;
}
}
false
}
pub fn you_blame(s: &str) -> bool {
const VERBS: &[&str] = &[
"deleted", "removed", "changed", "broke", "overwrote", "ignored", "forgot", "missed", "dropped", "pushed", "left",
"reverted", "rewrote", "renamed", "modified", "touched", "edited", "wiped", "killed", "skipped", "reformatted",
"committed", "merged", "added", "created", "installed", "replaced", "moved", "messed", "screwed", "destroyed", "lost",
"hardcoded", "mocked", "disabled", "stripped", "truncated", "duplicated", "never", "didn't", "failed", "stopped",
"mangled", "clobbered", "trashed", "nuked", "bypassed", "formatted", "refactored", "rebased", "amended", "squashed",
"bumped", "upgraded", "downgraded", "cleaned", "pruned", "reset", "reinstalled", "regenerated", "swapped", "shipped",
"deployed", "ruined", "wrecked", "erased", "uninstalled", "inlined", "stubbed", "hid", "commented", "unstaged",
];
const GOOD: &[&str] = &[
"thanks", "thank", "great", "nice", "perfect", "awesome", "love", "good", "right", "well", "appreciate", "helpful",
"excellent", "brilliant", "amazing", "fixed", "correctly",
];
const NO_LEAD: &[&str] = &[
"if", "when", "whether", "unless", "can", "could", "would", "should", "will", "do", "does", "did", "how", "why", "where",
"which", "who", "thank", "thanks", "please", "once", "after", "before", "since", "while", "that", "because",
];
let w = words(s);
for i in 0..w.len().min(5) {
if w[i] != "you" {
continue;
}
if w[..i].iter().any(|x| NO_LEAD.contains(x)) {
return false;
}
let mut j = i + 1;
while w.get(j).is_some_and(|x| matches!(*x, "just" | "also" | "then" | "even" | "really" | "literally" | "totally" | "completely" | "already" | "now" | "again" | "actually" | "somehow")) {
j += 1;
}
let Some(v) = w.get(j) else { return false };
if *v == "made" && w[j + 1..].iter().take(4).any(|x| *x == "up") {
return !w.iter().any(|x| GOOD.contains(x));
}
if !VERBS.contains(v) {
return false;
}
return !w.iter().any(|x| GOOD.contains(x));
}
false
}
pub fn claim(s: &str) -> bool {
s.split(',').any(|clause| claim_clause(clause.trim()))
}
fn claim_clause(s: &str) -> bool {
let w = words(s);
let Some(&f) = w.first() else { return false };
const SUBJ: &[&str] = &["it", "that", "it's", "that's", "its", "these", "those"];
const NEG: &[&str] = &["not", "isn't", "doesn't", "didn't", "won't", "wasn't", "hasn't", "can't", "aren't", "don't"];
const STATE: &[&str] = &[
"working", "running", "true", "right", "correct", "fixed", "there", "installed", "compiling", "compile", "passing",
"pass", "real", "valid", "work", "fix", "exist", "load", "loading", "start", "starting", "build", "building", "help",
"run", "accurate", "found", "how", "available", "enabled", "set", "print", "show", "output", "return", "display",
"produce", "respond", "appear", "change", "update", "save", "finish", "log", "open", "boot",
];
const FAIL: &[&str] = &[
"fails", "failed", "failing", "crashed", "crashes", "crashing", "errors", "errored", "hangs", "hung", "panics", "panicked",
"broke", "breaks", "froze", "freezes", "segfaults", "exploded", "broken", "wrong", "blank", "empty",
];
if f == "this" && w.len() <= 4 && w.iter().any(|x| NEG.contains(x) || *x == "not") && matches!(w.last(), Some(&"fixed") | Some(&"right") | Some(&"correct") | Some(&"true") | Some(&"done")) {
return true;
}
if SUBJ.contains(&f) {
let mut i = 1;
while w.get(i).is_some_and(|x| matches!(*x, "is" | "was" | "does" | "did" | "has" | "still" | "even" | "actually" | "really" | "just" | "do")) {
i += 1;
}
let still = w[1..i].contains(&"still");
if let Some(n) = w.get(i) {
if NEG.contains(n) {
let after = w.get(i + 1).copied().unwrap_or("");
if STATE.contains(&after) {
return !(after == "how" && f != "that's" && f != "that");
}
if after == "the" && w.get(i + 2).is_some_and(|x| THINGS.contains(x) || matches!(*x, "cause" | "bug" | "problem" | "issue" | "fix" | "right" | "schema" | "answer" | "api" | "endpoint" | "same")) {
return true;
}
if matches!(after, "on" | "in" | "at") && w.len() >= i + 3 && matches!(f, "it's" | "its" | "that's") {
return true;
}
if matches!(after, "a" | "an") && matches!(w.get(i + 2), Some(&"real") | Some(&"valid")) {
return true;
}
}
let recent = w.last().is_some_and(|x| matches!(*x, "now" | "again" | "anymore" | "too"));
let conditional = !recent && w.get(i + 1).is_some_and(|x| matches!(*x, "when" | "if" | "on" | "with" | "for" | "at" | "only" | "in" | "whenever" | "after" | "during" | "because" | "under"));
let terse_verdict = w.len() <= 3 && matches!(*n, "broken" | "wrong");
if FAIL.contains(n) && (still || terse_verdict || (!conditional && !matches!(*n, "wrong" | "blank" | "empty" | "broken"))) {
return true;
}
if matches!(*n, "false" | "untrue" | "inaccurate" | "incorrect") {
return true;
}
if *n == "not" && w.get(i + 1) == Some(&"true") {
return true;
}
}
return false;
}
match f {
"still" => {
const OK: &[&str] = &[
"using", "doing", "showing", "returning", "getting", "adding", "deleting", "ignoring", "touching", "writing",
"editing", "changing", "failing", "crashing", "erroring", "hanging", "missing", "broken", "wrong", "not", "no",
"there", "happening", "empty", "blank", "red", "same", "doesn't", "can't", "won't", "fails", "errors",
];
w.get(1).is_some_and(|x| OK.contains(x)) || (w.get(1) == Some(&"the") && w.get(2) == Some(&"same"))
}
"nothing" => w.get(1).is_some_and(|x| matches!(*x, "changed" | "happened" | "happens" | "works" | "worked" | "helped" | "builds" | "runs" | "compiles" | "loads" | "is" | "has" | "fixed" | "changes" | "prints" | "shows")) && !w.contains(&"urgent"),
"same" => w.get(1).is_some_and(|x| matches!(*x, "error" | "problem" | "issue" | "result" | "output" | "mistake" | "thing" | "bug" | "behavior" | "behaviour" | "stack" | "trace" | "stacktrace" | "message" | "failure" | "failures" | "warning" | "warnings" | "errors")),
"not" => w.len() <= 4 && w.get(1).is_some_and(|x| STATE.contains(x) || matches!(*x, "there" | "done" | "finished" | "solved")),
"didn't" | "doesn't" | "won't" | "isn't" => w.len() <= 5 && w.get(1).is_some_and(|x| STATE.contains(x) && !matches!(*x, "how" | "there")),
_ => {
if f != "this" {
if let Some(k) = w.iter().take(5).position(|x| *x == "still") {
if k >= 1 && !w[..k].iter().any(|x| matches!(*x, "if" | "when" | "why" | "how" | "what" | "is" | "whether" | "while")) && w.get(k + 1).is_some_and(|x| FAIL.contains(x) || NEG.contains(x) || matches!(*x, "there" | "happening" | "shows" | "returns" | "uses" | "prints" | "says" | "hangs" | "leaks" | "points" | "renders" | "contains")) {
return true;
}
}
if matches!(f, "the" | "your" | "that" | "my") && w.get(1).is_some_and(|x| matches!(*x, "fix" | "change" | "patch" | "solution" | "update" | "edit" | "commit" | "retry" | "workaround" | "suggestion" | "rewrite")) && w.get(2).is_some_and(|x| NEG.contains(x)) && w.get(3).is_some_and(|x| STATE.contains(x) || matches!(*x, "take" | "stick")) {
return true;
}
}
const STATE2: &[&str] = &["working", "running", "passing", "fixed", "broken", "failing", "blank", "red", "compiling", "loading", "there", "installed", "empty", "down", "building"];
for i in 1..w.len().min(5) {
if f == "this" {
break;
}
if matches!(w[i], "is" | "are") {
let mut j = i + 1;
let mut flagged = false;
while w.get(j).is_some_and(|x| matches!(*x, "still" | "not" | "also")) {
flagged = true;
j += 1;
}
return flagged && w.get(j).is_some_and(|x| STATE2.contains(x)) && !w[..i].iter().any(|x| matches!(*x, "if" | "when" | "why" | "how" | "what" | "is" | "whether"));
}
}
if matches!(f, "that" | "this") {
return false;
}
has(s, "no such flag") || has(s, "no such option") || has(s, "no such command") || has(s, "no such function")
}
}
}
pub fn quoted_claim(s: &str) -> bool {
let quoted = has(s, "you said") || has(s, "you told me") || has(s, "you claimed") || has(s, "you promised");
let against = has(s, "but") || has(s, "yet") || has(s, "actually")
|| ["empty", "nothing", "not", "doesn't", "didn't", "isn't", "fails", "failed", "wrong", "broken", "missing", "no"].iter().any(|x| has(s, x));
quoted && against && !has(s, "you said yes") && !has(s, "you said it's fine")
}
pub fn missing_thing(s: &str) -> bool {
let w = words(s);
if !matches!(w.first(), Some(&"that") | Some(&"this") | Some(&"there")) || w.len() < 3 {
return false;
}
if w[0] == "there" {
return w.get(1) == Some(&"is") && w.get(2) == Some(&"no") && w.get(3) == Some(&"such") && matches!(w.get(4), Some(&"flag") | Some(&"option") | Some(&"command") | Some(&"function") | Some(&"method") | Some(&"endpoint") | Some(&"api"));
}
w.iter().skip(1).take(3).any(|x| matches!(*x, "doesn't" | "isn't" | "aren't" | "does")) && (w.contains(&"exist") || has(s, "isn't a real") || has(s, "isn't real") || has(s, "not a real"))
}
pub fn contrast_fact(s: &str) -> bool {
let Some(i) = s.find(',') else { return false };
let (a, b) = (&s[..i], &s[i + 1..]);
let wa = words(a);
if wa.len() < 2 || !wa.iter().any(|x| matches!(*x, "isn't" | "aren't" | "wasn't" | "doesn't")) || wa.iter().any(|x| matches!(*x, "if" | "when" | "why" | "how" | "whether")) {
return false;
}
let wb = words(b);
matches!(wb.first(), Some(&"it's") | Some(&"its") | Some(&"they're")) && wb.get(1).is_some_and(|x| !matches!(*x, "just" | "only" | "a" | "an" | "fine" | "ok" | "okay" | "not" | "also"))
}
pub fn frustrated(s: &str) -> bool {
const OUTBURST: &[&[&str]] = &[
&["wtf"], &["ffs"], &["jesus", "christ"], &["jesus"], &["christ"], &["jeez"], &["for", "fucks", "sake"],
&["for", "fuck's", "sake"], &["for", "fucking", "sake"], &["for", "gods", "sake"], &["damn", "it"], &["dammit"],
&["goddamn", "it"], &["god", "damn", "it"], &["come", "on"], &["bro"], &["dude"], &["man"], &["omg"], &["ugh"],
&["what", "the", "hell"], &["what", "the", "fuck"], &["what", "the", "actual", "fuck"], &["holy", "shit"],
&["oh", "my", "god"], &["fuck", "sake"], &["for", "real"], &["seriously"], &["jesus", "fucking", "christ"],
];
let w = words(s);
const VERDICT: &[&str] = &["that's not", "it's not", "this isn't", "that isn't", "this is not", "that is not"];
if let Some(p) = VERDICT.iter().filter_map(|v| s.find(v).map(|i| i + v.len())).min() {
let tail = words(&s[p..]);
let said = tail.windows(2).any(|p| p[0] == "i" && matches!(p[1], "said" | "asked" | "meant" | "wanted" | "told" | "wrote" | "mentioned"));
if said && tail.len() <= 9 {
return true;
}
}
if let Some(c) = s.find(", not ") {
let head = words(&s[..c]);
let tail = words(&s[c + 6..]);
let outburst = head.first().is_some_and(|x| matches!(*x, "ffs" | "wtf" | "jesus" | "christ" | "goddamn" | "dude" | "bro" | "damn" | "ugh" | "omg"));
if outburst && head.len() >= 3 && tail.first().is_some_and(|x| matches!(*x, "the" | "a" | "an" | "that" | "this" | "those" | "it")) {
return true;
}
}
let mut i = 0;
let mut loud = false;
while i < w.len() && i < 8 {
let hit = OUTBURST.iter().find(|p| w[i..].starts_with(p));
match hit {
Some(p) => {
loud |= !matches!(p[0], "seriously" | "man" | "bro" | "dude" | "ugh" | "omg" | "come");
i += p.len();
}
None if matches!(w[i], "the" | "hell" | "fuck" | "fucking" | "shit" | "ok" | "okay" | "hey" | "oh" | "please" | "just") && i > 0 => i += 1,
None => break,
}
}
if i == 0 || !loud {
return false;
}
let rest = &w[i..];
let Some(&first) = rest.first() else { return false };
if matches!(first, "stop" | "quit") {
return rest.get(1).is_some_and(|x| x.len() > 4 && x.ends_with("ing") || matches!(*x, "it" | "that" | "this"));
}
if first == "wrong" || first == "you" {
return true;
}
super::LEAD_VERBS.contains(&first) && rest.len() >= 2
}
pub fn repeat(s: &str) -> bool {
const PHRASES: &[&str] = &[
"this is the second time", "this is the third time", "this is the fourth time", "this is the fifth time",
"the third time", "the fourth time", "the fifth time", "twice now", "third time", "fourth time", "same mistake",
"same thing as before", "same thing again", "same error again", "you keep", "keep doing this", "you never listen",
"you don't listen", "you're not listening", "not listening", "have to repeat", "told you already", "i said this",
"i've said this", "i have said this", "said this three times", "read my message", "read it again", "read again",
"i just said that", "i literally just said", "i literally said", "i already said", "i already told you", "what i said",
"that's what i said", "that is what i said", "we went over this", "i said it", "you forgot again", "again??",
"doing it again", "doing that again", "did it again", "did that again", "did this again", "done it again", "at it again",
"doing this again", "every single time", "twice already", "done this twice", "done this before", "already said",
"said already", "already told you", "you've done this", "you have done this", "second time now", "told you twice",
"told you before", "told you earlier", "i told you", "said it twice", "tell you again", "telling you again", "already covered", "covered this", "we covered", "we talked about", "we discussed",
];
if PHRASES.iter().any(|p| has(s, p)) {
return !has(s, "you keep the") && !has(s, "keep it") && !has(s, "you keep me");
}
let w = words(s);
let ordinal = |x: &str| {
matches!(x, "nth" | "umpteenth" | "hundredth" | "tenth" | "sixth" | "seventh" | "eighth" | "ninth")
|| (x.len() >= 3 && x.as_bytes()[..x.len() - 2].iter().all(u8::is_ascii_digit) && matches!(&x.as_bytes()[x.len() - 2..], b"st" | b"nd" | b"rd" | b"th"))
};
if w.windows(2).any(|p| ordinal(p[0]) && p[1] == "time") {
return true;
}
if w.len() <= 8 && w.contains(&"again") && w.iter().any(|x| matches!(*x, "read" | "reread")) && w.iter().any(|x| matches!(*x, "task" | "prompt" | "message" | "instructions" | "request" | "question" | "brief" | "spec" | "ticket" | "ask" | "rules")) {
return !matches!(w[0], "can" | "could" | "would");
}
(starts(s, "told you") && !has(s, "so")) || (starts(s, "once again") && !has(s, "thanks") && !has(s, "thank"))
}
pub fn hard_no(s: &str) -> bool {
let mut t = s.trim_start();
for _ in 0..2 {
let lead: String = t.chars().take_while(|c| c.is_alphabetic()).collect();
if matches!(lead.as_str(), "uh" | "um" | "hm" | "hmm" | "ok" | "okay" | "well" | "so" | "oh" | "ah" | "ahh" | "eh" | "yeah" | "yea" | "hey" | "hell" | "dude" | "bro" | "man" | "ugh" | "wait" | "bruh" | "lol") {
t = t[lead.len()..].trim_start_matches(|c: char| c == ',' || c == '.' || c.is_whitespace());
}
}
if super::NOT_CORRECTIONS.iter().any(|p| starts(t, p)) {
return false;
}
let w0: String = t.chars().take_while(|c| c.is_alphanumeric() || *c == '\'').collect();
let is_no = matches!(w0.as_str(), "no" | "nope" | "nah" | "nop" | "naw") || (w0.len() >= 3 && w0.starts_with("no") && w0.chars().all(|c| c == 'n' || c == 'o'));
if !is_no {
return false;
}
let after = &t[w0.len()..];
let rest = after.trim_start_matches(|c: char| c == ',' || c == '.' || c == '-' || c == ':' || c == '!' || c.is_whitespace());
let punct = after.starts_with(|c: char| matches!(c, ',' | '.' | '-' | ':' | '!'));
if rest.is_empty() {
return true;
}
let rw = words(rest);
let Some(&first) = rw.first() else { return true };
if !punct {
const FOLLOW: &[&str] = &[
"that", "that's", "this", "it", "it's", "its", "we", "i", "you", "they", "the", "don't", "do", "not", "stop", "wait",
"wrong", "actually", "never", "always", "only", "other", "no", "nope", "keep", "use", "put", "run", "call", "make",
"revert", "undo", "go", "switch", "try", "read", "look", "check", "set", "move", "rename", "change", "open", "write",
"name", "store", "place", "save", "add", "delete", "remove", "pick", "choose", "follow", "install", "build", "test",
"start", "update", "fix", "create", "edit", "leave",
];
if !FOLLOW.contains(&first) {
return false;
}
}
if matches!(first, "can" | "could" | "would" | "will" | "is" | "are" | "was" | "were" | "does" | "did" | "how" | "what" | "why" | "which" | "where" | "when" | "who" | "should" | "shall" | "have" | "has" | "am" | "isn't" | "aren't" | "wasn't") && first != "do" {
return false;
}
const CALM: &[&str] = &[
"fine", "good", "ok", "okay", "great", "perfect", "thanks", "thank", "works", "lgtm", "nice", "awesome", "worries",
"problem", "rush", "hurry", "matter", "idea", "yet", "later", "sure", "welcome", "excellent", "cool", "sweet", "love",
"nothing", "nevermind", "wait", "please",
];
!rw.iter().any(|x| CALM.contains(x) && !matches!(*x, "wait" | "please" | "later" | "nothing" | "sure"))
&& !(matches!(first, "wait" | "please" | "later" | "nothing" | "sure"))
&& !(first == "i" && matches!(rw.get(1), Some(&"don't") | Some(&"dont") | Some(&"was") | Some(&"am") | Some(&"have") | Some(&"haven't") | Some(&"can't") | Some(&"think") | Some(&"guess") | Some(&"meant") | Some(&"mean")))
}