Skip to content
Browse files

iibot on the wild

  • Loading branch information...
0 parents commit ea495b38da06b282b80c293cc920410f62bcaf42 @c00kiemon5ter committed May 1, 2012
Showing with 121 additions and 0 deletions.
  1. +23 −0 README.mkdn
  2. +52 −0 iibot
  3. +46 −0 iicmd
23 README.mkdn
@@ -0,0 +1,23 @@
+
+## iibot
+
+a minimal bot based on [ii] by [suckless], auto-managed by 40sloc of bash.
+
+#### featuring:
+
+ * dynamic commands - just edit `iicmd`, simple plain bash. stdout goes to channel.
+ * parallel connection to networks
+ * auto reconnect to networks and channels
+
+## UnLicense
+
+code and text are unlicensed.
+see [unlicense.org] for more information
+original hacks by [Ivan c00kiemon5ter V Kanakarakis][c].
+if you have cookies, share :]
+
+ [ii]: http://tools.suckless.org/ii/
+ [suckless]: http://suckless.org/
+ [unlicense.org]: http://unlicense.org/
+ [c]: http://c00kiemon5ter.github.com/
+
52 iibot
@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+
+: "${ircdir:=$HOME/ircbot}"
+: "${nickname:=amabot}"
+
+declare -A networks=(
+ [irc.freenode.net]="#foss-aueb"
+)
+
+# some privacy please, thanks
+chmod 700 "$ircdir"
+chmod 600 "$ircdir"/*/ident &>/dev/null
+
+monitor() {
+ tailf -n1 "$ircdir/$network/$channel/out" | \
+ while read -r date time nick msg; do
+ [[ "$nick" == '-!-' ]] && continue
+ nick="${nick:1:-1}" # strip < and >
+ [[ "$nick" == "$nickname" ]] && continue
+ [[ "$msg" =~ ^! ]] && exec iicmd "$nick" "${msg#\!}" "$ircdir" "$network" "$channel" "$nickname" &
+ done > "$ircdir/$network/$channel/in"
+}
+
+for network in "${!networks[@]}"; do
+ while true; do
+ # cleanup
+ rm -f "$ircdir/$network/in"
+
+ # connect to netwrok - password is set through the env var IIPASS
+ ii -i "$ircdir" -n $nickname -s "$network" -e ssl &
+ pid="$!"
+
+ # wait for the connection
+ while ! test -p "$ircdir/$network/in"; do sleep 1; done
+
+ # auth to services
+ [[ -e "$ircdir/$network/ident" ]] && \
+ printf -- "/j nickserv identify %s\n" "$(<"$ircdir/$network/ident")" > "$ircdir/$network/in"
+ rm -f "$ircdir/$network/nickserv/out" # clean that up - ident passwd is in there
+
+ # join channels
+ for channel in ${networks[$network]}; do
+ printf -- "/j %s\n" "$channel" > "$ircdir/$network/in"
+ [[ -e "$ircdir/$network/$channel/out" ]] || touch "$ircdir/$network/$channel/out"
+ monitor &
+ done
+
+ # if connection is lost reconnect
+ wait "$pid"
+ done &
+done
+
46 iicmd
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+
+nick="$1"
+mesg="$2"
+ircd="$3"
+netw="$4"
+chan="$5"
+self="$6"
+
+read -r cmd extra <<< "$mesg"
+if [[ "$mesg" =~ .*\>.* ]]; then
+ IFS='>' read -r extra nicks <<< "$extra"
+ [[ -z "$nicks" ]] && nicks=( $extra ) extra= || nicks=( $nicks )
+fi
+
+if [[ "${nicks[0]}" == "@all" ]]; then
+ printf -- "/names %s\n" "$chan"
+ sleep 1 && nicks=( $(tail -n2 "$ircd/$netw/out" | grep "[[:digit:]-]\+ [[:digit:]:]\+ = #" | cut -d" " -f5-) )
+fi
+
+commands=(
+ list
+ fortune
+ ping
+ slap
+ whereami
+)
+
+case "$cmd" in
+ list)
+ printf -- "%s: %s\n" "$nick" "${commands[*]}"
+ ;;
+ fortune)
+ printf -- "%s\n" "$(fortune -osea)"
+ ;;
+ ping)
+ (( ${#nicks[@]} )) && printf -- "%s: ping!\n" "${nicks[*]}" || printf -- "%s: pong!\n" "$nick"
+ ;;
+ slap)
+ printf -- "%s slaps %s with %s\n" "$nick" "${nicks[*]:-his cohones}" "${extra:-a large herpderp}"
+ ;;
+ whereami)
+ printf -- "this\nis\n%s!!\n" "$chan"
+ ;;
+esac
+

0 comments on commit ea495b3

Please sign in to comment.
Something went wrong with that request. Please try again.