Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/zsh
- autoload -U tcp_open
- c='#freenodechannel' #channel for bot to enter
- cp='channelpw' #channel pw if prevalant
- e='#' # this is your command starter.
- n=irc.freenode.net #irc network
- l=n
- p=6667 #port
- u='cirrus_minor' #this is you, or your usernampe ion freenode
- w="cirrus_minor!~cirrus_mi@unaffiliated/cirrus-minor"
- ip='freenodeircpw' # CIRRUS LIKES IT IN DA JUNGLE! :D
- function aix { ( x=$(ix $@); notice "$x - autodeletion in 60"; sleep 60; ix -d ${x##*/} ) >&/dev/null & }
- function lyrics { aix ".lyrics/`mpc current`.txt" }
- function permit { [[ "$r" =~ "^:$w" || "$l" = 'n' ]] || { notice "You do not have permission to issue the following command: $2."; return 1 } }
- function notice { [[ $#@ > 0 ]] && >&3 <<< "notice $(<.curchan) :$@" }
- tcp_open $n $p
- tcp_open ${MPD_HOST:-localhost} ${MPD_PORT:-6600}
- >&3 <<< "nick $u|$$" <<< "user $u|$$ 8 * : $u the bot"
- while :; do >&4 <<< 'ping'; sleep 60; done &
- while read r; do
- [[ "$r" =~ '^ACK' ]] && notice $r
- [[ "$r" =~ '^(Title|Artist|Time|time|file|OK)' ]] && t=${r%%\:*} || continue
- v=${r#*\: }
- case "$t" in
- (Artist) artist=$v ;;
- (Title) title=$v ;;
- (Time) mm=$[$v / 60] ss=$[$v - $[$mm * 60]]
- (( $#ss < 2 )) && ss=0$ss; (( $#mm < 2 )) && mm=0$mm ;;
- (time) v=${v%\:*}; m=$[$v / 60] s=$[$v - $[$m * 60]]
- (( $#s < 2 )) && s=0$s; (( $#m < 2 )) && m=0$m
- notice "[$m:$s/$mm:$ss] $title by $artist"
- unset artist title mm ss m s ;;
- esac
- unset t v
- done <&4 &
- while read r; do <<< $r
- [[ "$r" =~ '^:[a-z\.]+ 396' ]] && >&3 <<< "nick ${u}MPD" <<< "join $c${cp:+ $cp}"
- [[ "$r" =~ '^PING' ]] && >&3 <<< "${r/PING/PONG}" <<< "nick ${u}MPD" <<< "join $c"
- [[ "$r" =~ '^:[a-z\.]+ 376' ]] && >&3 <<< "privmsg nickserv :identify $u $ip"
- [[ "$r" =~ '^:[a-z\.]+ 391' ]] && notice "${r#:*:}"
- [[ "$r" =~ "PRIVMSG .* :$e" ]] || continue
- s=${${r#:}%%$e*}; d=${${r##*$e}%\r\n}; c=${${r#*PRIVMSG }% :*}; W=${${d#:}%%\!*}
- >.curchan<<<$c
- [[ "$d" =~ '[a-z]+' ]] && case "$MATCH" in
- ## Help Section
- (help) [[ "${d#help }" =~ '[a-z]+' ]] && case "$MATCH" in
- (currentsong) notice 'Display information about current song' ;;
- (find) notice "Given a query and term will search the database. Usage: ${e}find <query> <term> -- reference ${e}help query" ;;
- (load) notice 'Loads a playlist' ;;
- (next) notice 'Plays next song' ;;
- (play) notice 'Plays song specified by number from the playlist, alternatively if no song is specified it shows current song playing or resumes the playlist if stopped' ;;
- (save) notice 'Saves a playlist' ;;
- (seek) notice "Seeks to the given time in the given song. Usage ${e}seek <songID> <seconds>" ;;
- (clear) notice 'Clears the whole playlist' ;;
- (query) notice 'Name, Artist, Album, Albumartist, Composer, Title, Track, File' ;;
- (delete) notice 'Removes a song from the playlist' ;;
- (repeat) notice "Sets the repeat mode to either True or False. Usage: ${e}repeat [01]" ;;
- (single) notice "Sets the single mode to either True or False. Usage: ${e}single [01]" ;;
- (findadd) notice "Given a query and term will search through the database and add all results. Usage: ${e}findadd <query> <term> -- referene ${e}help query" ;;
- (previous) notice 'Plays previous song' ;;
- (random) notice "Sets the random mode to either True or False. Usage: ${e}random [01]" ;;
- (time) notice "Requests the time of a given user. Usage: ${e}time <user>" ;;
- (*) notice "Use ${e}help <command>; see ${e}commands for the list."
- esac ;;
- (commands) notice 'Playlist Navigation: currentsong, next, play, previous, seek'
- notice 'Playlist Management: findadd, add, clear, crossfade, delete, load, move, ping, random, repeat, save, setvol, shuffle, single'
- notice ' Extra Commands: playlist, lyrics, help.'
- notice ' Admin Commands: lock, unlock, quit' ;;
- (currentsong) >&4 <<< "$d" <<< 'currentsong' <<< 'status' ;;
- (playlist) mpc playlist | cat -n | aix ;;
- (lyrics) lyrics & ;;
- (next|play|previous|seek) permit "$r" "$MATCH" && >&4 <<< "$d" <<< 'currentsong' <<< 'status' ;;
- (findadd|add|crossfade|delete|load|move|pause|ping|random|repeat|save|shuffle|single)
- permit "$r" "$MATCH" && notice 'Done!' && echo "$r" "$match" "$d"
- >&4 <<< "$d" ;; # This could be exploitable to send anything to the seerver... But I would expect ACKs...
- (time) >&3 <<< "ctcp ${${d#time }%\r\n} :time" ;;
- (lstatus) notice "The bot is currently on $l status" ;;
- (quit) [[ "$r" =~ "^:$w" ]] || continue
- >&3 <<< 'quit'
- >&4 <<< 'close' ;;
- (clear) [[ "$r" =~ "^:$w" ]] || { notice "You do not have permission to use this command." && continue }
- >&4 <<< "$d"
- notice 'Playlist Cleared' ;;
- (delete) [[ "$r" =~ "^:$w" ]] || { notice "You do not have permission to use this command." && continue }
- >&4 <<< "$d"
- notice 'Deleted' ;;
- (lock) [[ "$r" =~ "^:$w" ]] || { notice "You do not have permission to use this command." && continue }
- l='y'
- notice 'Locked' ;;
- (unlock) [[ "$r" =~ "^:$w" ]] || { notice "You do not have permission to use this command." && continue }
- l='n'
- notice 'Unlocked' ;;
- (setvol) [[ "$r" =~ "^:$w" ]] || { notice "You do not have permission to use this command." && continue }
- >&4 <<< "$d"
- notice "Volume set to: ${d#setvol }" ;;
- (*) notice "No such command: \"$MATCH\""
- esac
- done <&3 &
- while read r; do >&3 <<< "$r"; sleep 0.3; done
- >&3 <<< 'quit'
- >&4 <<< 'close'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement