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.

Relay / Write

Help for those learning Tcl or writing their own scripts.
Post Reply
J
JAFO
Voice
Posts: 19
Joined: Thu Oct 13, 2005 1:18 pm

Relay / Write

Post by JAFO »

Hi all ,

I would like to get some help on a script.
Searched the forum , found some bits and pieces of the script i'd like to have.
TCL aint my strongest side ;)

This is what i found :

Code: Select all

set relay(chans) "[list #chan1 #chan2 #etc]"; # put the channels within this list of which you want to relay messages from
set relay(who) "[list nick1 nick2 nick3 etc]"; # put here the nicknames of who you want to relay messages from
set relay(to) "#relay-to-this-channel"

bind pubm - {*} relay:pubm

proc relay:pubm {nick uhost hand chan text} {
    global relay
    if {[lsearch -exact "$relay(chans)" $chan] == -1} { return }
    if {[lsearch -exact "$relay(who)" $nick] == -1} { return }
    if {[validchan $relay(to)] && [botonchan $relay(to)]} {
        puthelp "PRIVMSG $relay(to) :\[[clock format [clock seconds] -format %H:%M:%S]\] <$nick> $text"
    }
}

But instead of relaying to a channel / network , i'd like the bot to write to a file.

IE.

My bot says:

<NFOrce> (NEWS) : blablabla http://blabla

then i wanna put "(NEWS) : blablabla http://blabla" into a file in /home/NFOrce/data.txt ( or any other word i want to echo later )

Also like to know if it's possible if the bot can write his own txt into the file or do i need a new eggdrop for that ??

TIA

JAFO
w
w00f
Halfop
Posts: 49
Joined: Wed Oct 04, 2006 6:50 pm

Post by w00f »

Code: Select all

set relay(chans) "[list #chan1 #chan2 #etc]"
set relay(who) "[list nick1 nick2 nick3 etc]"
set relay(db) "NFOrce/nforce.txt"
set relay(db_bak) "NFOrce/nforce.bak.txt"

bind pubm - {*} relay:pubm

proc relay:pubm {nick uhost hand chan text} {
    global relay
    if {[lsearch -exact "$relay(chans)" $chan] == -1} { return }
    if {[lsearch -exact "$relay(who)" $nick] == -1} { return }

	if {![file exist $relay(db)]} {
		putlog "creating db file ..."
		create_db
		}

	file rename -force $relay(db) $relay(db_bak)

	set i 0
	set fp [open $relay(db) w]
	set bak [open $relay(db_bak) r]

	while {![eof $bak]} {
		gets $bak line
		if {$i == 1} {
			puts $fp "$text"
		} 
		if {$line != ""} {
			puts $fp $line
		}
		incr i
	}
	close $fp
	close $bak
}


proc create_db {} {
	global relay
	set fp [open $relay(db) a]
	puts $fp "nforce info"
	close $fp
}

putlog "crapy tcl loaded"

this code is untested, but i thinks that will work fine.

w00f
J
JAFO
Voice
Posts: 19
Joined: Thu Oct 13, 2005 1:18 pm

Post by JAFO »

thx for ya help w00f :)

But i dont wanna use the .bak.txt.

Also i'd like to specify the word(s) in the line on which it should write to file.

Further help would be much appreciated :)
w
w00f
Halfop
Posts: 49
Joined: Wed Oct 04, 2006 6:50 pm

Post by w00f »

You can specify what you want to add by , binding what you want instead of *(with * the bot will put into data file everything that X says in one of the #chans that you specify), regexp $text first in a way to get what you want.
All depends what you want to add to that file, and certainly that I don't know what you want.

for the example you gave, you can bind (NEWS).

bind pub - (NEWS) relay:pubm

this will work for that kind of NFOrce announce.
Like i said you can also add/remove from the $text what you want, but you need to tell what you want in spite of setting up the script.

or i completely misunderstood what you want (hard night here lol)
J
JAFO
Voice
Posts: 19
Joined: Thu Oct 13, 2005 1:18 pm

Post by JAFO »

maybe this will help.

I have this script that echoes to another channel.
I'd like to have it rewritten so it writes to a file. This script works like a charm, so maybe it be better if ya could help me rewrite this one :)

Code: Select all

#what nicks are allowed to trigger the relay
# you can use wildcards, separate each nick with a space
set rl_nicks "NFOrce"

#source chan to relay from (only put one chan here)
#no wildcards allowed here
set rl_source "#NEWS"

#chans to relay to, separate each chan with a space
#no wildcards allowed here
set rl_dest "#chan1"

#text to watch for in the source chan
#(only put one text string here)
set rl_text "*(NEWS)*"

#DON'T EDIT BELOW HERE

bind pubm - "$rl_text" rl:go

proc rl:go { n u h c t } {
  global rl_dest
  if {[rl:auth $n $c]} {
    set rl_dest [string tolower $rl_dest]
    foreach dest $rl_dest {
      if {[botonchan $dest]} {
        puthelp "PRIVMSG $dest :$t"
      }
    }
  }
}

proc rl:auth { n c } {
  global rl_nicks rl_source
  set rl_nicks [string tolower $rl_nicks]
  set rl_source [string tolower $rl_source]
  set n [string tolower $n]
  set c [string tolower $c]
  foreach m $rl_nicks {
    if {[string match "$m" $n] && $c == $rl_source} {
      return 1
    }
  }
  return 0
}
 
  

But here it says

Code: Select all

#text to watch for in the source chan
#(only put one text string here)
set rl_text "*(NEWS)*"
only put one text :(

i'd like to add several.

TIA :D
J
JAFO
Voice
Posts: 19
Joined: Thu Oct 13, 2005 1:18 pm

Post by JAFO »

I tried the basic write script , but still nada :(

It's all mumbojumbo to me, so if anyone could help me out much appreciated. That way i'll get more insight on further tcl probs, since i will learn how the script reacts to what i want.

Hope anyone will help me out here ....

TIA
Post Reply