[PATCH 01/65] FAQ: update, working bot example

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Wed, 16 Apr 2014 16:58:30 +0200

a simple bot with a command !rand that outputs a random number to a user.

Signed-off-by: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
---
 FAQ | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/FAQ b/FAQ
index 4aefa6a..49a2c2c 100644
--- a/FAQ
+++ b/FAQ
_AT_@ -6,6 +6,7 @@ Where is IRC command xy (ignore etc.)?
 ii is for advanced users, please use standard tools like awk, sed and grep for
 this. This can be done easily and will not bloat the code.
 
+
 Where is a graphical interface?
 -------------------------------
 Basically ii follows the UNIX philosophy so it is only file based. But it
_AT_@ -14,12 +15,14 @@ the FIFOs and output files. Feel free to implement or wait until we have done
 this. Actually I use ii in combination with vim, multitail and screen and it works
 like a charm.
 
+
 Which commands are supported?
 -----------------------------
 j (join or msg), t (topic), a (away), n (nick), l (leave). The missing are
 obsolete or can be easily used by typing the IRC commands itself (i.e. /WHO
 instead of /who).
 
+
 How can I recognize queries?
 ----------------------------
 ii itself doesn't support this but the queries.sh script is an example
_AT_@ -28,9 +31,23 @@ To get an instant notice of a new file other mechanisms like inotify/dnotify
 could be used as well but I was too lazy to try it out since the script
 is enough for me.
 
+
 What other fancy stuff can I do with ii?
 ----------------------------------------
 It is very easy to write irc bots in ii:
-tail -f \#/out | while read foo; do name=echo $foo | awk '{print $2}' | sed 's,<\\(.*\\)>,\\1,'; if 0 -eq expr $RANDOM % 10 then echo "$name: WHAT??" ; fi; done
+
+	#!/bin/sh
+	chan="#yourchannel"
+	tail -f "${chan}/out" | while read line; do
+		cmd=$(printf '%s\n' "$line" | cut -d ' ' -f 4-)
+		name=$(printf '%s\n' "$line" | cut -d ' ' -f 3 | tr -d '<>')
+		if [ "$cmd" = "!rand" ]; then
+			r="$RANDOM"
+			if expr "$r" "%" "10"; then
+				echo "$name: $r" >> "${chan}/in"
+			fi
+		fi
+	done
+
 This will just spam a channel but think about using nagios2irc or you can
 use ii to generate channel stats. Your imagination should be boundless.
-- 
2.4.10
--Multipart=_Mon__9_May_2016_17_21_10_+0200_I.6cpFVydhq75aaE
Content-Type: text/x-diff;
 name="0002-LICENSE-update.patch"
Content-Disposition: attachment;
 filename="0002-LICENSE-update.patch"
Content-Transfer-Encoding: 7bit
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Mon May 09 2016 - 17:24:22 CEST