From 2fb956121d09e7c33d6e7b073c34f4f74a7c4c16 Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Mon, 1 Aug 2011 20:52:38 +0000
Subject: [PATCH] Add a watchfile system (anything appended to the file is
 echoed in the channel) Also, fix the callsign command to return the LAST
 match in the FCC database, not the first.

---
 exec/ircbots/ham/ham.js | 45 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)

diff --git a/exec/ircbots/ham/ham.js b/exec/ircbots/ham/ham.js
index 589f2659ca..5000f297a0 100644
--- a/exec/ircbots/ham/ham.js
+++ b/exec/ircbots/ham/ham.js
@@ -5,6 +5,45 @@ if(!js.global || js.global.HTTPRequest==undefined)
 //function Bot_Command(x,y,z){}
 //js.global.config_filename='hambot.ini';
 
+var last_update=0;
+var update_interval=2;
+var last_wflength=-1;
+function main(srv,target)
+{	
+	if((time() - last_update) < update_interval) return;
+
+	var config = new File(system.ctrl_dir + js.global.config_filename);
+	var watch=new File();
+	if(!config.open('r')) {
+		log("Unable to open config!");
+		return;
+	}
+	var wfname=config.iniGetValue("module_Ham", 'watchfile');
+	config.close();
+	if(wfname.length > 0) {
+		var wf=new File(wfname);
+		var len=wf.length;
+		// Ignore contents at start up.
+		if(last_wflength==-1)
+			last_wflength=len;
+		// If the file is truncated, start over
+		if(last_wflength > len)
+			last_wflength=0;
+		if(len > last_wflength) {
+			if(wf.open("r")) {
+				var l;
+				wf.position=last_wflength;
+				while(l=wf.readln()) {
+					srv.o(target, l);
+				}
+				last_wflength=wf.position;
+				wf.close();
+			}
+		}
+	}
+	last_update=time();
+}
+
 Bot_Commands["CALLSIGN"] = new Bot_Command(0,false,false);
 Bot_Commands["CALLSIGN"].command = function (target,onick,ouh,srv,lvl,cmd) {
 	var callsign;
@@ -47,10 +86,10 @@ Bot_Commands["CALLSIGN"].command = function (target,onick,ouh,srv,lvl,cmd) {
 		req.SendRequest();
 		req.ReadResponse();
 
-		m=req.body.match(/(license.jsp\?licKey=[^\s]*)/);
+		m=req.body.match(/license.jsp\?licKey=[^\s]*/g);
 
-		if(m) {
-			var response=new HTTPRequest().Get('http://wireless2.fcc.gov/UlsApp/UlsSearch/'+m[1]);
+		if(m && m.length) {
+			var response=new HTTPRequest().Get('http://wireless2.fcc.gov/UlsApp/UlsSearch/'+m[m.length-1]);
 			m=response.match(/In the case of City, state and zip[^-]*?-->([\x00-\xff]*?)<\/td>/);
 			if(m) {
 				var info=callsign+':';
-- 
GitLab