egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Relay / Write

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
JAFO
Voice


Joined: 13 Oct 2005
Posts: 19

PostPosted: Sat Mar 17, 2007 5:24 am    Post subject: Relay / Write Reply with quote

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 Wink

This is what i found :

Code:
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
Back to top
View user's profile Send private message
w00f
Halfop


Joined: 04 Oct 2006
Posts: 49

PostPosted: Sat Mar 17, 2007 6:30 pm    Post subject: Reply with quote

Code:

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
Back to top
View user's profile Send private message
JAFO
Voice


Joined: 13 Oct 2005
Posts: 19

PostPosted: Sat Mar 17, 2007 7:46 pm    Post subject: Reply with quote

thx for ya help w00f Smile

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 Smile
Back to top
View user's profile Send private message
w00f
Halfop


Joined: 04 Oct 2006
Posts: 49

PostPosted: Sat Mar 17, 2007 10:54 pm    Post subject: Reply with quote

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)
Back to top
View user's profile Send private message
JAFO
Voice


Joined: 13 Oct 2005
Posts: 19

PostPosted: Wed Mar 21, 2007 6:09 am    Post subject: Reply with quote

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 Smile

Code:

#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:

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


only put one text Sad

i'd like to add several.

TIA Very Happy
Back to top
View user's profile Send private message
JAFO
Voice


Joined: 13 Oct 2005
Posts: 19

PostPosted: Thu Mar 22, 2007 7:49 pm    Post subject: Reply with quote

I tried the basic write script , but still nada Sad

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber