Just for fun, I tried to write my own version of nikkybot in JavaScript.
I used irccloud to download my logs for #cemetech, used some regexes to extract my SAX/IRC messages (about 300kb of text), and wrote some code that implements a Markov Chain. Nothing too fancy.
https://legend-of-iphoenix.github.io/iPhoenixBot/
My 450-ish kb encoded data file is here
My tiny (and fast) function to generate the text is here:
Code:
First param is my data file, second is the maximum number of nodes to read.
Here's the compressed parser function:
Code:
It inputs a string, and outputs a data string for the generate function.
The vaguely readable versions are here, dissect at your own risk. (This was just a short project to take up a few hours, so I wasn't concerned with code quality )
For those who want the details:
- Each node in my chain is a string of regex word characters followed by a string of non-word characters.
- After the initial set of states/nodes are extracted, I attempt to combine nodes that have a 100% chance of feeding into each other. If node "a" exclusively feeds into node "b", then the probabilities for node "a" are set to the probabilities for node "b" and the text in node "b" is appended to node "a".
Let's say there's a node with the text "Hello, " and it always leads into a node with the text "world!". The node waits the text "world!" can lead into many other nodes.
My parser takes the "Hello, " node, changes its text to "Hello world!", and sets the probabilities for the following nodes to the ones found in the "world!" node. The "world!" node is not altered.
As a side effect of my process, links are quite funny:
https://stackoverflow.com/proudloyaltier/timedia#what-if.xkcd.com/file/KMWIbifb/Screen%20Shot%202018-08-07%20at%204.06.27%20PM.png
https://www.youtube.com/Battlesquid/bDiscuss/pull/4
https://status.firebase.auth().currentUser.updateProfile({displayName:"TheLastMillennial"});
https://youtu.be/JqAMxFnWeAI?t=13242&highlight=
https://malwaretips.com/Legend-of-iPhoenix/
https://weblogs.asp.net/forum/viewforum.php?f=r[n]=r[n],r[o],r[n]=r[n],r[n],r[n]=r[o],r[o],r[n]=r[o]=f;return r})([...Array(options||0)].map((a,a string?!
https://www.amazon.com/CE-Programming/toolchain/blob/master/docs/
I think I like the weird links.
I used irccloud to download my logs for #cemetech, used some regexes to extract my SAX/IRC messages (about 300kb of text), and wrote some code that implements a Markov Chain. Nothing too fancy.
https://legend-of-iphoenix.github.io/iPhoenixBot/
My 450-ish kb encoded data file is here
My tiny (and fast) function to generate the text is here:
Code:
function generate(t,a){for(var e=t.split("»"),n=(t=[e[0].split("@").map(t=>t.split("!").map(t=>parseInt(t,36))),e[1].replace(/¶/g,"\n").split("«").map(t=>[t.match(/\|([^]*)/)[1],parseInt(t.match(/\w+/)[0],36)])])[0],r=(t=t[1]).length-1,p=Math,l=t=>p.floor(p.random()*t.length),o=r;o==r;){o=l(t)}var m=0,i="";for(m=0;o!=r&&m<a;m++){i+=t[o][0],o=n[t[o][1]][l(n[t[o][1]])]}document.querySelector('pre').innerText=i}
First param is my data file, second is the maximum number of nodes to read.
Here's the compressed parser function:
Code:
function parse(n){var p=n=>Array.from(new Set(n)),a=[],e=n.match(/.+?\b(?:\W+)?/g).filter(n=>n.length),t=p(e);t.push([]),(e=e.map(n=>t.findIndex(p=>p==n))).push(t.length-1),t=t.map(n=>[n,[],[]]),e.map((n,p)=>{n!=t.length-1&&t[n][1].push(e[p+1])}),t.map((n,p)=>n[1].map(n=>t[n][2].push(p)));for(var m=(n,p)=>(t[n[1][0]][2]=t[n[1][0]][2].filter(n=>n!=p),[n[0]+t[n[1][0]][0],t[n[1][0]][1],n[2]]);t.find(n=>1==n[1].length);){t=t.map((n,p)=>1==n[1].length?m(n,p):n)}return t=(t=t.map((n,p)=>[n[0],n[1],n[2],p]).filter(n=>n[2].length)).map(n=>[n[0],n[1].length?n[1].map(n=>t.findIndex(p=>p[3]==n)):[]]),(a=p(t.map(n=>n[1].join("|"))).map(n=>n.split("|").map(n=>parseInt(n)))).map(n=>n.map(n=>n.toString(36)).join("!")).join("@")+"»"+t.map((n,p)=>[n[0],a.findIndex(p=>p.join("|")==n[1].join("|"))]).map(n=>n[1].toString(36)+("|"+n[0]).replace(/\n/g,"¶")).join("«")}
It inputs a string, and outputs a data string for the generate function.
The vaguely readable versions are here, dissect at your own risk. (This was just a short project to take up a few hours, so I wasn't concerned with code quality )
For those who want the details:
- Each node in my chain is a string of regex word characters followed by a string of non-word characters.
- After the initial set of states/nodes are extracted, I attempt to combine nodes that have a 100% chance of feeding into each other. If node "a" exclusively feeds into node "b", then the probabilities for node "a" are set to the probabilities for node "b" and the text in node "b" is appended to node "a".
Let's say there's a node with the text "Hello, " and it always leads into a node with the text "world!". The node waits the text "world!" can lead into many other nodes.
My parser takes the "Hello, " node, changes its text to "Hello world!", and sets the probabilities for the following nodes to the ones found in the "world!" node. The "world!" node is not altered.
As a side effect of my process, links are quite funny:
https://stackoverflow.com/proudloyaltier/timedia#what-if.xkcd.com/file/KMWIbifb/Screen%20Shot%202018-08-07%20at%204.06.27%20PM.png
https://www.youtube.com/Battlesquid/bDiscuss/pull/4
https://status.firebase.auth().currentUser.updateProfile({displayName:"TheLastMillennial"});
https://youtu.be/JqAMxFnWeAI?t=13242&highlight=
https://malwaretips.com/Legend-of-iPhoenix/
https://weblogs.asp.net/forum/viewforum.php?f=r[n]=r[n],r[o],r[n]=r[n],r[n],r[n]=r[o],r[o],r[n]=r[o]=f;return r})([...Array(options||0)].map((a,a string?!
https://www.amazon.com/CE-Programming/toolchain/blob/master/docs/
I think I like the weird links.