-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patharcade-chatbot-engine.js
More file actions
497 lines (455 loc) ยท 24 KB
/
Copy patharcade-chatbot-engine.js
File metadata and controls
497 lines (455 loc) ยท 24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
/**
* Signal Share Arcade Chatbot Engine
* Implements a keyword-based intent system to trigger app actions.
* This "algorithm" allows the companion to feel like an A.I. by reacting to specific commands.
*/
/**
* Helper function to call handlePlayPauseAction from chatbot engine
*/
function callHeroPlayPauseAction(heroController, forcePlay) {
if (!heroController || typeof heroController.handlePlayPause !== 'function') return;
// Gather context from global state
const state = window.state || {};
const elements = window.elements || {};
const target = null; // Chatbot doesn't have specific target
// Create minimal context object for handlePlayPauseAction
const context = {
state,
elements,
getControllablePlayerPost: () => {},
heroMode: state.heroControlMode || 'feed',
render: () => {},
nativeSnapshot: null,
performNativeAction: () => false,
NATIVE_ACTION_PLAY_PAUSE: 'play_pause',
desktopSnapshot: null,
performDesktopAction: () => Promise.resolve(false),
DESKTOP_ACTION_PLAY_PAUSE: 'play_pause',
isNativeCapacitorApp: () => false,
companionPromptDismissed: true,
showCompanionPrompt: () => {},
toggleLocalPlayback: () => {},
playHeroMedia: () => {},
getNativeBridge: () => null,
target,
getActivePlayerMediaElement: () => null,
normalizePlaybackState: (value) => value || 'none',
refreshDesktopSnapshot: () => {},
refreshNativeSnapshot: () => {}
};
// Call the actual action handler
heroController.handlePlayPause(context, forcePlay);
}
window.ArcadeChatbotEngine = (function() {
const intentHandlers = [
// GAMES & LAUNCHERS
{
keywords: ['pinball', 'flipper', 'bumper'],
action: () => {
if (typeof window.launchPinball === 'function') window.launchPinball();
else if (typeof window.showGameDetails === 'function') window.showGameDetails('pinball');
return "๐น๏ธ [Arcade Protocol]: Initializing Neon Pinball. Keep your eye on the ball!";
}
},
{
keywords: ['snake', 'cobra', 'slither'],
action: () => {
if (typeof window.launchSnake === 'function') window.launchSnake();
else if (typeof window.showGameDetails === 'function') window.showGameDetails('snake');
return "๐น๏ธ [Arcade Protocol]: Deploying Neon Snake. Data consumption initialized.";
}
},
{
keywords: ['basketball', 'hoops', 'dunk', 'ball'],
action: () => {
if (typeof window.launchBasketball === 'function') window.launchBasketball();
else if (typeof window.showGameDetails === 'function') window.showGameDetails('basketball');
return "๐น๏ธ [Arcade Protocol]: Entering the court. Neon Hoops is ready.";
}
},
{
keywords: ['calc', 'calculator', 'math'],
action: (text) => {
const mathMatch = text.match(/calculate\s+([\d\s\+\-\*\/\(\)\.]+)/i);
if (mathMatch) {
try {
// Safe evaluation of simple math
const result = Function('"use strict";return (' + mathMatch[1] + ')')();
return `๐งฎ [Utility Protocol]: Calculation complete. ${mathMatch[1]} = ${result}`;
} catch (e) {
return "๐งฎ [Utility Protocol]: I couldn't parse that math expression. Try something simpler!";
}
}
if (typeof window.launchCalc === 'function') window.launchCalc();
else if (typeof window.showGameDetails === 'function') window.showGameDetails('calc');
return "๐งฎ [Utility Protocol]: Opening the Scientific Calculator.";
}
},
{
keywords: ['find', 'search', 'where is', 'look for'],
action: (text) => {
const query = text.toLowerCase()
.replace(/find|search|where is|look for/g, '')
.replace(/\bin\b|\bthe\b|\beditor\b|\bcode\b/g, '')
.replace(/[?.!]/g, '')
.trim();
if (!query) return "๐ [Search Protocol]: What would you like me to find in the editor?";
if (typeof window.handleAiSearchCommand === 'function') {
const result = window.handleAiSearchCommand(query);
if (result && result.ok) {
return `๐ [Search Protocol]: Found "${result.match}" on line ${result.line}. I've centered the editor for you.`;
}
return `๐ [Search Protocol]: I couldn't find "${query}" in the active file. Try a different keyword?`;
}
return "๐ [Search Protocol]: The editor search engine is not available. Please enter Workshop > Edit mode first.";
}
},
{
keywords: ['library', 'games'],
action: () => {
if (typeof window.setCategory === 'function') window.setCategory('all');
if (typeof window.showLibrary === 'function') window.showLibrary();
return "๐น๏ธ [Library Protocol]: Opening your game collection.";
}
},
{
keywords: ['leaderboard', 'high score', 'rank'],
action: () => {
if (typeof window.setCategory === 'function') window.setCategory('leaderboard');
return "๐ [Leaderboard Protocol]: Fetching global telemetry and rankings.";
}
},
{
keywords: ['shop', 'store'],
action: () => {
if (typeof window.setCategory === 'function') window.setCategory('store');
return "๐ช [Store Protocol]: Accessing the Signal Share Store.";
}
},
// MEDIA CONTROLS
{
keywords: ['pause', 'stop', 'hold'],
action: (text) => {
const query = text.toLowerCase();
const forceFeed = query.includes('on feed') || query.includes('on signal share') || query.includes('signal');
if (window.heroMediaPlayerController) {
let targetSource = null;
if (query.includes('spotify')) targetSource = 'spotify';
else if (query.includes('youtube')) targetSource = 'youtube';
if (targetSource) {
const isSystemActive = typeof window.heroMediaPlayerController.isSourceActiveOnSystem === 'function' &&
window.heroMediaPlayerController.isSourceActiveOnSystem(targetSource);
if (isSystemActive && !forceFeed) {
if (typeof window.heroMediaPlayerController.setHeroControlMode === 'function') {
window.heroMediaPlayerController.setHeroControlMode('media');
}
} else {
if (typeof window.heroMediaPlayerController.setHeroControlMode === 'function') {
window.heroMediaPlayerController.setHeroControlMode('feed');
}
}
if (typeof window.heroMediaPlayerController.setHeroControlSource === 'function') {
window.heroMediaPlayerController.setHeroControlSource(targetSource);
}
}
// FIXED: Use handlePlayPauseAction instead of non-existent .pause() method
callHeroPlayPauseAction(window.heroMediaPlayerController, false);
}
return "๐ต [Media Protocol]: Pausing active playback.";
}
},
{
keywords: ['play', 'resume', 'start'],
action: (text) => {
const query = text.toLowerCase();
const forceFeed = query.includes('on feed') || query.includes('on signal share') || query.includes('signal');
if (window.heroMediaPlayerController) {
let targetSource = null;
if (query.includes('spotify')) targetSource = 'spotify';
else if (query.includes('youtube')) targetSource = 'youtube';
if (targetSource) {
const isSystemActive = typeof window.heroMediaPlayerController.isSourceActiveOnSystem === 'function' &&
window.heroMediaPlayerController.isSourceActiveOnSystem(targetSource);
if (isSystemActive && !forceFeed) {
if (typeof window.heroMediaPlayerController.setHeroControlMode === 'function') {
window.heroMediaPlayerController.setHeroControlMode('media');
}
} else {
if (typeof window.heroMediaPlayerController.setHeroControlMode === 'function') {
window.heroMediaPlayerController.setHeroControlMode('feed');
}
}
if (typeof window.heroMediaPlayerController.setHeroControlSource === 'function') {
window.heroMediaPlayerController.setHeroControlSource(targetSource);
}
}
// FIXED: Use handlePlayPauseAction instead of non-existent .play() method
callHeroPlayPauseAction(window.heroMediaPlayerController, true);
}
return "๐ต [Media Protocol]: Resuming media playback.";
}
},
{
keywords: ['next', 'skip'],
action: (text) => {
const query = text.toLowerCase();
const forceFeed = query.includes('on feed') || query.includes('on signal share') || query.includes('signal');
if (window.heroMediaPlayerController) {
let targetSource = null;
if (query.includes('spotify')) targetSource = 'spotify';
else if (query.includes('youtube')) targetSource = 'youtube';
if (targetSource) {
const isSystemActive = typeof window.heroMediaPlayerController.isSourceActiveOnSystem === 'function' &&
window.heroMediaPlayerController.isSourceActiveOnSystem(targetSource);
if (isSystemActive && !forceFeed) {
if (typeof window.heroMediaPlayerController.setHeroControlMode === 'function') {
window.heroMediaPlayerController.setHeroControlMode('media');
}
} else {
if (typeof window.heroMediaPlayerController.setHeroControlMode === 'function') {
window.heroMediaPlayerController.setHeroControlMode('feed');
}
}
if (typeof window.heroMediaPlayerController.setHeroControlSource === 'function') {
window.heroMediaPlayerController.setHeroControlSource(targetSource);
}
}
if (typeof window.heroMediaPlayerController.next === 'function') {
window.heroMediaPlayerController.next();
}
}
return "๐ต [Media Protocol]: Skipping to the next track.";
}
},
{
keywords: ['previous', 'back', 'prev'],
action: (text) => {
const query = text.toLowerCase();
const forceFeed = query.includes('on feed') || query.includes('on signal share') || query.includes('signal');
if (window.heroMediaPlayerController) {
let targetSource = null;
if (query.includes('spotify')) targetSource = 'spotify';
else if (query.includes('youtube')) targetSource = 'youtube';
if (targetSource) {
const isSystemActive = typeof window.heroMediaPlayerController.isSourceActiveOnSystem === 'function' &&
window.heroMediaPlayerController.isSourceActiveOnSystem(targetSource);
if (isSystemActive && !forceFeed) {
if (typeof window.heroMediaPlayerController.setHeroControlMode === 'function') {
window.heroMediaPlayerController.setHeroControlMode('media');
}
} else {
if (typeof window.heroMediaPlayerController.setHeroControlMode === 'function') {
window.heroMediaPlayerController.setHeroControlMode('feed');
}
}
if (typeof window.heroMediaPlayerController.setHeroControlSource === 'function') {
window.heroMediaPlayerController.setHeroControlSource(targetSource);
}
}
if (typeof window.heroMediaPlayerController.previous === 'function') {
window.heroMediaPlayerController.previous();
}
}
return "๐ต [Media Protocol]: Returning to the previous track.";
}
},
{
keywords: ['volume', 'louder', 'quieter', 'mute'],
action: () => {
return "๐ [Audio Protocol]: You can adjust the volume slider in the Media Player dock.";
}
},
{
keywords: ['spotify', 'youtube', 'open spotify', 'open youtube', 'launch spotify', 'launch youtube'],
action: async (text) => {
const query = text.toLowerCase();
const isSpotify = query.includes('spotify');
const isYouTube = query.includes('youtube');
const forceFeed = query.includes('on feed') || query.includes('on signal share') || query.includes('signal');
if (window.heroMediaPlayerController) {
const targetSource = isSpotify ? 'spotify' : (isYouTube ? 'youtube' : null);
if (targetSource) {
const isSystemActive = typeof window.heroMediaPlayerController.isSourceActiveOnSystem === 'function' &&
window.heroMediaPlayerController.isSourceActiveOnSystem(targetSource);
if (isSystemActive && !forceFeed) {
if (typeof window.heroMediaPlayerController.setHeroControlMode === 'function') {
window.heroMediaPlayerController.setHeroControlMode('media');
}
} else {
if (typeof window.heroMediaPlayerController.setHeroControlMode === 'function') {
window.heroMediaPlayerController.setHeroControlMode('feed');
}
}
if (typeof window.heroMediaPlayerController.setHeroControlSource === 'function') {
window.heroMediaPlayerController.setHeroControlSource(targetSource);
}
}
if (query.includes('open') || query.includes('launch')) {
if (typeof window.heroMediaPlayerController.openNowPlayingMediaApp === 'function') {
if (isSpotify) {
await window.heroMediaPlayerController.openNowPlayingMediaApp("com.spotify.music", "spotify:");
return "๐ต [Media Protocol]: Opening Spotify...";
}
if (isYouTube) {
await window.heroMediaPlayerController.openNowPlayingMediaApp("com.google.android.youtube", "https://www.youtube.com");
return "๐ต [Media Protocol]: Opening YouTube...";
}
}
}
}
if (isSpotify) return "๐ต [Media Protocol]: Switching control to Spotify.";
if (isYouTube) return "๐ต [Media Protocol]: Switching control to YouTube.";
return "๐ต [Media Protocol]: Media control source updated.";
}
},
// THEMES & CUSTOMIZATION
{
keywords: ['theme', 'color', 'midnight', 'sunset', 'forest', 'ocean', 'paper', 'ember'],
action: (text) => {
const query = text.toLowerCase();
const themes = ['midnight', 'sunset', 'forest', 'ocean', 'paper', 'ember'];
const matched = themes.find(t => query.includes(t));
if (matched && typeof window.updateUserPreferences === 'function') {
window.updateUserPreferences({ theme: matched });
return `๐จ [UI Protocol]: Applying the ${matched.charAt(0).toUpperCase() + matched.slice(1)} theme.`;
}
return "๐จ [UI Protocol]: Which theme would you like? (Midnight, Sunset, Forest, Ocean, Paper, Ember)";
}
},
{
keywords: ['dark mode', 'dark'],
action: () => {
if (typeof window.updateUserPreferences === 'function') window.updateUserPreferences({ theme: 'midnight' });
return "๐จ [UI Protocol]: Dark Mode engaged.";
}
},
// NAVIGATION & UI
{
keywords: ['scroll to top', 'scroll up', 'go up'],
action: () => {
const content = document.querySelector('.steam-content') || window;
content.scrollTo({ top: 0, behavior: 'smooth' });
return "๐ [Nav Protocol]: Scrolling to the top.";
}
},
{
keywords: ['scroll to bottom', 'scroll down', 'go down'],
action: () => {
const content = document.querySelector('.steam-content') || window;
content.scrollTo({ top: (content.scrollHeight || document.body.scrollHeight), behavior: 'smooth' });
return "๐ [Nav Protocol]: Jumping to the bottom.";
}
},
{
keywords: ['profile', 'account'],
action: () => {
if (typeof window.openOwnProfile === 'function') window.openOwnProfile();
return "๐ค [Profile Protocol]: Opening your Signal Share profile.";
}
},
{
keywords: ['settings', 'preferences'],
action: () => {
if (typeof window.openSettingsPanel === 'function') window.openSettingsPanel();
return "โ๏ธ [System Protocol]: Opening application settings.";
}
},
{
keywords: ['messenger', 'chat', 'messages'],
action: () => {
if (typeof window.openMessengerDock === 'function') window.openMessengerDock({ expanded: true });
return "๐ฌ [Comms Protocol]: Opening the Messenger interface.";
}
},
// SYSTEM & STATUS
{
keywords: ['bridge', 'status', 'connection'],
action: () => {
const online = window.__BRIDGE_ONLINE__;
return `๐ก [Bridge Protocol]: Status: ${online ? "ONLINE" : "OFFLINE"}. Local LLM is ${online ? "ready for inference" : "currently unavailable"}.`;
}
},
{
keywords: ['clear', 'new chat'],
action: () => {
if (typeof window.startNewChat === 'function') window.startNewChat();
return "๐งน [System Protocol]: Session cleared. Starting a fresh conversation.";
}
},
{
keywords: ['shortcuts', 'keys'],
action: () => {
if (typeof window.openKeyboardShortcutsPanel === 'function') window.openKeyboardShortcutsPanel();
return "โจ๏ธ [Help Protocol]: Displaying active keyboard shortcuts.";
}
},
// STRATEGY & TIPS
{
keywords: ['strategy', 'tip', 'how to'],
action: (text) => {
const query = text.toLowerCase();
if (query.includes('snake')) return "๐ [Strategy]: Stay near the edges early on to maximize space. Use quick turns to trap your own tail in a controlled loop.";
if (query.includes('pinball')) return "๐ฎ [Strategy]: Aim for the bumpers to build your multiplier. Use the flippers together to trap the ball for a precision shot.";
if (query.includes('hoops')) return "๐ [Strategy]: Timing is everything. Release the ball at the peak of your jump for maximum accuracy.";
return "๐ก [Tip Protocol]: Which game do you need help with? I have strategies for Snake, Pinball, and Hoops.";
}
},
// FUN / EASTER EGGS
{
keywords: ['barrel roll'],
action: () => {
document.body.style.transition = "transform 1s";
document.body.style.transform = "rotate(360deg)";
setTimeout(() => document.body.style.transform = "", 1000);
return "๐น๏ธ [Easter Egg]: Do a barrel roll! Initiating sequence...";
}
},
{
keywords: ['joke', 'funny'],
action: () => {
const jokes = [
"Why did the gamer stay in bed? Because he had 'lag'.",
"I asked the A.I. to make me a sandwich. It said: 'SUDO make sandwich'.",
"How many programmers does it take to change a lightbulb? None, that's a hardware problem.",
"What's a gamer's favorite snack? Micro-chips."
];
return "๐ค [Humor Protocol]: " + jokes[Math.floor(Math.random() * jokes.length)];
}
},
{
keywords: ['konami code'],
action: () => {
return "๐น๏ธ [Easter Egg]: โ โ โ โ โ โ โ โ B A. 30 Lives added! (Metaphorically speaking).";
}
},
{
keywords: ['meaning of life', '42'],
action: () => {
return "๐พ [Deep Protocol]: 42. And also, achieving a new high score in the arcade.";
}
},
{
keywords: ['hello', 'hi ', 'hey'],
action: () => {
return "๐ [Arcade Protocol]: Greetings! I am your companion. I can help you launch games, control media, or change the theme. What's on your mind?";
}
}
];
return {
processIntent: function(text) {
const query = (text || "").toLowerCase().trim();
if (!query) return null;
// Check each handler
for (const handler of intentHandlers) {
// If any keyword is found as a whole word or significant part
if (handler.keywords.some(keyword => {
const regex = new RegExp(`\\b${keyword}\\b`, 'i');
return regex.test(query) || (keyword.length > 3 && query.includes(keyword));
})) {
return handler.action(text);
}
}
return null;
}
};
})();