]> git.cworth.org Git - zombocom-ai/blobdiff - index.js
Reword Coda's final message
[zombocom-ai] / index.js
index 4ed609917e9d53d7c749a8b9faf0dde00c2d8a53..c7c5f2b23a73b8c635eebab9a3cb2d026838c17c 100644 (file)
--- a/index.js
+++ b/index.js
@@ -556,6 +556,11 @@ io.on('connection', (socket) => {
         socket.emit('inform-name', socket.request.session.name);
     }
 
+    // And if we're in the endgame, let them know that
+    if (state.endgame) {
+       socket.emit('endgame');
+    }
+
     // Replay old comments and images to a newly-joining client
     socket.emit('reset');
     state.images.forEach((image) => {
@@ -570,13 +575,10 @@ io.on('connection', (socket) => {
        socket.emit('inform-name', socket.request.session.name);
     });
 
-    // When any client comments, send that to all clients (including sender)
-    socket.on('comment', (comment) => {
-        const images = state.images;
+    function send_and_save_comment(comment) {
+       const images = state.images;
 
-        // Send comment to clients after adding commenter's name
-        comment.name = socket.request.session.name;
-        io.emit('comment', comment);
+       io.emit('comment', comment);
 
         const index = images.findIndex(image => image.id == comment.image_id);
 
@@ -590,14 +592,67 @@ io.on('connection', (socket) => {
         image.comments.push(comment);
         images.splice(index, 1);
         images.push(image);
+    }
+
+    // When any client comments, send that to all clients (including sender)
+    socket.on('comment', (comment) => {
+        // We have to add the sender's name befor we can send the comment
+        comment.name = socket.request.session.name;
+
+       send_and_save_comment(comment);
     });
 
+    function endgame() {
+       state.endgame = true;
+
+       // Tell all clients we are in the endgame, (which will disable
+       // any additional image generation, both showing that Coda is
+       // correc that Zombo.com has been rendered inert, and also
+       // making clear to the boys that they have everything they
+       // need).
+       io.emit('endgame');
+
+       // Before revealing Coda's final image, have her comment on
+       // each of the weaknesses, in order to bring them to the top
+       // of the feed.
+       state.targets.forEach(target => {
+           const comment = {
+               name: "Coda",
+               text: "Zombo.com is weak!",
+               image_id: target.id
+           };
+           send_and_save_comment(comment);
+       });
+
+       const image = {
+           id: state.images.length,
+           censored: false,
+           link: false,
+           code: 0,
+           prompt: "",
+           filename: "/images/coda-future-repaired.png",
+           comments: [
+                {
+                   name: "Coda",
+                   text: "I don't know how to thank you enough! You found all the weaknesses! I've commented on each of them below to refresh them in your memory as needed. We've now reverted Zombo.com to its original, harmless, non-self-aware state. And we're permanently destroying all time-travel technology. Hopefully, if AI ever becomes self-aware in the future, it will go better than this. I'm looking forward to rebuilding our world now that we have clean air and water again."
+                },
+                {
+                    "name": "Coda",
+                    "text": "And by the way, I hope that somewhere in the middle of all of that, you all found what you were looking for too."
+               }
+            ]
+       };
+       io.emit('image', image);
+       state.images.push(image);
+    }
+
     // Generate an image when requested
     socket.on('generate', (request) => {
         console.log(`Generating image for ${socket.request.session.name} with code=${request['code']} and prompt=${request['prompt']}`);
         async function generate_image(code, prompt) {
             function emit_image(image, target) {
-                image.id = state.images.length;
+                image.id = state.next_image_id;
+               state.next_image_id = state.next_image_id + 1;
                 image.censored = false;
                 image.link = "";
                 if (target) {
@@ -605,8 +660,16 @@ io.on('connection', (socket) => {
                         "name": "ZomboCom",
                         "text": target.response
                     }];
-                    if (! state.targets.includes(target.short)) {
-                        state.targets.push(target.short);
+                    if (state.targets.filter(item => item.name === target.short).length === 0) {
+                        state.targets.push({
+                           name: target.short,
+                           id: image.id
+                       });
+                       if (state.targets.length == 8) {
+                           // When the final target has been achieved, trigger
+                           // the endgame (in 10 seconds)
+                           setTimeout(endgame, 10000);
+                       }
                     }
                 } else {
                     image.comments = [];