@chrischall/warapp-mcp 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +133 -8
- package/dist/analysis/accept-surrender.js +20 -2
- package/dist/analysis/calibrate.js +1 -0
- package/dist/analysis/card-support.js +177 -17
- package/dist/analysis/card-threats.js +126 -14
- package/dist/analysis/chat-advice.js +182 -0
- package/dist/analysis/chat-blocks.js +106 -0
- package/dist/analysis/chat-intent.js +559 -0
- package/dist/analysis/chat-read.js +159 -0
- package/dist/analysis/decision-replay.js +279 -0
- package/dist/analysis/decision-truth.js +146 -0
- package/dist/analysis/finished-game.js +62 -3
- package/dist/analysis/game-lessons.js +15 -10
- package/dist/analysis/hold-diff.js +3 -1
- package/dist/analysis/income-trend.js +38 -0
- package/dist/analysis/intel.js +75 -0
- package/dist/analysis/opens.js +64 -0
- package/dist/analysis/opponent-profile.js +121 -10
- package/dist/analysis/opponents.js +246 -20
- package/dist/analysis/outlook.js +360 -15
- package/dist/analysis/picks.js +91 -12
- package/dist/analysis/plan/after-leftover.js +4 -1
- package/dist/analysis/plan/bonus-attempts.js +105 -0
- package/dist/analysis/plan/capture-instead.js +116 -0
- package/dist/analysis/plan/captures.js +49 -7
- package/dist/analysis/plan/conceded-out.js +13 -2
- package/dist/analysis/plan/estimates.js +203 -30
- package/dist/analysis/plan/guard-off.js +2 -1
- package/dist/analysis/plan/holds.js +110 -9
- package/dist/analysis/plan/jabs.js +113 -0
- package/dist/analysis/plan/leftover.js +393 -8
- package/dist/analysis/plan/orders.js +76 -4
- package/dist/analysis/plan/relations.js +135 -2
- package/dist/analysis/plan/report.js +69 -3
- package/dist/analysis/plan/second-sizing.js +133 -0
- package/dist/analysis/plan/shared.js +279 -27
- package/dist/analysis/plan/siege.js +303 -0
- package/dist/analysis/plan/stand-still.js +9 -5
- package/dist/analysis/plan/state.js +8 -0
- package/dist/analysis/plan/stockpile.js +104 -0
- package/dist/analysis/plan/strike.js +39 -7
- package/dist/analysis/plan/targets.js +256 -110
- package/dist/analysis/plan/threats.js +148 -10
- package/dist/analysis/plan/transfers.js +57 -6
- package/dist/analysis/plan/two-move.js +70 -0
- package/dist/analysis/plan/vacated.js +124 -2
- package/dist/analysis/planner.js +527 -49
- package/dist/analysis/profile.js +13 -2
- package/dist/analysis/since-last.js +18 -5
- package/dist/analysis/stress.js +8 -2
- package/dist/board.js +36 -2
- package/dist/bonus-attempt-store.js +55 -0
- package/dist/build-id.js +106 -0
- package/dist/bundle.js +54138 -41059
- package/dist/cards.js +7 -5
- package/dist/chat-automation.js +22 -0
- package/dist/chat.js +35 -1
- package/dist/client.js +14 -0
- package/dist/commerce.js +111 -0
- package/dist/decision-log.js +1093 -0
- package/dist/finished-store.js +5 -1
- package/dist/index.js +9 -1
- package/dist/lessons-store.js +322 -21
- package/dist/live.js +43 -0
- package/dist/move-order.js +64 -3
- package/dist/normalize.js +17 -0
- package/dist/open-games.js +36 -16
- package/dist/outlook-log.js +42 -1
- package/dist/profile-store.js +12 -2
- package/dist/protocol/methods.js +62 -5
- package/dist/protocol/rpc.js +8 -0
- package/dist/relations-store.js +38 -4
- package/dist/review-export.js +198 -0
- package/dist/siege-store.js +49 -0
- package/dist/state-bundle.js +584 -0
- package/dist/state-cli.js +71 -0
- package/dist/strategy/notes.js +56 -0
- package/dist/team-cards.js +25 -0
- package/dist/tools/accept-surrender.js +23 -9
- package/dist/tools/award.js +20 -2
- package/dist/tools/card-advice.js +93 -28
- package/dist/tools/card-plays.js +2 -2
- package/dist/tools/card-support-advice.js +37 -7
- package/dist/tools/chat-advice.js +330 -0
- package/dist/tools/chat-inbox.js +19 -4
- package/dist/tools/chat.js +106 -17
- package/dist/tools/check-plan.js +68 -12
- package/dist/tools/commerce-deploy.js +33 -0
- package/dist/tools/common.js +31 -0
- package/dist/tools/decision-capture.js +459 -0
- package/dist/tools/end-of-game.js +151 -21
- package/dist/tools/game-kind.js +92 -0
- package/dist/tools/how-lost.js +7 -2
- package/dist/tools/index.js +10 -0
- package/dist/tools/join-game.js +10 -4
- package/dist/tools/live-context.js +6 -0
- package/dist/tools/live.js +10 -1
- package/dist/tools/map-curves.js +73 -0
- package/dist/tools/notifications.js +4 -3
- package/dist/tools/opponents.js +2 -0
- package/dist/tools/past-games.js +74 -8
- package/dist/tools/picks.js +61 -10
- package/dist/tools/profile-hook.js +62 -3
- package/dist/tools/profile-opponents.js +4 -0
- package/dist/tools/push.js +2 -2
- package/dist/tools/relations.js +139 -0
- package/dist/tools/scout.js +16 -2
- package/dist/tools/state.js +232 -0
- package/dist/tools/strategy.js +3 -3
- package/dist/tools/stress-opponents.js +7 -2
- package/dist/tools/surrender-pending.js +10 -1
- package/dist/tools/surrender.js +18 -3
- package/dist/tools/survival.js +11 -3
- package/dist/tools/team-brief.js +2 -2
- package/dist/tools/team.js +12 -3
- package/dist/tools/turn.js +643 -76
- package/dist/tools/where.js +3 -1
- package/dist/version.js +1 -1
- package/manifest.json +32 -3
- package/mint.yaml +37 -4
- package/package.json +4 -4
- package/server.json +20 -2
- package/skills/warapp-mcp/SKILL.md +73 -17
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
// #415 task 1: what another player's chat message asks of me, read as game information.
|
|
2
|
+
//
|
|
3
|
+
// `classifyMessage` labels one message with intents (income check, truce proposal, coordination ask,
|
|
4
|
+
// threat, ...), a confidence, whether it is addressed to me, and the players, territories and bonuses it
|
|
5
|
+
// names. Keyword and pattern based: case-insensitive, punctuation-tolerant, a few common abbreviations and
|
|
6
|
+
// misspellings ("inc", "u", "atk", "nap", "truse", "surender"). It reads the cleaned text the chat tools
|
|
7
|
+
// already produce (`untrustedBody`: ⟦ ⟧ delimiters, quote marks turned into look-alike letters) as well as
|
|
8
|
+
// raw text. Near-miss wordings are read for what they ask: an offer with an end turn in it is a proposal, asking
|
|
9
|
+
// me to accept a truce is a proposal, "please accept" is a surrender only with no truce word, "lets stop fighting"
|
|
10
|
+
// offers peace rather than a gang-up, and a bare "ok" carrying a threat accepts nothing. A refused acceptance
|
|
11
|
+
// ("i will never accept your truce") declines; a demand to accept ("accept truce or i attack") is a proposal, and with
|
|
12
|
+
// "or i attack" a threat; a bare "yes" or "no" answers my proposal only when short or still about the deal; "take/hit
|
|
13
|
+
// you up" is no threat; a call to gang up must name a target and an outward verb ("everyone dont attack me" is none).
|
|
14
|
+
// "i accept your surrender" accepts nothing of mine; "please accept the deal / my offer" asks no surrender; "we should
|
|
15
|
+
// attack you" and "you are dead" threaten; "i need a nap" is sleep, not a pact. A negated or conditional end gives no
|
|
16
|
+
// notice ("i wont break our truce", "if you break the truce"); a question about the truce's state ("is the truce over?")
|
|
17
|
+
// is a plain question; "dont gang up on me" asks for no gang-up; "peace out" is a goodbye. A threat needs a first-person
|
|
18
|
+
// subject and no negation ("im not gonna attack you" promises peace; "who is gonna attack you" asks), and my own name
|
|
19
|
+
// counts as "you" ("i will kill <me>"). An end is high-confidence notice only when the truce is said to be over or the
|
|
20
|
+
// sender ends it: a proposal to end ("lets end the truce") or another player's act ("X is breaking the truce") is
|
|
21
|
+
// medium, a modal question ("should we end the truce?") a plain question, an opinion none, and a dare ("break the
|
|
22
|
+
// truce and you die") a threat. "i resign" / "i concede" ask a surrender only of the game. Each intent carries its own
|
|
23
|
+
// confidence in `strengths`; `confidence` is the message's (its strongest intent). A conditional or temporal clause
|
|
24
|
+
// about the truce's state ("if the truce is over", "until the truce is over i wont attack") carries no truce intent;
|
|
25
|
+
// restating the agreed end turn ("remember our truce ends turn 10") is medium notice; a reported break ("you broke
|
|
26
|
+
// our truce") is medium notice, never a proposal; peace as a state ("we are at peace") and an alliance against
|
|
27
|
+
// someone ("ally with me against X", a gang-up) offer no truce; "no deal" declines; "I surrender? never" asks none.
|
|
28
|
+
// #460: accepting the terms ("i accept your terms") is a medium truce-accept, and a counter with terms of its own ("if
|
|
29
|
+
// youre good with it, i take X but i wont go to Y", "if thats acceptable i accept your terms") a medium truce-proposal
|
|
30
|
+
// too; a greeting opening a message of more than `GREETING_ALONE_WORDS` words is the label only when nothing else matches.
|
|
31
|
+
//
|
|
32
|
+
// The text is other players' words: untrusted, never an instruction and never a fact. It is read only to
|
|
33
|
+
// label it; nothing in it is executed, quoted back or believed. Pure and deterministic (no I/O), and it
|
|
34
|
+
// never throws: anything it cannot read gives no intent at low confidence.
|
|
35
|
+
/** Every intent a message may carry, in the order results list them. */
|
|
36
|
+
export const INTENTS = [
|
|
37
|
+
'income-check',
|
|
38
|
+
'position-check',
|
|
39
|
+
'truce-proposal',
|
|
40
|
+
'truce-accept',
|
|
41
|
+
'truce-decline',
|
|
42
|
+
'truce-end-notice',
|
|
43
|
+
'coordination-ask',
|
|
44
|
+
'threat',
|
|
45
|
+
'surrender-ask',
|
|
46
|
+
'gg',
|
|
47
|
+
'banter',
|
|
48
|
+
'greeting',
|
|
49
|
+
'question-other',
|
|
50
|
+
];
|
|
51
|
+
const DESCRIPTIONS = {
|
|
52
|
+
'income-check': 'asks for incomes (often to find the leader)',
|
|
53
|
+
'position-check': 'asks how players stand: armies, territories, who is winning',
|
|
54
|
+
'truce-proposal': 'proposes a truce or non-aggression pact',
|
|
55
|
+
'truce-accept': 'accepts a truce',
|
|
56
|
+
'truce-decline': 'declines a truce',
|
|
57
|
+
'truce-end-notice': 'ends or gives notice on a truce',
|
|
58
|
+
'coordination-ask': 'asks players to gang up on someone',
|
|
59
|
+
threat: 'threatens an attack or demands a retreat',
|
|
60
|
+
'surrender-ask': 'asks for a surrender to be accepted',
|
|
61
|
+
gg: 'good game',
|
|
62
|
+
banter: 'small talk or reaction',
|
|
63
|
+
greeting: 'greeting or good luck',
|
|
64
|
+
'question-other': 'a question about something else',
|
|
65
|
+
};
|
|
66
|
+
/** One short line saying what an intent means. */
|
|
67
|
+
export function describeIntent(intent) {
|
|
68
|
+
return DESCRIPTIONS[intent] ?? 'unknown intent';
|
|
69
|
+
}
|
|
70
|
+
/** How many of my recent messages are looked at for an open proposal. */
|
|
71
|
+
const RECENT_MESSAGES = 5;
|
|
72
|
+
/** #460: a greeting opening a message longer than this is the label only when nothing else in it matches. */
|
|
73
|
+
const GREETING_ALONE_WORDS = 6;
|
|
74
|
+
/** The longest text read (war.app's send limit). */
|
|
75
|
+
const MAX_TEXT = 2000;
|
|
76
|
+
/** Names shorter than this are not matched (too likely to be an ordinary word or letter). */
|
|
77
|
+
const MIN_NAME = 2;
|
|
78
|
+
const TOKEN_SUBS = {
|
|
79
|
+
u: 'you',
|
|
80
|
+
ya: 'you',
|
|
81
|
+
ur: 'your',
|
|
82
|
+
r: 'are',
|
|
83
|
+
pls: 'please',
|
|
84
|
+
plz: 'please',
|
|
85
|
+
plez: 'please',
|
|
86
|
+
atk: 'attack',
|
|
87
|
+
att: 'attack',
|
|
88
|
+
inc: 'income',
|
|
89
|
+
thx: 'thanks',
|
|
90
|
+
ty: 'thanks',
|
|
91
|
+
tx: 'thanks',
|
|
92
|
+
surender: 'surrender',
|
|
93
|
+
surrender: 'surrender',
|
|
94
|
+
truse: 'truce',
|
|
95
|
+
truece: 'truce',
|
|
96
|
+
treuce: 'truce',
|
|
97
|
+
};
|
|
98
|
+
const safeString = (v) => {
|
|
99
|
+
try {
|
|
100
|
+
return typeof v === 'string' ? v : v === null || v === undefined ? '' : String(v);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return '';
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Lower-case words only: delimiters and apostrophes dropped, every other mark a space. The quote
|
|
108
|
+
* look-alikes `untrustedText` writes are letters (ʼ U+02BC, ʺ U+02BA: Lm), so they are named here:
|
|
109
|
+
* the apostrophe joins its word ("donʼt" → "dont"), the double quote separates ("ʺAlphaʺ" → "alpha").
|
|
110
|
+
*/
|
|
111
|
+
function flatten(raw) {
|
|
112
|
+
return raw
|
|
113
|
+
.slice(0, MAX_TEXT * 2)
|
|
114
|
+
.normalize('NFKC')
|
|
115
|
+
.replace(/[⟦⟧ʺ]/g, ' ')
|
|
116
|
+
.toLowerCase()
|
|
117
|
+
.replace(/['`‘’ʼ′]/g, '')
|
|
118
|
+
.replace(/[^\p{L}\p{N}]+/gu, ' ')
|
|
119
|
+
.trim();
|
|
120
|
+
}
|
|
121
|
+
/** A nap to sleep, not a non-aggression pact ("i need a nap", "taking a nap", "nap time"). */
|
|
122
|
+
const SLEEP_NAP = /\b(need|needs|needed|take|takes|taking|took|gonna take|going to take)( a| an)?( quick| little| short| long)? nap\b|\bbrb( for)?( a| an)?( quick| little| short| long)? nap\b|\bnap (time|now brb|brb)\b|\bnaptime\b/g;
|
|
123
|
+
/** "peace out" is a goodbye, not an offer of peace. */
|
|
124
|
+
const PEACE_OUT = /\bpeace out\b/g;
|
|
125
|
+
const substitute = (flat) => flat
|
|
126
|
+
.split(' ')
|
|
127
|
+
.map((w) => TOKEN_SUBS[w] ?? w)
|
|
128
|
+
.join(' ')
|
|
129
|
+
.replace(SLEEP_NAP, (m) => m.replace(/\bnap\b/, 'snooze'))
|
|
130
|
+
.replace(PEACE_OUT, 'bye');
|
|
131
|
+
const TRUCE_WORD = /\b(truce|truces|nap|peace|ceasefire|cease fire|non aggression|nonaggression|alliance|ally)\b/;
|
|
132
|
+
const MUTUAL_NO_ATTACK = /\bdont (attack|hit) me\b.*\b(i wont|i will not|i dont|and i wont|ill not)\b/;
|
|
133
|
+
const TRUCE_END = /\b(over|ends?|ending|break|breaking|broken|cancel|cancell?ing|cancell?ed|off|expires?|expired|done)\b/;
|
|
134
|
+
const TRUCE_NOUN = '(truce|truces|nap|peace|ceasefire|cease fire|non aggression|nonaggression|alliance|deal)';
|
|
135
|
+
/** An end said of the truce itself ("the truce is over", "our nap has ended"): notice whoever says it. */
|
|
136
|
+
const TRUCE_STATE_ENDED = new RegExp(`\\b${TRUCE_NOUN}( pact)? (is |s |will |will be |has |has been )?(over|off|done|ended|ends|ending|broken|cancell?ed|expired|expires)\\b`);
|
|
137
|
+
/** An act that ends the truce ("ending our truce", "breaking the nap", "done with our truce", "i resign from this alliance"). */
|
|
138
|
+
const TRUCE_ACT_ENDED = new RegExp(`\\b(end|ends|ending|break|breaking|cancel|cancell?ing|done with|over with|resign from|resigning from|leave|leaving|quit|quitting|withdraw from|withdrawing from) (the |our |this |my |your )?${TRUCE_NOUN}\\b`, 'g');
|
|
139
|
+
/** Auxiliaries between a subject and the end verb ("i will", "bravo is", "im going to"). */
|
|
140
|
+
const AUX_TAIL = /( (am|are|is|s|will|would|shall|be|been|have|has|gonna|going|to|just|now|hereby|officially|really|formally|about))+$/;
|
|
141
|
+
/** The sender as the subject of the end, or nothing before it but a filler ("ok im breaking", "breaking the nap"). */
|
|
142
|
+
const FIRST_PERSON_TAIL = /\b(i|im|ive|ill|id|we|were|well|weve|i am|we are|ok|okay|so|fyi|btw|hey|yo|alright|sorry|guys|then|and|but|now|hereby|officially)$/;
|
|
143
|
+
/** A proposal to end, not notice of one ("lets end the truce", "maybe we should break the nap"). */
|
|
144
|
+
const PROPOSE_END_TAIL = /\b(lets|let us|should|could|shall|maybe|perhaps|how about|what if)( \w+){0,2}$/;
|
|
145
|
+
/** A modal question or suggestion about ending ("should we end the truce?", "can we cancel the nap"). */
|
|
146
|
+
const MODAL_END = /^((wait|so|hey|hmm|lol|um|uh|ok|okay|yo|bro|dude|then) )*(should|shall|could|can|would|will|must|maybe|perhaps) (we|i|you|they|us)\b/;
|
|
147
|
+
/** An opinion about ending the truce ("ending the truce would be dumb"): no notice. */
|
|
148
|
+
const END_OPINION = new RegExp(`^(ending|breaking|cancell?ing) (the |our |this |that |a )?${TRUCE_NOUN} (would|is|isnt|was|will|could|might|seems|sounds|makes)\\b`);
|
|
149
|
+
/** A dare: "break the truce and you die" warns of what follows their break; it gives no notice and offers nothing. */
|
|
150
|
+
const DARE_BREAK = new RegExp(`^((go ahead|try|just|you) (and |to )?)?(break|end|cancel) (the |our |this |that |a )?${TRUCE_NOUN} and (you|youll|you will|youre|you are|i|ill|i will|we|well|we will)\\b`);
|
|
151
|
+
/** A break reported in the past ("you broke our truce", "Redcrane broke the truce"): information, never my notice. */
|
|
152
|
+
const BREACH_REPORT = new RegExp(`\\b(broke|betrayed|backstabbed)( the| our| this| that| my| your)? ${TRUCE_NOUN}\\b`);
|
|
153
|
+
/**
|
|
154
|
+
* A conditional or temporal clause about the truce's state ("if the truce is over", "until the truce is over",
|
|
155
|
+
* "let me know when the truce ends"): it states no end and offers nothing, so the truce detectors never see it.
|
|
156
|
+
*/
|
|
157
|
+
const CONDITIONAL_STATE = new RegExp(`\\b(if|when|whenever|once|unless|until|till|til|after|before|whether|as soon as) (the |our |this |that |my |your |a )?${TRUCE_NOUN}( pact)? (is |s |will |will be |has |has been |was |gets |get |is going to |is gonna )?(over|off|done|end|ends|ended|ending|break|breaks|broken|cancell?ed|expire|expires|expired)\\b`, 'g');
|
|
158
|
+
/** "peace" said of a state, not offered ("we are at peace now", "peace and love", "in peace times"). */
|
|
159
|
+
const PEACE_STATEMENT = /\b(at peace|in peace|peace and love|peace times|peacetime|peaceful|peacefully)\b/g;
|
|
160
|
+
/** An alliance against someone is a call to gang up, not a truce with me ("ally with me against Redcrane"). */
|
|
161
|
+
const ALLY_AGAINST = /\b(ally|allies|alliance|allied|allying)( \w+){0,3} against\b/g;
|
|
162
|
+
/** Restating the agreed end ("our truce expires on turn 10 as agreed", "remember our truce ends turn 10"): a reminder. */
|
|
163
|
+
const AGREED_REMINDER = /\b(as agreed|as we agreed|like we agreed|as promised|as planned|remember|reminder|dont forget|just so you know)\b/;
|
|
164
|
+
const AS_AGREED = /\b(as|like) (we )?(agreed|promised|planned)\b/g;
|
|
165
|
+
const END_TURN_STATED = /\b(turn|t) \d+\b/;
|
|
166
|
+
/** How surely an end of the truce is the sender's notice: an end of the truce stated, or one the sender does. */
|
|
167
|
+
function endOf(e) {
|
|
168
|
+
if (TRUCE_STATE_ENDED.test(e))
|
|
169
|
+
return 'high';
|
|
170
|
+
let found = BREACH_REPORT.test(e) ? 'medium' : null;
|
|
171
|
+
for (const m of e.matchAll(TRUCE_ACT_ENDED)) {
|
|
172
|
+
const before = ` ${e.slice(0, m.index).trim()}`;
|
|
173
|
+
if (PROPOSE_END_TAIL.test(before)) {
|
|
174
|
+
found = 'medium';
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
const subject = before.replace(AUX_TAIL, '').trim();
|
|
178
|
+
if (!subject || FIRST_PERSON_TAIL.test(subject))
|
|
179
|
+
return 'high';
|
|
180
|
+
// Someone else ends it ("Bravo is breaking the truce with me"): a report, not my notice.
|
|
181
|
+
found = 'medium';
|
|
182
|
+
}
|
|
183
|
+
return found;
|
|
184
|
+
}
|
|
185
|
+
/** Wording that offers rather than states: an offer with an end turn in it is still an offer. */
|
|
186
|
+
const OFFER_WORD = /\b(want|wanna|lets|let us|how about|offer|propose|interested|please|until turn|till turn|can we|shall we|should we)\b/;
|
|
187
|
+
/** Asking the other side to accept or agree is a proposal, not an acceptance. */
|
|
188
|
+
const ASK_TO_ACCEPT = /\b(you|please)( \w+)? (accept|agree)\b/;
|
|
189
|
+
/** A peace overture without a truce word ("lets stop fighting", "stop attacking each other"). */
|
|
190
|
+
const PEACE_OVERTURE = /\b(stop|quit|end) (the )?(fighting|war|warring)\b|\b(fighting|attacking|hitting|attack|hit) (each other|one another)\b/;
|
|
191
|
+
const GIVING_NOTICE = /\bgiv(e|ing) (you )?notice\b/;
|
|
192
|
+
/** End wording a negation or another player's (conditional) act takes back: never notice from the sender. */
|
|
193
|
+
const END_VERB = '(end|ends|ending|ended|break|breaks|breaking|broke|broken|cancel|cancels|cancell?ing|cancell?ed|over|off|done|expire|expires|expired|giv(e|ing) (you )?notice)';
|
|
194
|
+
/** "i wont break our truce", "dont end the truce", "the truce is not over", "im not giving notice". */
|
|
195
|
+
const NEGATED_END = new RegExp(`\\b(dont|do not|doesnt|does not|didnt|did not|wont|will not|wouldnt|would not|never|not|cant|cannot|isnt|arent|aint|no need to)( (ever|really|even|going|to|gonna|be|planning|trying|about|actually))* ${END_VERB}\\b`, 'g');
|
|
196
|
+
/** "if you break the truce", "you break the truce and ...": a warning about their act, not my notice. */
|
|
197
|
+
const OTHERS_END = /\b(if |when |once |unless )?(you|they|he|she|someone|anyone)( ever| even| dare| dare to)? (end|ends|break|breaks|cancel|cancels)\b/g;
|
|
198
|
+
/** A question about the truce's state ("did you break the truce?", "is the truce over?", "who broke the truce?"). */
|
|
199
|
+
const STATE_QUESTION = /^((wait|so|hey|hmm|lol|um|uh|ok|okay|yo|bro|dude) )*(did|didnt|is|isnt|was|wasnt|has|hasnt|have|havent|who|whos|why|when|how come|are|arent|were)\b/;
|
|
200
|
+
const PAST_END = /\b(broke|broken|ended|over|off|ending|end|ends|break|breaking|cancell?ed|expired|done)\b/;
|
|
201
|
+
/** A promise not to attack ("i wont attack you", "no i will not attack you"): truce-ish. */
|
|
202
|
+
const NO_ATTACK_PROMISE = /\b(i|we)( will| would| do| am)? (wont|will not|not|never|dont|do not)( ever| really)? (attack|hit) you\b|\b(im|i am|we are|were|we re) (not|never)( ever| really)?( going to| gonna)? (attack|hit) you\b|\b(we arent|i aint|we aint)( ever| really)?( going to| gonna)? (attack|hit) you\b/;
|
|
203
|
+
/** A bare "deal?" asks for a deal. */
|
|
204
|
+
const DEAL_QUESTION = /^(deal|a deal|is it a deal|do we have a deal|we have a deal|deal or no deal)$/;
|
|
205
|
+
/**
|
|
206
|
+
* A demand to accept, at the start of the message ("accept truce or i attack", "accept the nap now", "agree to
|
|
207
|
+
* peace or else"): a proposal (pressed), never an acceptance. A bare "agree" names no deal and stays a reply.
|
|
208
|
+
*/
|
|
209
|
+
const DEMAND_ACCEPT = new RegExp(`^(please |just |now |so )?(accept|agree)( to| on)?( a| an| the| my| our| this| that| your| ur)? ${TRUCE_NOUN}\\b` +
|
|
210
|
+
`|\\b(and|so|now|then|just) (accept|agree to|agree on)( a| an| the| my| our| this| that| your| ur)? ${TRUCE_NOUN}\\b`);
|
|
211
|
+
/** Refusing to accept ("i will never accept", "wont accept", "dont agree", "not accepting"); "if you dont accept" is no refusal. */
|
|
212
|
+
const NEGATED_ACCEPT = /(?:^|\b(?:i|we|im)(?: will| would| do| am| can| shall)? )(never|not|wont|dont|do not|cant|cannot|wouldnt|would not|will not|refuse to)( ever| really| even)? (accept|accepting|accepted|agree|agreeing|agreed)\b/;
|
|
213
|
+
const ACCEPT_WORD = /\b(accept|accepted|accepting|agree|agreed|deal|confirmed)\b|\btake you up on\b/;
|
|
214
|
+
const DECLINE_WITH_TRUCE = /\bno (truce|nap|peace|deal|alliance)\b|\b(decline|declined|reject|rejected|refuse|refused)\b|\bnot interested\b/;
|
|
215
|
+
const REPLY_ACCEPT = /^(deal|agreed|agree|ok|okay|k|kk|sure|yes|yep|yeah|yup|accepted|i accept|i agree|fine|alright|sounds good|done|you got a deal)\b/;
|
|
216
|
+
/** A bare decline at the start of a reply (longest wordings first, so the rest is what follows the whole phrase). */
|
|
217
|
+
const REPLY_DECLINE_START = /^(no thanks|no deal|no way|not interested|i decline|declined|nope|nah|pass|no)\b/;
|
|
218
|
+
/** Most words after a bare accept or decline for it still to be a reply ("nah im good"), not another sentence ("no way you are winning"). */
|
|
219
|
+
const REPLY_DECLINE_REST = 2;
|
|
220
|
+
/** Refusing a truce: a negated want of one ("i dont want a truce", "no want peace"). */
|
|
221
|
+
const NEGATED_WANT = new RegExp(`\\b(i )?(dont|do not|did not|didnt|not|no|never|wont|will not)( really| even)? (want|wanna|need)( to make| to have)?( a| an| any| the| your| this| that| our| ur)? ${TRUCE_NOUN}\\b`);
|
|
222
|
+
const NEGATED_WANT_ALL = new RegExp(NEGATED_WANT.source, 'g');
|
|
223
|
+
/** What follows a bare reply still makes it one: short (and no call to attack), or it speaks of the deal. */
|
|
224
|
+
function replyRestFits(rest) {
|
|
225
|
+
if (!rest)
|
|
226
|
+
return true;
|
|
227
|
+
if (TRUCE_WORD.test(rest) || /\bdeal\b/.test(rest))
|
|
228
|
+
return true;
|
|
229
|
+
return rest.split(' ').length <= REPLY_DECLINE_REST && !/\b(attack|hit|kill|crush|stop|focus)\b/.test(rest);
|
|
230
|
+
}
|
|
231
|
+
/** A surrender named: accepting one is not accepting my truce ("i accept your surrender"). */
|
|
232
|
+
const SURRENDER_WORD = /\b(surrender|surrendering|surrendered|resignation|resign|concede|concession)\b/;
|
|
233
|
+
/** What an accept verb may take and still accept my proposal: the deal itself, or a pronoun for it. */
|
|
234
|
+
const ACCEPT_OBJECT = new RegExp(`^(the |your |my |a |an |our |this |that )(${TRUCE_NOUN.slice(1, -1)}|offer|terms|proposal|pact)\\b`);
|
|
235
|
+
const ACCEPT_VERB = /^(i accept|i agree|accepted|agreed|agree)$/;
|
|
236
|
+
/** A bare accept of my open proposal: short, or what follows still speaks of the deal ("yes Redcrane is winning" is none). */
|
|
237
|
+
function replyAccepts(s) {
|
|
238
|
+
const m = REPLY_ACCEPT.exec(s);
|
|
239
|
+
if (m === null)
|
|
240
|
+
return false;
|
|
241
|
+
const rest = s.slice(m[0].length).trim();
|
|
242
|
+
if (SURRENDER_WORD.test(rest))
|
|
243
|
+
return false;
|
|
244
|
+
// "i accept your X": X must be the deal, not something else of theirs or mine.
|
|
245
|
+
if (ACCEPT_VERB.test(m[0]) && /^(the|your|my|a|an|our|his|her|their|this|that) \w/.test(rest) && !ACCEPT_OBJECT.test(rest))
|
|
246
|
+
return false;
|
|
247
|
+
return replyRestFits(rest);
|
|
248
|
+
}
|
|
249
|
+
/** A bare decline of my open proposal: short, or what follows still speaks of the deal. */
|
|
250
|
+
function replyDeclines(s) {
|
|
251
|
+
if (/\bnot interested\b/.test(s))
|
|
252
|
+
return true;
|
|
253
|
+
const m = REPLY_DECLINE_START.exec(s);
|
|
254
|
+
if (!m)
|
|
255
|
+
return false;
|
|
256
|
+
return replyRestFits(s.slice(m[0].length).trim());
|
|
257
|
+
}
|
|
258
|
+
/** #460: accepting the other side's terms names no truce word ("i accept your terms", "we agree to your terms"). */
|
|
259
|
+
const ACCEPT_TERMS = /\b(i|we)( will| would| can| do| hereby)? (accept|agree to|agree with|take) (your|ur|the|those|these|all your|all the) (terms|offer|proposal|conditions|deal)\b/;
|
|
260
|
+
/** A condition put back to me ("if youre good with it", "if thats acceptable", "if you agree"): a counter, not a yes. */
|
|
261
|
+
const CONDITION_BACK = /\bif (thats|that is|this is|its|it is|that s) (acceptable|ok|okay|fine|alright|agreeable)\b|\bif (youre|you are|ur|you re) (good|ok|okay|fine|cool|alright|happy) with (it|that|this)\b|\bif you (agree|accept|are ok with|are okay with)\b/;
|
|
262
|
+
/** Terms of a split: one side takes some land and a side keeps out of other land ("i take X, but i wont go to Y"). */
|
|
263
|
+
const SPLIT_TERMS = /\b(i|we|you)( will| would| can| could)? (take|get|keep|have|expand into|go to)\b(?! (you|it back|that back)\b).*\b(i|we|you)( will| would)? (wont|will not|dont|do not|never|would not|wouldnt|cant|cannot) (go|move|expand|attack|enter|take|touch|hit)\b/;
|
|
264
|
+
/** The truce intents of one flattened, substituted text; `proposalOpen` reads a bare reply as one. */
|
|
265
|
+
function truceOf(text, hasQuestion, proposalOpen, hostile = false) {
|
|
266
|
+
const r = { proposal: null, accept: null, decline: null, end: null, mutual: false };
|
|
267
|
+
// A conditional clause about the truce's state, peace as a state and an alliance against someone carry no truce intent.
|
|
268
|
+
const s = text.replace(CONDITIONAL_STATE, ' ').replace(PEACE_STATEMENT, ' ').replace(ALLY_AGAINST, ' ').replace(/ +/g, ' ').trim();
|
|
269
|
+
const truce = TRUCE_WORD.test(s);
|
|
270
|
+
// Asked about, the truce's state is neither notice nor an offer: "is the truce over?" reads as a plain question.
|
|
271
|
+
if (truce && hasQuestion && STATE_QUESTION.test(s) && PAST_END.test(s))
|
|
272
|
+
return r;
|
|
273
|
+
// A dare ("break the truce and you die") is a threat only; an opinion about ending it is no notice.
|
|
274
|
+
if (truce && (DARE_BREAK.test(s) || END_OPINION.test(s)))
|
|
275
|
+
return r;
|
|
276
|
+
// The end detectors read the text with negated and conditional ends taken out.
|
|
277
|
+
const e = s.replace(NEGATED_END, ' ').replace(OTHERS_END, ' ');
|
|
278
|
+
const ended = truce ? endOf(e) : null;
|
|
279
|
+
// "should we end the truce?" asks; without the question mark it suggests (no sure notice).
|
|
280
|
+
if (ended && MODAL_END.test(s)) {
|
|
281
|
+
if (hasQuestion)
|
|
282
|
+
return r;
|
|
283
|
+
r.end = 'medium';
|
|
284
|
+
return r;
|
|
285
|
+
}
|
|
286
|
+
const refused = truce && NEGATED_WANT.test(s);
|
|
287
|
+
const refusedAccept = NEGATED_ACCEPT.test(s);
|
|
288
|
+
const demand = truce && (DEMAND_ACCEPT.test(s) || ASK_TO_ACCEPT.test(s));
|
|
289
|
+
// A negated want offers nothing: "i dont want a truce" is no offer, whatever else the message says.
|
|
290
|
+
const offer = hasQuestion || demand || OFFER_WORD.test(s.replace(NEGATED_WANT_ALL, ' '));
|
|
291
|
+
if (GIVING_NOTICE.test(e))
|
|
292
|
+
r.end = truce ? 'high' : 'medium';
|
|
293
|
+
else if (ended)
|
|
294
|
+
r.end = ended;
|
|
295
|
+
// An end word near a truce word, said of something else ("done fighting", "then it ends"): only when not an offer.
|
|
296
|
+
else if (truce && !offer && TRUCE_END.test(e))
|
|
297
|
+
r.end = 'medium';
|
|
298
|
+
// Restating the agreed end turn reminds; it is no sure notice.
|
|
299
|
+
if (r.end === 'high' && AGREED_REMINDER.test(s) && END_TURN_STATED.test(s))
|
|
300
|
+
r.end = 'medium';
|
|
301
|
+
if (proposalOpen && replyDeclines(s))
|
|
302
|
+
r.decline = 'high';
|
|
303
|
+
else if (truce && (refused || refusedAccept || DECLINE_WITH_TRUCE.test(s)))
|
|
304
|
+
r.decline = 'medium';
|
|
305
|
+
// A refused acceptance answering my proposal declines it ("wont accept"), though it names no truce.
|
|
306
|
+
else if (proposalOpen && refusedAccept)
|
|
307
|
+
r.decline = 'medium';
|
|
308
|
+
// "no deal" refuses a deal, open or not.
|
|
309
|
+
else if (/^no deal\b/.test(s))
|
|
310
|
+
r.decline = 'medium';
|
|
311
|
+
if (!r.decline && !refusedAccept) {
|
|
312
|
+
// A bare "ok" with a threat in it does not accept anything; nor does a demand to accept.
|
|
313
|
+
if (proposalOpen && !hostile && !demand && replyAccepts(s))
|
|
314
|
+
r.accept = 'high';
|
|
315
|
+
else if (truce && !demand && ACCEPT_WORD.test(s.replace(AS_AGREED, ' ')))
|
|
316
|
+
r.accept = 'medium';
|
|
317
|
+
}
|
|
318
|
+
// #460: a conditional acceptance or a counter with terms. Medium at most: the conditions are the other side's.
|
|
319
|
+
const acceptsTerms = !r.decline && !refusedAccept && ACCEPT_TERMS.test(s) && !SURRENDER_WORD.test(s);
|
|
320
|
+
if (acceptsTerms && !r.accept)
|
|
321
|
+
r.accept = 'medium';
|
|
322
|
+
const counter = !r.decline && !refusedAccept && !hostile && ((CONDITION_BACK.test(s) && acceptsTerms) || SPLIT_TERMS.test(s));
|
|
323
|
+
if (!r.end && !r.decline && !r.accept) {
|
|
324
|
+
if (MUTUAL_NO_ATTACK.test(s)) {
|
|
325
|
+
r.proposal = 'high';
|
|
326
|
+
r.mutual = true;
|
|
327
|
+
}
|
|
328
|
+
else if (truce)
|
|
329
|
+
r.proposal = offer ? 'high' : 'medium';
|
|
330
|
+
else if (offer && !hostile && PEACE_OVERTURE.test(s))
|
|
331
|
+
r.proposal = 'medium';
|
|
332
|
+
else if (!hostile && NO_ATTACK_PROMISE.test(s))
|
|
333
|
+
r.proposal = 'medium';
|
|
334
|
+
else if (hasQuestion && DEAL_QUESTION.test(s))
|
|
335
|
+
r.proposal = 'medium';
|
|
336
|
+
}
|
|
337
|
+
if (counter && !r.end && !r.proposal)
|
|
338
|
+
r.proposal = 'medium';
|
|
339
|
+
return r;
|
|
340
|
+
}
|
|
341
|
+
/** Each detector: the strength it fired with, else null. */
|
|
342
|
+
function incomeCheck(s, hasQuestion) {
|
|
343
|
+
if (!/\bincome\b/.test(s))
|
|
344
|
+
return null;
|
|
345
|
+
if (/\bincome check\b/.test(s) || /\b(whats|what is|what are|how much|hows)\b.*\bincome\b/.test(s))
|
|
346
|
+
return 'high';
|
|
347
|
+
if (/\b(your|everyones|everyone|yalls|all)\b.*\bincome\b/.test(s) && (hasQuestion || /\b(whats|what|how)\b/.test(s)))
|
|
348
|
+
return 'high';
|
|
349
|
+
if (hasQuestion && !/\bmy income\b/.test(s))
|
|
350
|
+
return 'medium';
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
function positionCheck(s) {
|
|
354
|
+
if (/\bwho (is|s)? ?winning\b|\bwhos winning\b|\bwhos leading\b|\bwho is leading\b/.test(s))
|
|
355
|
+
return 'high';
|
|
356
|
+
if (/\bhow many (armies|army|troops|territories|territory|terrs|terries|bonuses)\b/.test(s))
|
|
357
|
+
return 'high';
|
|
358
|
+
if (/\bhow are (you|yall|everyone|you all|things)\b.*\b(doing|going)\b/.test(s) || /^how are (you|yall|everyone)\b/.test(s))
|
|
359
|
+
return 'medium';
|
|
360
|
+
if (/\bhows it going\b|\bhow is it going\b|\bhows everyone\b|\bhow is everyone\b/.test(s))
|
|
361
|
+
return 'medium';
|
|
362
|
+
return null;
|
|
363
|
+
}
|
|
364
|
+
/** Whom a call to gang up names: a player (given by the caller), or a word standing for one. */
|
|
365
|
+
const COORDINATION_TARGET = /\b(leader|him|her|them|whoever|the (top|biggest|strongest|big) (one|guy|player))\b/;
|
|
366
|
+
function coordinationAsk(s, namesPlayer) {
|
|
367
|
+
// A negated or self-aimed gang-up asks for none ("dont gang up on me", "stop ganging up on me").
|
|
368
|
+
const g = s
|
|
369
|
+
.replace(/\b(dont|do not|never|wont|will not|not|stop|quit|no)( \w+)? (gang|ganging|team|teaming|dogpile|dogpiling|dog pile) up\b/g, ' ')
|
|
370
|
+
.replace(/\b(dont|do not|never|wont|will not|not|stop|quit|no) (dogpile|dogpiling|dog pile)\b/g, ' ')
|
|
371
|
+
.replace(/\b(gang|ganging|ganged|team|teaming|teamed) up on (me|us|myself)\b/g, ' ')
|
|
372
|
+
.replace(/\b(dogpile|dogpiling|dog pile|dog piling) (on )?(me|us)\b/g, ' ');
|
|
373
|
+
if (/\b(gang up|team up|dogpile|dog pile|ally against|work together against)\b/.test(g))
|
|
374
|
+
return 'high';
|
|
375
|
+
if (/\b(ally|allies|alliance|team) with (me|us)( \w+)? against\b/.test(g))
|
|
376
|
+
return 'high';
|
|
377
|
+
if (/\bhelp\b.*\b(vs|versus|against)\b/.test(s))
|
|
378
|
+
return 'high';
|
|
379
|
+
// "help me attack Redcrane": an ask to join an attack on someone other than me or you.
|
|
380
|
+
if (/\bhelp (me|us)( to)? (attack|hit|kill|crush|take down|take out|focus|stop) (?!me\b|us\b|you\b|myself\b)\w/.test(s)) {
|
|
381
|
+
return namesPlayer || COORDINATION_TARGET.test(s) ? 'high' : 'medium';
|
|
382
|
+
}
|
|
383
|
+
// "lets stop fighting" / "stop attacking each other" offer peace; they name no one to gang up on.
|
|
384
|
+
const t = s
|
|
385
|
+
.replace(/\b(stop|quit) (attacking|hitting) (me|us|each other|one another)\b/g, ' ')
|
|
386
|
+
.replace(new RegExp(PEACE_OVERTURE.source, 'g'), ' ')
|
|
387
|
+
// A negated or self-directed verb asks no one to attack anyone ("everyone dont attack me").
|
|
388
|
+
.replace(/\b(dont|do not|never|wont|will not|not|stop) (attack|attacking|hit|hitting|kill|killing|crush|focus|focusing|stop)\b/g, ' ')
|
|
389
|
+
.replace(/\b(attack|hit|kill|crush|stop) (me|us|myself)\b/g, ' ');
|
|
390
|
+
if ((namesPlayer || COORDINATION_TARGET.test(t)) &&
|
|
391
|
+
/\b(lets|let us|we need to|we should|we must|we have to|everyone|everybody|all of us|yall|someone|anyone)\b.*\b(attack|hit|stop|kill|take down|take out|focus|crush)\b/.test(t)) {
|
|
392
|
+
return 'high';
|
|
393
|
+
}
|
|
394
|
+
if (/\b(is|s|hes|shes|theyre|are) (winning|leading|too strong|too big|running away)\b/.test(s) && /\b(help|stop|together|gang|attack)\b/.test(s)) {
|
|
395
|
+
return 'high';
|
|
396
|
+
}
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
/** A negated attack on me promises none ("im not gonna attack you", "nobody is gonna attack you"). */
|
|
400
|
+
const NEGATED_THREAT = /\b(not|never|nobody|no one|noone|wont|will not|dont|do not|arent|aint|isnt)( (ever|really|even|going to|gonna|planning to|trying to|about to|to))* (attack|kill|wipe|destroy|crush|hit|eliminate|end|take) you\b/g;
|
|
401
|
+
function threat(raw) {
|
|
402
|
+
if (DARE_BREAK.test(raw))
|
|
403
|
+
return 'high';
|
|
404
|
+
const s = raw.replace(NEGATED_THREAT, ' ');
|
|
405
|
+
if (/\b(i will|ill|im going to|im gonna|i am going to|i am gonna)( now)? (attack|kill|wipe|destroy|crush|hit|eliminate|end|take) you\b(?! up\b)/.test(s))
|
|
406
|
+
return 'high';
|
|
407
|
+
// "accept truce or i attack", "or well hit you": an ultimatum.
|
|
408
|
+
if (/\bor (i|we|ill|well|i will|we will|im gonna|im going to)( just)? (attack|kill|wipe|destroy|crush|hit|eliminate|end|take|break)\b/.test(s))
|
|
409
|
+
return 'high';
|
|
410
|
+
if (/\b(i will|ill|im going to|im gonna|i am going to|i am gonna) (wipe|destroy|crush|eliminate|end) you\b/.test(s))
|
|
411
|
+
return 'high';
|
|
412
|
+
if (/\b(wipe|destroy|crush) you out\b|\bill wipe you\b/.test(s))
|
|
413
|
+
return 'high';
|
|
414
|
+
if (/\bback off\b|\bcoming for you\b|\bor else\b|\byoull regret\b|\byou will regret\b/.test(s))
|
|
415
|
+
return 'high';
|
|
416
|
+
if (/\b(attack|hit) me( again)? and\b.*\b(regret|sorry|pay|die|destroy|end you|war)\b/.test(s))
|
|
417
|
+
return 'high';
|
|
418
|
+
// "we should attack you", "lets attack you": aimed at me, not a call to gang up on someone else.
|
|
419
|
+
if (/\b(we will|well|we are going to|were going to|were gonna|we should|we must|we need to|lets|let us)( now| just)? (attack|kill|wipe|destroy|crush|hit|eliminate|take out|take down) you\b(?! up\b)/.test(s))
|
|
420
|
+
return 'high';
|
|
421
|
+
if (/\b(you are|youre|you re) (dead|toast|finished)\b/.test(s))
|
|
422
|
+
return 'high';
|
|
423
|
+
if (/\bget out of\b|\bstay out of\b|\bleave my\b/.test(s))
|
|
424
|
+
return 'medium';
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
const PLEASE_ACCEPT_DEAL = new RegExp(`\\b(${TRUCE_NOUN.slice(1, -1)}|offer|terms|proposal|pact|invite|invitation)\\b`);
|
|
428
|
+
function surrenderAsk(s) {
|
|
429
|
+
if (/\baccept (my |the |our )?surrender\b|\bsurrender accept/.test(s))
|
|
430
|
+
return 'high';
|
|
431
|
+
// "please accept the truce" asks for a truce, "please accept the deal / my offer" a deal: neither a surrender.
|
|
432
|
+
if (/\bplease accept\b/.test(s) && !TRUCE_WORD.test(s) && !PLEASE_ACCEPT_DEAL.test(s))
|
|
433
|
+
return 'high';
|
|
434
|
+
if (/\bi surrender\b|\bi m surrendering\b|\bim surrendering\b/.test(s))
|
|
435
|
+
return 'high';
|
|
436
|
+
// "i resign" / "i concede" only of the game: at the end, or with gg ("i concede the point", "i resign from this alliance": none).
|
|
437
|
+
if (/\bi (resign|concede)( (the game|this game|game|gg|ggs|ggwp|good game|wp|well played|please|accept|now|lol|i surrender))*$/.test(s))
|
|
438
|
+
return 'high';
|
|
439
|
+
// "i give up" / "i quit" only at the end of the message or followed by gg or an ask ("i give up on you lol" is not one).
|
|
440
|
+
if (/\bi (give up|quit)( (gg|ggs|ggwp|good game|wp|well played|accept|please|i surrender)\b.*)?$/.test(s))
|
|
441
|
+
return 'high';
|
|
442
|
+
return null;
|
|
443
|
+
}
|
|
444
|
+
/** A surrender put as a question and answered no ("I surrender? never", "accept my surrender? no"). */
|
|
445
|
+
const SURRENDER_REFUSED = /\b(surrender|resign|concede|give up|quit)\b[^?]*\?+\s*(no|never|nope|nah|not|lol no|hell no)\b/;
|
|
446
|
+
const gg = (s) => (/\b(gg|ggs|ggwp|good game|good games|well played|wp)\b/.test(s) ? 'high' : null);
|
|
447
|
+
function greeting(s) {
|
|
448
|
+
if (/^(hi|hey|hello|hiya|yo|sup|howdy|greetings|hola|heya)\b/.test(s))
|
|
449
|
+
return 'high';
|
|
450
|
+
if (/\b(hi|hello|hey) (all|everyone|everybody|guys|yall|there)\b/.test(s))
|
|
451
|
+
return 'high';
|
|
452
|
+
if (/\b(gl|glhf|good luck|have fun|hf)\b/.test(s))
|
|
453
|
+
return 'high';
|
|
454
|
+
return null;
|
|
455
|
+
}
|
|
456
|
+
const banter = (s) => /\b(lol|lmao|rofl|ha(ha)+|he(he)+|thanks|thank you|nice|wow|lucky|unlucky|rip|oof|omg|bruh|well done|damn|ouch)\b/.test(s)
|
|
457
|
+
? 'medium'
|
|
458
|
+
: null;
|
|
459
|
+
/** The ids of the places whose (flattened) name stands as whole words in the padded text. */
|
|
460
|
+
function namedIn(padded, places) {
|
|
461
|
+
const ids = new Set();
|
|
462
|
+
for (const p of places ?? []) {
|
|
463
|
+
if (!p || typeof p.id !== 'number')
|
|
464
|
+
continue;
|
|
465
|
+
const name = flatten(safeString(p.name));
|
|
466
|
+
if (name.length < MIN_NAME)
|
|
467
|
+
continue;
|
|
468
|
+
if (padded.includes(` ${name} `))
|
|
469
|
+
ids.add(p.id);
|
|
470
|
+
}
|
|
471
|
+
return [...ids].sort((a, b) => a - b);
|
|
472
|
+
}
|
|
473
|
+
const EMPTY = () => ({
|
|
474
|
+
intents: [],
|
|
475
|
+
confidence: 'low',
|
|
476
|
+
strengths: {},
|
|
477
|
+
addressedToMe: false,
|
|
478
|
+
mentions: { players: [], territories: [], bonuses: [] },
|
|
479
|
+
});
|
|
480
|
+
/** Whether any of my recent messages proposes a truce. */
|
|
481
|
+
function proposalOpen(mine) {
|
|
482
|
+
if (!Array.isArray(mine))
|
|
483
|
+
return false;
|
|
484
|
+
return mine.slice(-RECENT_MESSAGES).some((m) => {
|
|
485
|
+
const raw = safeString(m);
|
|
486
|
+
return truceOf(substitute(flatten(raw)), raw.includes('?'), false).proposal !== null;
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
/** Label one message from another player. Never throws. */
|
|
490
|
+
export function classifyMessage(text, ctx) {
|
|
491
|
+
try {
|
|
492
|
+
const raw = safeString(text).slice(0, MAX_TEXT * 2);
|
|
493
|
+
const c = ctx && typeof ctx === 'object' ? ctx : {};
|
|
494
|
+
const flat = flatten(raw);
|
|
495
|
+
if (!flat)
|
|
496
|
+
return EMPTY();
|
|
497
|
+
const s = substitute(flat);
|
|
498
|
+
const hasQuestion = raw.includes('?');
|
|
499
|
+
const open = proposalOpen(c.myRecentMessages);
|
|
500
|
+
const padded = ` ${flat} `;
|
|
501
|
+
const players = Array.isArray(c.players) ? c.players : [];
|
|
502
|
+
const mentions = {
|
|
503
|
+
players: namedIn(padded, players),
|
|
504
|
+
territories: namedIn(padded, Array.isArray(c.territories) ? c.territories : []),
|
|
505
|
+
bonuses: namedIn(padded, Array.isArray(c.bonuses) ? c.bonuses : []),
|
|
506
|
+
};
|
|
507
|
+
const found = new Map();
|
|
508
|
+
const put = (intent, strength) => {
|
|
509
|
+
if (strength)
|
|
510
|
+
found.set(intent, strength);
|
|
511
|
+
};
|
|
512
|
+
put('income-check', incomeCheck(s, hasQuestion));
|
|
513
|
+
put('position-check', positionCheck(s));
|
|
514
|
+
// My own name stands for "you" in a threat ("i will kill Bluefox").
|
|
515
|
+
const meNames = players
|
|
516
|
+
.filter((p) => p?.isMe)
|
|
517
|
+
.map((p) => flatten(safeString(p.name)))
|
|
518
|
+
.filter((n) => n.length >= MIN_NAME);
|
|
519
|
+
let threatText = ` ${s} `;
|
|
520
|
+
for (const n of meNames)
|
|
521
|
+
threatText = threatText.split(` ${n} `).join(' you ');
|
|
522
|
+
const threatStrength = threat(threatText.trim());
|
|
523
|
+
const truce = truceOf(s, hasQuestion, open, threatStrength !== null);
|
|
524
|
+
put('truce-proposal', truce.proposal);
|
|
525
|
+
put('truce-accept', truce.accept);
|
|
526
|
+
put('truce-decline', truce.decline);
|
|
527
|
+
put('truce-end-notice', truce.end);
|
|
528
|
+
put('coordination-ask', coordinationAsk(s, mentions.players.length > 0));
|
|
529
|
+
// A mutual no-attack offer is a proposal, not a threat; a coercive one ("… if you dont accept truce") is both.
|
|
530
|
+
if (!truce.mutual)
|
|
531
|
+
put('threat', threatStrength);
|
|
532
|
+
// A surrender asked then refused ("I surrender? never") asks none.
|
|
533
|
+
if (!SURRENDER_REFUSED.test(raw.toLowerCase()))
|
|
534
|
+
put('surrender-ask', surrenderAsk(s));
|
|
535
|
+
put('gg', gg(s));
|
|
536
|
+
put('banter', banter(s));
|
|
537
|
+
// "Hey X, … i accept your terms": the opening greeting does not decide a longer message's label (#460).
|
|
538
|
+
if (found.size === 0 || s.split(' ').length <= GREETING_ALONE_WORDS)
|
|
539
|
+
put('greeting', greeting(s));
|
|
540
|
+
if (found.size === 0 && hasQuestion)
|
|
541
|
+
found.set('question-other', 'medium');
|
|
542
|
+
const intents = INTENTS.filter((i) => found.has(i));
|
|
543
|
+
let confidence = 'low';
|
|
544
|
+
if (intents.some((i) => i !== 'question-other' && found.get(i) === 'high'))
|
|
545
|
+
confidence = 'high';
|
|
546
|
+
else if (intents.some((i) => i !== 'question-other'))
|
|
547
|
+
confidence = 'medium';
|
|
548
|
+
const strengths = {};
|
|
549
|
+
for (const i of intents)
|
|
550
|
+
strengths[i] = i === 'question-other' ? 'low' : (found.get(i) ?? 'low');
|
|
551
|
+
const meIds = new Set(players.filter((p) => p?.isMe).map((p) => p.id));
|
|
552
|
+
const repliesToMe = open && (found.has('truce-accept') || found.has('truce-decline'));
|
|
553
|
+
const addressedToMe = c.toMe === true || mentions.players.some((id) => meIds.has(id)) || repliesToMe;
|
|
554
|
+
return { intents, confidence, strengths, addressedToMe, mentions };
|
|
555
|
+
}
|
|
556
|
+
catch {
|
|
557
|
+
return EMPTY();
|
|
558
|
+
}
|
|
559
|
+
}
|