#!/bin/bash # If aviable source the settings file, if not quit with an arror. if [ -f ~/.awaysms ]; then . ~/.awaysms echo "`date +%H:%M:%S` [query.sh]: settings loaded" >> "$debug" else echo "FATAL ERROR: settings not found. Please report that to The-Compiler." exit 1 fi echo "===== LOG OPENED AT `date +%H:%M:%S` ====" >> "$debug" server="$1" host="$2" text="$3" # Some debug output... echo "`date +%H:%M:%S` [query.sh]: server: $server || host: $host || text: $text" >> $debug # Exit if the away2web file doesn't exist if [ ! -e "$awayfile" ]; then echo "`date +%H:%M:%S` [query.sh]: awayfile $awayfile doesn't exist. Aborting." >> "$debug" exit 2 else echo "`date +%H:%M:%S` [query.sh]: awayfile $awayfile exists." >> "$debug" fi # If we aren't away exit echo "`date +%H:%M:%S` [query.sh]: checking away status" >> "$debug" awaystatus=$(head -n 1 "$awayfile") if [ "$awaystatus" -eq 1 ]; then echo "`date +%H:%M:%S` [query.sh]: awaystatus is $awaystatus - not away. Aborting." >> "$debug" exit 1 else echo "`date +%H:%M:%S` [query.sh]: awaystatus is $awaystatus - away." >> "$debug" fi # Get the awayreason echo "`date +%H:%M:%S` [query.sh]: reading away-reason" >> "$debug" awayreason=$(tail -n 1 "$awayfile") echo "`date +%H:%M:%S` [query.sh]: away-reason is: $awayreason" >> "$debug" # get the options for the user echo "`date +%H:%M:%S` [query.sh]: giving control to readoptions.sh now" >> "$debug" readoptions=$("$dir/readoptions.sh" "$host") echo "`date +%H:%M:%S` [query.sh]: gained control back, exit status $? || readoptions: $readoptions" >> "$debug" # split options up echo "`date +%H:%M:%S` [query.sh]: splitting options up now" >> "$debug" options=$(echo $readoptions | cut -d " " -f 1) number=$(echo $readoptions | cut -d " " -f 2) echo "`date +%H:%M:%S` [query.sh]: options: $options || number: $number" >> "$debug" # check if the user is banned echo "`date +%H:%M:%S` [query.sh]: let's see if the user is banned" >> "$debug" if echo "$readoptions" | grep -q ban; then echo "`date +%H:%M:%S` [query.sh]: ouch. User $host is banned. Aborting." >> "$debug" exit 3 else echo "`date +%H:%M:%S` [query.sh]: okay, the user $host isn't banned." >> "$debug" fi # check what the user wants to do echo "`date +%H:%M:%S` [query.sh]: now checking the text: >$text<" >> "$debug" case $text in \!send*) #send something ;; \!help*) # help echo "`date +%H:%M:%S` [query.sh]: The user wanted some help, aye." >> "$debug" echo "Possible commands:" echo "!send - send a message to me" ;; \!*) # unknown command echo "`date +%H:%M:%S` [query.sh]: The command $text was unknown." >> "$debug" echo "Unknown command. Try !help" ;; *) # normal text echo "`date +%H:%M:%S` [query.sh]: $text seems to be a normal text, giving the user my awaymessage." >> "$debug" echo "Sorry, but I'm not here at the moment ($awayreason) - use !send to send me a message via SMS." ;; esac echo "`date +%H:%M:%S` [query.sh]: We did what we had to do, exiting." >> "$debug" exit 0