This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Tracking Script

Help for those learning Tcl or writing their own scripts.
f
furious
Voice
Posts: 14
Joined: Mon Jan 16, 2006 11:44 am
Contact:

Tracking Script

Post by furious »

Ok here is the script that I have, it kinda works, but I need it to do a couple of other things as well. Right now the bot does catch the words being said, however I want the bot to write a log file, and put the log file in a specific place in the directory so I need to be able to put a path to the log. Also I want the script to keep writting the same log for 7 days. Then switch to a new file. Also I am getting an error message which I will post at the end of the script itself.


Script

Code: Select all

proc ccodes:filter {str} {
  regsub -all -- {\003([0-9]{1,2}(,[0-9]{1,2})?)?|\017|\037|\002|\026|\006|\007} $str "" str
  return $str
}

## Starting Process
proc filter_words {nick uhost handle channel args} {
 global words botnick
 set args [ccodes:filter $args] 
  set handle [nick2hand $nick]
	foreach word [string tolower $words] {     
	if {[string match *$word* [string tolower $args]]}  {
       if {[matchattr $handle flags $channel]} {
           putlog "-4Tracking Script -ATTENTION-0 $nick ($handle) said $args on $channel"
             } else {
           putlog "-4Tracking Script -ATTENTION0 $nick on $channel matched by $args"
             $channel $botnick
       }
    }
  }
}
bind pubm - * filter_words
Error Message I get

[20:24] Tcl error [filter_words]: invalid command name "#channel"
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

My guess is cos of the '$channel $botnick' line. Also, a quote from the doc/tcl-commands.doc file:
| stripcodes <strip-flags> <string>
| Description: strips specified control characters from the string given.
| strip-flags can be any combination of the following:
| b - remove all boldface codes
| c - remove all color codes
| r - remove all reverse video codes
| u - remove all underline codes
| a - remove all ANSI codes
| g - remove all ctrl-g (bell) codes
| Returns: the stripped string.
| Module: core
Wich should do the same job and even faster than ppslim's ccodes:filter proc. :)
Once the game is over, the king and the pawn go back in the same box.
f
furious
Voice
Posts: 14
Joined: Mon Jan 16, 2006 11:44 am
Contact:

Post by furious »

Ok yeah duh that was my bad after removing that one line that takes care of my error message, but it's still not logging the word being said. It does catch the phrase though, because it shows it in the party line, but I want to retrieve this information later on, if somebody could help that would be great, or point me in the direction of a very dummified beginers manual would be great. This is my first attempt at writing something myself, so I have taken bits and pieces of it from other scripts so far, making progress but still a ways to go. :lol:
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Since you used [putlog], you can see them in the eggdrop's logfile.
f
furious
Voice
Posts: 14
Joined: Mon Jan 16, 2006 11:44 am
Contact:

Post by furious »

Ok since it's still not logging I have even tried to specify a path for it to send the logs to. So now this is what my script looks like.

Code: Select all

# Set the next line as the file to log to
set filter_words "/home/user/eggdrop/logs/serverstats.log"


### Set Words that you want the Bot to Log on
set words { 
"sample"
}


## Binding all Public Messages to our Process
bind pubm - * filter_words

proc ccodes:filter {str} {
  regsub -all -- {\003([0-9]{1,2}(,[0-9]{1,2})?)?|\017|\037|\002|\026|\006|\007} $str "" str
  return $str
}

## Starting Process
proc filter_words {nick uhost handle channel args} {
 global words botnick
 set args [ccodes:filter $args] 
  set handle [nick2hand $nick]
	foreach word [string tolower $words] {     
	if {[string match *$word* [string tolower $args]]}  {
       if {[matchattr $handle flags $channel]} {
           putlog "-4Tracking Script -ATTENTION-0 $nick ($handle) said $args on $channel"
             } else {
           putlog "-4Tracking Script -ATTENTION0 $nick on $channel matched by $args"
       }
    }
  }
}

bind pubm - * filter_words
putlog "FuRiOuS Tracking Script Loaded"
f
furious
Voice
Posts: 14
Joined: Mon Jan 16, 2006 11:44 am
Contact:

