Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ea495b3
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|