Pumping pads as files into publishing frameworks!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

107 lines
30 KiB

<html>
<head>
<script src="/versions.js"></script>
<link href="../stylesheet.css" rel="stylesheet">
<link href="https://pad.vvvvvvaria.org/p/relearn_hooks" rel="alternate" title="Etherpad" type="text/html">
<link href="relearn_hooks.raw.txt" rel="alternate" title="Plain text" type="text/plain">
<link href="relearn_hooks.raw.html" rel="alternate" title="HTML" type="text/html">
<link href="relearn_hooks.meta.json" rel="alternate" title="Meta data" type="application/json">
<meta charset="utf-8">
<title>relearn_hooks</title>
</head>
<body># __PUBLISH__<br>
<br># RELEARN HOOKS FILE<br>#---------------------------------<br>
<br>        # Please take a look at the reroamingguide to see which currently added hooks and commands are available or modified, how to use them and what they do.<br>        # <a href="http://relearn.local:9001/p/reroamingguide" rel="noreferrer noopener">http://relearn.local:9001/p/reroamingguide</a>
<br>        # Take care, this file is directly used by the server for every user logging into the server!<br>
<br>#---------------------------------<br>
<br>
<br>
<br>#example message<br>#----------------------------<br>#using the echo command we can send messages back to the user<br># echo "hello!"<br>#inside that we can also use some variables, such as:<br># $1  = Is replaced with the command sent by the user<br># $USER = Is replaced with the user's name<br>
<br>
<br>#example basic if statement<br>#----------------------------<br># if [[ $1 == ls ]]   &lt;- This is the comparison. $1 is the entered command, ls is what it is being compared against. Spaces after [ and before ] are neccesary! Comparisons are not flexible, so "ls blabla" will not trigger this, only "ls"<br># then<br>#     echo "message you want to send"  <br># fi  &lt;- fi (reverse 'if') is used to end the statement, if the statement in "if' is correct all code between then and fi will be executed.<br>#----------------------------<br>
<br>
<br>#example 'blanket' or partial if statement<br>#----------------------------<br>#Writing a partial if statement works the same as above, but in the if line you write the following:<br># if [[ $1 == *cd* ]]<br>#where cd is whatever you're trying to find. If cd is found in $1 (The command sent), it will return true and execute the code below (Until fi)<br>#the asterisk allows for any words to be before or after cd.<br>#----------------------------<br>
<br>
<br>#example "swallowing" or blocking the statement<br>#----------------------------<br>#If you want to respond to a command but prevent it from executing, you can use the following commands;<br># shopt -s extdebug<br># return 1;<br># by enabling this and returning something other than 0, it will stop where it is and never reach execution of the command.<br>#----------------------------<br>
<br>
<br>#example text input<br>#----------------------------<br>#If you want to ask the user for input and use it elsewhere, try the following:<br># echo "What's your answer?"<br># read answer<br># read gives a user input prompt and waits for the user to enter data and hit enter.<br># Once done, it stores it inside $answer, which can then be used for other if statements!<br>#----------------------------<br>
<br>
<br>
<br>#useful links<br>#----------------------------<br># <a href="https://ryanstutorials.net/bash-scripting-tutorial/bash-if-statements.php" rel="noreferrer noopener">https://ryanstutorials.net/bash-scripting-tutorial/bash-if-statements.php</a>
<br># <a href="https://learnxinyminutes.com/docs/bash/" rel="noreferrer noopener">https://learnxinyminutes.com/docs/bash/</a>
<br># <a href="https://devhints.io/bash" rel="noreferrer noopener">https://devhints.io/bash</a>
<br>#----------------------------<br>
<br>
<br>preexec() { <br>      source /opt/hooks/hooks           #This links the published etherpad file to the server's hooks file. Leave this to allow updating! See cronjobs.<br>
<br>        # unsudo lottery plsssss "congratz you lost your sudo privileges, enjoy your free time"<br>        if [[ $RANDOM == 1 ]]<br>        then<br>                echo "CONGRATULATIONS!" | lolcat<br>                echo "You are today's winner of the bash-lottery." | lolcat<br>        fi<br>
<br>        if [[ $1 == ls ]];<br>        then<br>                echo "I'll show you..."<br>        fi<br>
<br>        if [[ $1 == time ]];<br>        then<br>                echo "time for beer!"<br>        fi<br>
<br>        if [[ $1 == touch* ]];<br>        then<br>                echo "No touching!"<br>        fi<br>
<br>        if [[ $1 == exit ]];<br>        then<br>                echo "you're stuck here… FOREVAAAAAA"<br>                sleep 2<br>                echo "just joking, do logout instead"<br>                shopt -s extdebug  <br>                return 1<br>        fi<br>
<br>        if [[ $1 == heyfriends ]];<br>        then<br>          who | grep -Eo '^[^ ]+'<br>                shopt -s extdebug  <br>                return 1<br>        fi<br>
<br>        if [[ $1 == hello* ]];<br>        then<br>                echo "Hi $USER! What's up?" | lolcat<br>                read mood<br>                if [[ $mood == *no* ]]<br>                then<br>                        echo "Sorry to hear that, $USER. Anything I can do to help?" | lolcat<br>                        read uselessanswer<br>                else<br>                        echo "Glad to hear, keep up the good vibes!" | lolcat<br>                fi<br>                shopt -s extdebug   #stops "hello" from executing, which would give a "command not found" error.<br>                return 1<br>        fi<br>
<br>        if [[ $1 == *apt-get* ]];<br>        then<br>                echo "Thank you $USER for your maintenance efforts! Our community really appreciates it" | lolcat<br>        fi<br>
<br>        if [[ $1 == guide* ]];<br>        then<br>                split=($1)<br>                echo ${split[1]}<br>                man /opt/guides/${split[1]}.1<br>                shopt -s extdebug<br>                return 1<br>        fi<br>
<br>        if [[ $1 == ssh* ]];<br>        then<br>                if [[ $(( ( RANDOM % 10 )  + 1 )) == 1 ]]<br>                then<br>                        echo "Not today, maybe later..." | lolcat<br>                        shopt -s extdebug<br>                        return 1<br>                fi<br>        fi<br>
<br>
<br>        if [[ $1 == *adduser* ]];<br>
<br>            then<br>                   inputcommand=($1)<br>                   echo "What is your preferred pronoun?" | lolcat<br>                   read answer<br>                   if [[ $answer ]]<br>                   then <br>                            echo $answer &gt; ${inputcommand[2]}pronoun.txt<br>                        fi<br>            sudo adduser ${inputcommand[2]}<br>            sudo mv ${inputcommand[2]}pronoun.txt /home/${inputcommand[2]}/pronoun.txt<br>            shopt -s extdebug<br>            return 1<br>        fi<br>
<br>        if [[ $1 == *reroaming* ]];<br>        then<br>            argument=($1)<br>            if [[ ${argument[1]} == howto ]];<br>            then<br>                man /opt/guides/howto.1<br>          fi<br>            if [[ ${argument[1]} == guide ]];<br>            then<br>                sed '/__PUBLISH__/d' /opt/guides/guide | fold | lolcat<br>            fi<br>            if [[ ${argument[1]} == why ]];<br>            then<br>                man /opt/guides/why.1<br>            fi<br>            shopt -s extdebug <br>            return 1<br>
<br>        fi<br>
<br>
<br>        if [[  -e "tellme.txt" &amp;&amp; $1 == *"tellme"* ]]<br>        then<br>            name="name called title"<br>            what="info explain folder what"<br>            why="why because"<br>            how="how instructions use"<br>            when="when time past history"<br>            who="who author creator owner user" <br>
<br>            tell () {<br>                    if [[ ${@:0:1} == "@" ]]<br>                    then<br>                            eval ${@:1:-1}<br>                    else<br>                             echo "$@" | pv -qL 128<br>                             echo " "<br>                     fi<br>            }<br>
<br>            captured_command=0<br>
<br>            for per_word in $1; do<br>                    if [[ $name == *"$per_word"* ]]<br>                    then<br>                            tell $(grep -A 2 '#name' "tellme.txt" | grep -v "#name")<br>                            captured_command=1<br>                            break<br>                    elif [[ $what == *"$per_word"* ]]<br>                    then<br>                            tell $(grep -A 2 '#what' "tellme.txt" | grep -v "#what")<br>                            captured_command=1<br>                            break<br>                    elif [[ $why == *"$per_word"* ]]<br>                    then<br>                            tell $(grep -A 2 '#why' "tellme.txt" | grep -v "#why")<br>                            captured_command=1<br>                            break<br>                    elif [[ $how == *"$per_word"* ]]<br>                    then<br>                            tell $(grep -A 2 '#how' "tellme.txt" | grep -v "#how")<br>                            captured_command=1<br>                            break<br>                    elif [[ $when == *"$per_word"* ]]<br>                    then<br>                            tell $(grep -A 2 '#when' "tellme.txt" | grep -v "#when")<br>                            captured_command=1<br>                            break<br>                    elif [[ $who == *"$per_word"* ]]<br>                    then<br>                            tell $(grep -A 2 '#who' "tellme.txt" | grep -v "#who")<br>                            captured_command=1<br>                            break<br>                    fi<br>            done<br>
<br>            if [[ $captured_command == 1 ]]<br>            then<br>                shopt -s extdebug  <br>                return 1<br>            fi<br>        fi<br>
<br>        if [[ $1 == *"explainthis"* ]]<br>        then<br>
<br>            tell () {<br>                    if [[ ${@:0:1} == "@" ]]<br>                    then<br>                            eval ${@:1:-1}<br>                    else<br>                                  echo " "<br>                             echo "$@" | pv -qL 128<br>                             echo " "<br>                     fi<br>            }<br>
<br>            tell "Thanks for taking the time to explain your work! I will ask you some questions about what you've done. You are free to leave questions unanswered."<br>            tell "What is your project or folder called?"<br>            read new_name<br>            tell "How would you describe your work in a short sentence?"<br>            read new_what<br>            tell "What's your name or nickname?"<br>            read new_who<br>            tell "When did you create this work?"<br>            read new_when<br>            tell "Why did you create this work?"<br>            read new_why<br>            tell "How did you create this work?"<br>            read new_how<br>            tell "Thanks, I'll document it! You can use the tellme command (tellme how, tellme why, etc) to query other folders."<br>            &gt; tellme.txt<br>            echo "#name" &gt;&gt; tellme.txt<br>            echo $new_name &gt;&gt; tellme.txt<br>            echo " " &gt;&gt; tellme.txt<br>            echo "#who" &gt;&gt; tellme.txt<br>            echo $new_who &gt;&gt; tellme.txt<br>            echo " " &gt;&gt; tellme.txt<br>            echo "#what" &gt;&gt; tellme.txt<br>            echo $new_what &gt;&gt; tellme.txt<br>            echo " " &gt;&gt; tellme.txt<br>            echo "#when" &gt;&gt; tellme.txt<br>            echo $new_when &gt;&gt; tellme.txt<br>            echo " " &gt;&gt; tellme.txt<br>            echo "#why" &gt;&gt; tellme.txt<br>            echo $new_why &gt;&gt; tellme.txt<br>            echo " " &gt;&gt; tellme.txt<br>            echo "#how" &gt;&gt; tellme.txt<br>            echo $new_how &gt;&gt; tellme.txt<br>            echo " " &gt;&gt; tellme.txt<br>            shopt -s extdebug  <br>            return 1<br>        fi<br>
<br>
<br>
<br>
<br>      if [[ $1 == tour ]];<br>      then<br>        echo "hello $USER, welcome to the filesystem tour" | lolcat<br>        echo ""<br>        echo '/\/\/\/\/\/\/\/\/\/\' | lolcat | pv -qL 8<br>        echo ""<br>        echo 'FIRST STOP!' | lolcat<br>
<br>
<br>        cd ~<br>
<br>        echo "This directory is your home directory. Cozy, isn't it?" | lolcat<br>        sleep 1 <br>        echo "here's a picture of the landscape" | lolcat<br>        echo ""<br>        ls -la | lolcat<br>        echo ""<br>
<br>        shopt -s extdebug<br>        return 1<br>
<br>      fi<br>
<br>
<br>        #add a tour guide persona, telling you pwd<br>        if [[ $1 == whereami ]];<br>        then<br>          echo "you are here, don't get lost :)"<br>       pwd<br>       shopt -s extdebug<br>        fi<br>
<br>
<br>#Sorry, unnecesary code for fun! Visit home/stone_castle_room and ls to take a look at what this code does.<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>if [[ $1 == *"createobject"* ]]<br>then<br>
<br>    tell () {<br>            if [[ ${@:0:1} == "@" ]]<br>            then<br>                    eval ${@:1:-1}<br>            else<br>                     echo "$@" | pv -qL 128<br>                     echo " "<br>             fi<br>    }<br>
<br>    tell "Glad to hear you'd like to add an object!"<br>    tell "What is your object called? (one word that people reference it by)"<br>    read obj_name<br>    tell "What would you see if you looked at/read it closely?"<br>    read obj_look<br>    tell "What would happen if you touched/hit/caressed it?"<br>    read obj_touch<br>    tell "What would happen if you took/stole it?"<br>    read obj_take<br>    tell "What would happen if you used/talked/employed it?"<br>    read obj_use<br>    tell "Thanks, I'll create it here!"<br>    &gt; $obj_name .txt<br>    echo $obj_name &gt;&gt; $obj_name .txt<br>    echo " " &gt;&gt; $obj_name .txt<br>    echo "#look" &gt;&gt; $obj_name .txt<br>    echo $obj_look &gt;&gt; $obj_name .txt<br>    echo " " &gt;&gt; $obj_name .txt<br>    echo "#touch" &gt;&gt; $obj_name .txt<br>    echo $obj_touch &gt;&gt; $obj_name .txt<br>    echo " " &gt;&gt; $obj_name .txt<br>    echo "#take" &gt;&gt; $obj_name .txt<br>    echo $obj_take &gt;&gt; $obj_name .txt<br>    echo " " &gt;&gt; $obj_name .txt<br>    echo "#use" &gt;&gt; $obj_name .txt<br>    echo $obj_use &gt;&gt; $obj_name .txt<br>    shopt -s extdebug  <br>    return 1<br>fi<br>
<br>
<br>if [[ $1 == *"createroom"* ]]<br>then<br>
<br>    tell () {<br>            if [[ ${@:0:1} == "@" ]]<br>            then<br>                    eval ${@:1:-1}<br>            else<br>                     echo "$@" | pv -qL 128<br>                     echo " "<br>             fi<br>    }<br>
<br>    tell "Glad to hear you'd like to create a room!"<br>    tell "What is your room called? (one word that people reference it by)"<br>    read room_name<br>    tell "What would you see if you looked around?"<br>    read room_description<br>    tell "Thanks, I'll create it here!"<br>    sudo mkdir $room_name<br>    sudo chmod +777 $room_name<br>    cd $room_name<br>    &gt; room.txt<br>    echo $room_description &gt;&gt; room.txt<br>    shopt -s extdebug  <br>    return 1<br>fi<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>        answer=$1<br>        if [[ $answer != "exit" &amp;&amp; $answer != "logout" &amp;&amp; -e "room.txt" ]]<br>        then<br>
<br>                use="use apply employ exploit handle operate manipulate manage speak talk say"<br>                leave="back return retreat around leave"<br>                look="look inspect glance eye glimpse review stare view peek notice scrutinize peer read stare study watch admire behold gawk observe ls peruse"<br>                take="take grab keep bring stash steal lift borrow nab pluck pocket salvage snag snatch swipe carry"<br>                touch="touch feel brush caress hit kiss lick reach rub stroke" <br>
<br>                show_room=1<br>                found_reference=0<br>
<br>                tell () {<br>                        if [[ ${@:0:1} == "@" ]]<br>                        then<br>                                eval ${@:1:-1}<br>                        else<br>                                 echo $@ |  pv -qL 128<br>                                 echo " "<br>                         fi<br>                }<br>                clear<br>                echo " "<br>                                if [ $found_reference == 0 ]<br>                                then<br>                                        for per_word in $answer; do<br>                                                if [[ -d "$per_word" ]]<br>                                                then<br>                                                        cd $per_word<br>                                                        echo " "<br>                                                        tell "You enter the " ${PWD##*/} "..."<br>                                                        found_reference=1<br>                                                        show_room=1<br>                                                        break<br>                                                                shopt -s extdebug  <br>                                                                return 1<br>                                                fi<br>                                        done<br>                                fi<br>                if [[ $leave == *"$answer"*  ]]<br>                   then<br>                         echo " "<br>                         tell "You leave the " ${PWD##*/} "..."<br>                          cd ..<br>                         found_reference=1<br>                        show_room=1<br>                 fi     <br>
<br>                echo " "<br>                if [ $show_room == 1 ]<br>                then<br>                        if [[ -e "room.txt" ]]<br>                        then<br>                               if [[ -e "room.jpg" ]]<br>                               then<br>                                       tiv room.jpg -w 70<br>                               fi<br>                               echo " "<br>                                tell "$(&lt;room.txt)"<br>                                show_room=0<br>                        fi<br>                fi                <br>                for filename in *.txt; do<br>                        [ -e "$filename" ] || continue<br>                        if [[ $filename != "room.txt" ]]<br>                        then<br>                                item_names="$(head -1 "$filename")"<br>                                for per_word in $answer; do<br>                                        if [[ $item_names == *"$per_word"* ]]<br>                                        then<br>                                                       if [[ -e $item_names".jpg" ]]<br>                                                                then<br>                                                                        tiv $item_names".jpg" -w 70<br>                                                                fi<br>                                                for per_word in $answer; do<br>                                                        if [[ $use == *"$per_word"* ]]<br>                                                        then<br>                                                                tell $(grep -A 2 '#use' $filename | grep -v "#use")<br>                                                                found_reference=1<br>                                                                break<br>                                                        elif [[ $look == *"$per_word"* ]]<br>                                                        then<br>                                                                tell $(grep -A 2 '#look' $filename | grep -v "#look")<br>                                                                found_reference=1<br>                                                                break<br>                                                        elif [[ $take == *"$per_word"* ]]<br>                                                        then<br>                                                                tell $(grep -A 2 '#take' $filename | grep -v "#take")<br>                                                                mv $filename /home/$USER/$filename<br>                                                                found_reference=1<br>                                                                break<br>                                                        elif [[ $touch == *"$per_word"* ]]<br>                                                        then<br>                                                                tell $(grep -A 2 '#touch' $filename | grep -v "#touch")<br>                                                                found_reference=1<br>                                                                break<br>                                                        else<br>                                                                tell "Can't do that with this " $item_names "..."<br>                                                                found_reference=1<br>                                                                break<br>                                                        fi<br>                                                done<br>                                        fi<br>                                done<br>                        fi<br>                done<br>
<br>
<br>                if [[ $found_reference == 1 || $show_room=0 ]]<br>                then<br>                        shopt -s extdebug  <br>                        return 1<br>                        fi<br>        fi<br>
<br>
<br>
<br>
<br>
<br>}<br>
</body>
</html>