Post by furious »

Ok its logging now, but how can I specify what file to put it in? Because right now it is going into the bots normal log file which isn't what I want, thats a lot of lines to look through. I want this to go to a specific file and a specific place.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

if {[file exists scripts/trackingscript.log]} {
 set loglist [split [read [set file [open scripts/trackingscript.log]]][close $file] \n]
}

bind time - ?0* save:log

proc save:log args {
 set f [open scripts/trackingscript.log w]
 foreach l $::loglist {
  if {$l != ""} {
   puts $f $l
  }
 }
 close $f
}

proc myputlog arg {
 if {$arg != ""} {
  lappend ::loglist $arg
 }
}
so now, instead of [putlog] use [myputlog] and everything will be logged into trackingscript.log in the script/ directory. (The file is updated every 10 minutes)
f
furious
Voice
Posts: 14
Joined: Mon Jan 16, 2006 11:44 am
Contact:

Post by furious »

Ok have made a few changes and followed the advice given. Now this is my script.

Code: Select all

# Set the next line as the file to log to 
set filter_words "/home/user/eggdrop/logs/stats.log" 


### Set Words that you want the Bot to Log on 
set words { 
"test" 
} 


## Binding all Public Messages to our Process 
bind pubm - * filter_words 

proc ccodes:filter {str} { 
regsub -all -- {\003([0-9]{1,2}(,[0-9]{1,2})?)?|\017|\037|\002|\026|\006|\007} $str "" str 
return $str 
} 

## Starting Process 
proc filter_words {nick uhost handle channel args} { 
global words botnick 
set args [ccodes:filter $args] 
foreach word [string tolower $words] { 
if {[string match *$word* [string tolower $args]]} { 
if {[matchattr $handle $channel]} { 
myputlog "4\[[strftime "%D %T"]\] $nick said $args on $channel"  
} 
close $file 
} 
} 
} 
if {[file exists scripts/stats.log]} { 
 set loglist [split [read [set file [open scripts/stats.log]]][close $file] \n] 
} 

bind time - ?0* save:log 

proc save:log args { 
 set f [open scripts/stats.log w] 
 foreach l $::loglist { 
  if {$l != ""} { 
   puts $f $l 
  } 
 } 
 close $f 
} 

proc myputlog arg { 
 if {$arg != ""} { 
  lappend ::loglist $arg 
 } 
}


bind pubm - * filter_words 
putlog " 4f13µ12®8î9ö6µ7§ 8 Tracking Script Loaded" 
However that script is now giving me this error message:

Tcl error [filter_words]: can't read "file": no such variable

So aside from this new error its also not logging again. I got the date and time added that I wanted to have, now just a few more small bugs to work out and I'm done.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Where did you get that "close $file" from? just add the code I gave you into your script, and change [putlog] to [myputlog].
f
furious
Voice
Posts: 14
Joined: Mon Jan 16, 2006 11:44 am
Contact:

Post by furious »

Thanks Sir_Fz it works fine. As a tweak to it, is there any way to make the script log just the word that matches the specified word instead of the whole sentence?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

What word?
f
furious
Voice
Posts: 14
Joined: Mon Jan 16, 2006 11:44 am
Contact:

Post by furious »

I would only want it to track instances of the word "trigger" being said. This is just a first draft of this script, once I get this better and finished touching it up, I'll start working on the next version that will be much easier to read and stuff. :lol:
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

you can add

Code: Select all

if {[string match -nocase "*trigger*" $arg]} {
 #myputlog...
}
btw, change args to arg, args has a special meaning in tcl.
f
furious
Voice
Posts: 14
Joined: Mon Jan 16, 2006 11:44 am
Contact:

Post by furious »

Ackkkkkkkkkkk now I have another problem, whenever I delete the logs that the script creates they diappear they are gone completely, but the next time the script updates the logs, it replaces everything that was deleted as well!! :shock: Any ideas on how to fix that?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

After you delete the log, .rehash or .tcl source scripts/thisscript.tcl.
Post Reply