| View previous topic :: View next topic |
| Author |
Message |
furious Voice
Joined: 16 Jan 2006 Posts: 14
|
Posted: Mon Feb 06, 2006 4:26 pm Post subject: Tracking Script |
|
|
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: |
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" |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Mon Feb 06, 2006 5:03 pm Post subject: |
|
|
My guess is cos of the '$channel $botnick' line. Also, a quote from the doc/tcl-commands.doc file:
| Quote: |
| 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. |
|
| Back to top |
|
 |
furious Voice
Joined: 16 Jan 2006 Posts: 14
|
Posted: Mon Feb 06, 2006 9:13 pm Post subject: |
|
|
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.  |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Mon Feb 06, 2006 9:54 pm Post subject: |
|
|
Since you used [putlog], you can see them in the eggdrop's logfile. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
furious Voice
Joined: 16 Jan 2006 Posts: 14
|
Posted: Mon Feb 06, 2006 11:20 pm Post subject: |
|
|
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: |
# 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"
|
|
|
| Back to top |
|
 |
furious Voice
Joined: 16 Jan 2006 Posts: 14
|
Posted: Tue Feb 07, 2006 3:20 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Tue Feb 07, 2006 7:49 pm Post subject: |
|
|
| Code: | 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) _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
furious Voice
Joined: 16 Jan 2006 Posts: 14
|
Posted: Tue Feb 07, 2006 11:28 pm Post subject: |
|
|
Ok have made a few changes and followed the advice given. Now this is my script.
| Code: | # 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. |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Wed Feb 08, 2006 9:15 am Post subject: |
|
|
Where did you get that "close $file" from? just add the code I gave you into your script, and change [putlog] to [myputlog]. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
furious Voice
Joined: 16 Jan 2006 Posts: 14
|
Posted: Wed Feb 08, 2006 10:20 am Post subject: |
|
|
| 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? |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
|
| Back to top |
|
 |
furious Voice
Joined: 16 Jan 2006 Posts: 14
|
Posted: Wed Feb 08, 2006 11:48 am Post subject: |
|
|
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.  |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Wed Feb 08, 2006 2:16 pm Post subject: |
|
|
you can add
| Code: | if {[string match -nocase "*trigger*" $arg]} {
#myputlog...
} |
btw, change args to arg, args has a special meaning in tcl. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
furious Voice
Joined: 16 Jan 2006 Posts: 14
|
Posted: Wed Feb 08, 2006 5:13 pm Post subject: |
|
|
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!! Any ideas on how to fix that? |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Wed Feb 08, 2006 6:41 pm Post subject: |
|
|
After you delete the log, .rehash or .tcl source scripts/thisscript.tcl. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
|