Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- deleteItemInList("all", "asks");
- addToList("Ask me something. Anything!", "asks");
- addToList("What's up?", "asks");
- addToList("What's going on?", "asks");
- deleteItemInList("all", "punctuation");
- addToList(".", "punctuation");
- addToList("?", "punctuation");
- addToList("!", "punctuation");
- addToList(",", "punctuation");
- addToList("-", "punctuation");
- addToList("...", "punctuation");
- addToList("a ", "punctuation"); // add some useless stuff here too
- addToList("an ", "punctuation");
- addToList("the ", "punctuation");
- deleteItemInList("all", "inputs");
- addToList("Hi", "inputs"); // 1
- addToList("Hello", "inputs");
- addToList("Sup", "inputs");
- addToList("Yo", "inputs");
- addToList("Wassup", "inputs"); // 5
- addToList("Hey", "inputs");
- addToList("My", "inputs");
- addToList("name", "inputs");
- addToList("is", "inputs");
- addToList("I'm", "inputs"); // 10
- addToList("I", "inputs");
- addToList("am", "inputs");
- addToList("awesome", "inputs");
- addToList("cool", "inputs");
- addToList("swaggy", "inputs"); // 15
- addToList("epic", "inputs");
- addToList("pro", "inputs");
- addToList("good", "inputs");
- addToList("right", "inputs");
- addToList("wrong", "inputs"); // 20
- addToList("bad", "inputs");
- addToList("happy", "inputs");
- addToList("good", "inputs");
- addToList("well", "inputs");
- addToList("awesome", "inputs"); // 25
- addToList("swaggy", "inputs");
- addToList("epic", "inputs");
- addToList("better", "inputs");
- addToList("great", "inputs");
- addToList("bad", "inputs"); // 30
- addToList("worse", "inputs");
- addToList("sad", "inputs");
- addToList("depressed", "inputs");
- addToList("sick", "inputs");
- deleteItemInList("all", "responses");
- addToList("I am a chatbot. Who are you?", "responses"); // 1
- addToList("Who are you?", "responses");
- addToList("I think you know who I am.", "responses");
- addToList("MegaApuTurkUltra created me.", "responses");
- addToList("That's you!", "responses"); // 5
- addToList("The Scratch Team is the team behind making Scratch!", "responses");
- addToList("I have no idea who that is.", "responses");
- addToList("This website is Scratch.", "responses");
- addToList("My purpose is to be awesome!", "responses");
- addToList("I don't know what your name is. Why don't you tell me?", "responses"); // 10
- addToList("Only you can find that out!", "responses");
- addToList("I don't know what that is.", "responses");
- addToList("Calculating...... It seems to be 42.", "responses");
- addToList("I can't tell you what your future is. Go find it out yourself :)", "responses");
- addToList("Thanks", "responses"); // 15
- addToList("Thanks :)", "responses");
- addToList("Yes I am", "responses");
- addToList("No thanks", "responses");
- addToList("No I'm not!", "responses");
- addToList("Ok then", "responses"); // 20
- addToList("Why don't you make up your mind?", "responses");
- addToList("I don't understand. Is that good or bad?", "responses");
- addToList("That's great!", "responses");
- addToList("That's good to hear", "responses");
- addToList("Good for you!", "responses"); // 25
- addToList("Oh no.", "responses");
- addToList("That's terrible.", "responses");
- addToList("Don't worry. Maybe I can make you feel better :)", "responses");
- addToList("I'm sorry to hear that", "responses");
- sayFor("Hello. I am The Oracle.", 1);
- nextThing = itemOfList(random(1, lengthOfList("asks")), "asks");
- asking = 1;
- name = "";
- while(true){
- // nextThingSSS = capitalizeFirst(nextThing);
- if(!(listContains("punctuation", letterAt(lengthOf(nextThing), nextThing)))){
- nextThing = join(nextThing, ".");
- }
- asking = 1;
- broadcast("wait");
- askAndWait(nextThing);
- asking = 0;
- process(answer());
- interpret();
- }
- @when received "wait" {
- wait(5);
- if(asking == 1){
- say(itemOfList(random(1, lengthOfList("asks")), "asks"));
- }
- }
- def @atomic interpret(){
- if(lengthOfList("words") == 0){
- nextThing = "Whoops! You didn't seem to say anything! Try saying some words!";
- return;
- }
- if(listContains("words", "thanks")){
- nextThing = "You're welcome"; return;
- }
- // answer things starting with you're \/ some people just can't spell
- if((itemOfList(1, "words") == "you're" || itemOfList(1, "words") == "your") || (itemOfList(1, "words") == "you" && (itemOfList(2, "words") == "are" || itemOfList(2, "words") == "aren't") )){
- negation = 0;
- if(itemOfList(2, "words") == "aren't"){negation = 1;}
- negation2 = listContains("words", "not");
- if(negation2 == 1){
- if(negation == 0){negation = 1;} else {negation = 0;}
- }
- good = listContainsList("words", "inputs", 13, 19, 2);
- bad = listContainsList("words", "inputs", 20, 21, 2);
- if(negation == 1){
- if(good==1){good=0;bad=1;}
- else { if(bad==1){bad=0;good=1;} }
- }
- if(good==1 && bad == 1){ nextThing=itemOfList(21, "responses");return; }
- if(good == 1){ nextThing=itemOfList(random(15, 17), "responses");return; }
- if(bad == 1){ nextThing=itemOfList(random(18, 20), "responses");return; }
- if(itemOfList(1, "words") == "welcome"){ nextThing=":)";return; }
- nextThing=itemOfList(20, "responses");return;
- }
- // answer things starting with I'm
- if((itemOfList(1, "words") == "I'm" || itemOfList(1, "words") == "Im") || (itemOfList(1, "words") == "I" && (itemOfList(2, "words") == "am" || itemOfList(2, "words") == "is") )){
- negation = listContains("words", "not");
- good = listContainsList("words", "inputs", 22, 29, 2);
- bad = listContainsList("words", "inputs", 30, 34, 2);
- if(negation == 1){
- if(good==1){good=0;bad=1;}
- else { if(bad==1){bad=0;good=1;} }
- }
- if(good==1 && bad == 1){ nextThing=itemOfList(22, "responses");return; }
- if(good == 1){ nextThing=itemOfList(random(23, 25), "responses");return; }
- if(bad == 1){ nextThing=itemOfList(random(26, 28), "responses");return; }
- nextThing=itemOfList(20, "responses");return;
- }
- // let's answer who and what
- if(listContains("words", "who") && (((listContains("words", "are") || listContains("words", "am")) || listContains("words", "is")))){
- if(listContains("words", "you")) {nextThing=itemOfList(random(1, 3), "responses");return;}
- if(listContains("words", "megaaputurkultra")) {nextThing=itemOfList(4, "responses");return;}
- if(listContains("words", "I")) {nextThing=itemOfList(11, "responses");return;}
- if(listContains("words", username())) {nextThing=itemOfList(5, "responses");return;}
- if(listContains("words", "ST") || (listContains("words", "Scratch") && listContains("words", "Team"))) {nextThing=itemOfList(6, "responses");return;}
- nextThing=itemOfList(7, "responses");return;
- }
- if( (listContains("words", "what") && ((listContains("words", "are") || listContains("words", "is")))) || itemOfList(1, "words") == "Is"){
- if(listContains("words", "Scratch") || listContains("words", "this")) {nextThing=itemOfList(8, "responses");return;}
- if((listContains("words", "your") || listContains("words", "you're")) && (listContains("words", "purpose") || listContains("words", "goal"))) {nextThing=itemOfList(9, "responses");return;}
- if(listContains("words", "my") && listContains("words", "name")) {nextThing=itemOfList(10, "responses");if(name!=""){nextThing = join("Your name is ", name);}return;}
- if(listContains("words", "meaning") && (listContains("words", "life") || listContains("words", "life's"))) {nextThing=itemOfList(13, "responses");return;}
- if(listContains("words", "my") && (listContains("words", "future") || listContains("words", "destiny"))) { nextThing=itemOfList(14, "responses");return; }
- nextThing=itemOfList(12, "responses");return;
- }
- // respond to greetings and name
- hasHello = listContainsList("words", "inputs", 1, 6, 2);
- hasName = returnNext("words", "inputs", 7, 9);
- if(hasName == ""){ hasName = returnNext("words", "inputs", 10, 10); }
- if(hasName == ""){ hasName = returnNext("words", "inputs", 11, 12); }
- name = hasName;
- if(hasHello == 1 && hasName!=""){
- nextThing = join(itemOfList(random(1, 6), "inputs"),join(", ", hasName));return; }
- else { if(hasHello == 1) {
- nextThing = itemOfList(random(1, 6), "inputs"); return;}
- else { if(hasName != "") {
- nextThing = join(itemOfList(random(1, 6), "inputs"),join(", ", join(hasName, ". I'm a chatbot!")));return;
- }}}
- // fallback
- nextThing = "Whoops! I didn't get what you said. Unfortunately I am not as smart as a human! Try saying something easier to understand.";
- }
- def capitalizeFirst(text){ // take advantage of Scratch case insensitivity
- letters="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- for(i=1;i<lengthOf(letters);i++){
- if(letterAt(1, text) == letterAt(i, letters)) {
- text2 = substr(text, 2, lengthOf(text));
- text2 = join(letterAt(i, letters), text2);
- return text2;
- }
- }
- return text;
- }
- def returnNext(haystack, needle, nstart, nend){
- for(i=1;i<=lengthOfList(haystack);i++){
- found = 1;
- for(j=nstart;j<=nend;j++){
- if(!(itemOfList(i+j - nstart, haystack) == itemOfList(j, needle))){ found = 0;}
- }
- if(found == 1){ return itemOfList(i+nend - nstart + 1, haystack); }
- }
- return "";
- }
- def listContainsList(haystack, needle, nstart, nend, andOr){
- for(i=nstart;i<=nend;i++){
- if(andOr == 1 && !(listContains(haystack, itemOfList(i, needle)))){ return 0;}
- if(andOr == 2 && listContains(haystack, itemOfList(i, needle))){ return 1;}
- }
- if(andOr==1){return 1;}
- if(andOr==2){return 0;}
- }
- def @atomic process(a2){
- a = a2;
- // replace all punctuation with spaces so we can delete them away later
- for(p = 1;p<=lengthOfList("punctuation");p++){
- a = replace(a, itemOfList(p, "punctuation"), " ");
- }
- // split up words
- deleteItemInList("all", "words");
- split(join(a, " "), " ", "words");
- //delete blanks
- for(i=0;i<lengthOfList("words");i++){
- item = itemOfList(i+1, "words");
- if(item==""){ // luckily the way ApuC is implemented
- // length is constantly re-evaluated.
- // So we decrese i by 1
- deleteItemInList(i+1, "words");
- i--;
- }
- }
- }
- def replace(haystack, needle, replacement){
- newString = "";
- for(i=1;i<=lengthOf(haystack);i++){
- matches = substrMatches(haystack, needle, i);
- if(matches == 1){
- newString = join(newString, replacement);
- i+=lengthOf(needle) - 1;
- } else {
- newString = join(newString, letterAt(i, haystack));
- }
- }
- return newString;
- }
- def @atomic split(string, delim, arrayName){
- currentItem = "";
- for(i=1;i<=lengthOf(string);i++){
- delimFound = substrMatches(string, delim, i);
- if(delimFound == 1){
- i+=lengthOf(delim) - 1;
- addToList(currentItem, arrayName);
- currentItem = "";
- } else {
- currentItem = join(currentItem, letterAt(i, string));
- }
- }
- }
- def substrMatches(haystack, needle, startIndex){
- for(j=1;j<=lengthOf(needle);j++){
- if(!(letterAt(j+startIndex - 1, haystack) == letterAt(j, needle))){
- return 0;
- }
- }
- return 1;
- }
- def substr(string, startIndex, endIndex){
- substr = "";
- for(i=startIndex;i<=endIndex;i++){
- substr = join(substr, letterAt(i, string));
- }
- return substr;
- }
Advertisement
Add Comment
Please, Sign In to add comment