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 text on keyword

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    egghelp.org community Forum Index -> Archive
View previous topic :: View next topic  
Author Message
johne
Voice


Joined: 19 Jul 2005
Posts: 29

PostPosted: Sat Aug 13, 2005 1:45 am    Post subject: relay text on keyword Reply with quote

ive been using this script and it works great, id just like to make a modification, heres the script.

Code:

# chan-relay v1.01 by shred, 2001 <shreder@tsu.tmn.ru>


# <vars>
set cr(version) "1.01"

# format: "bot1 #bot1chan flags1 {users1} bot2 #bot2chan flags2 {users2}"

# bot1                         <---  #bot2chan, flags2, {users2}
# #bot1chan, flags1, {users1}  --->  bot2

# users:
# {}      - no users
# {*}      - all users
# {nick1 nick2}   - selected users (only nick1 and nick2)

# flags (what to send):
# -   - NOTHING
# c   - chan msgs, actions
# C   - chan msgs, actions with @/+ prefix
# j   - join, part, quit msgs
# m   - mode change msgs
# k   - kick msgs
# n   - nick change
# N   - send with out nick (message only)
# t   - topic change
# u   - request user list (from another side)
# T   - t + synchronize
# 1|2|3   - output priority (default is 3, 1 is NOT recommended)
# a   = cjmnkt
# A   = CjmknT
# !! incorrect lines are ignored !!
### *** THIS IS WORKING EXAMPLE:
set cr(sets) {
  "dnr #distributed cN {dctievent} duron #distributed - {}"
  "dnr #distributed cN {dctievent} chasm #distributed - {}"
  "dnr #distributed cN {dctievent} chasm #dnet.ru - {}"
  "dnr #distributed cN {dctievent} Cluster #distributed - {}"
  "chasm #nnm.ru A {*} duron #noname uc {shred}"
  "ZED #qw.ru A {*} duron #qw.ru ucjn1 {shred}"
  "Cluster #atom a {*} duron #tyumen u {shred}"
  "dnr #qq A {*} duron #eggdrop A {*}"
}

# list of bots with this script on board (authorized bots)
# also needed for dcc command "cr_rehash" (rehash all selected bots)
### *** THIS IS WORKING EXAMPLE:
set cr(netbots) "Cluster ZED Fiber BadBlock def chasm duron dnr"
# </vars>


# <procs>
proc xindex {xarg xarg1} {return [join [lrange [split $xarg] $xarg1 $xarg1]]}
proc xrange {xarg xarg1 xarg2} {return [join [lrange [split $xarg] $xarg1 $xarg2]]}
proc b {} { return \002 }

proc cr_modep {nick chan cmd} {
  if {$cmd == "cr_pubm" || $cmd == "cr_act"} {
    if {[isop $nick $chan]} {return "\@$nick"}
    if {[isvoice $nick $chan]} {return "\+$nick"}
  }
  return $nick
}
proc cr_cansend {cmd modes} {
  if {$modes == "-"} {return 0}
  regsub "a" $modes "cjmnkt" modes
  regsub "A" $modes "CjmnkT" modes
  if {[lsearch "cr_report cr_ulist" $cmd] != -1} {return 1}
  switch $cmd {
    cr_pubm {if {[string match "*\[cC\]*" $modes]} {return 1}}
    cr_act {if {[string match "*\[cC\]*" $modes]} {return 1}}
    cr_join {if {[string match "*j*" $modes]} {return 1}}
    cr_part {if {[string match "*j*" $modes]} {return 1}}
    cr_sign {if {[string match "*j*" $modes]} {return 1}}
    cr_mode {if {[string match "*m*" $modes]} {return 1}}
    cr_nick {if {[string match "*n*" $modes]} {return 1}}
    cr_topc {if {[string match "*\[tT\]*" $modes]} {return 1}}
    cr_ulistreq {if {[string match "*u*" $modes]} {return 1}}
  }
  return 0
}
proc cr_getpri {modes} {
  if {[string match "*1*" $modes]} {return 1}
  if {[string match "*2*" $modes]} {return 2}
  return 3
}
proc cr_send2 {b1d b2d cmd nick text} {
  set b1name   [xindex $b1d 0]
  set b1chan   [xindex $b1d 1]
  set b1modes   [xindex $b1d 2]
  set b1users   [xindex $b1d 3]
  set b1pri   [cr_getpri $b1modes]
  set b2name   [xindex $b2d 0]
  set b2chan   [xindex $b2d 1]
  set b2modes   [xindex $b2d 2]
  set b2users   [xindex $b2d 3]
  set b2pri   [cr_getpri $b2modes]
  if {![cr_cansend $cmd $b1modes]} {return}
  if {$b1name == $b2name} {
    if {[string match "*\[CA\]*" $b1modes]} {set nick [cr_modep $nick $b1chan $cmd]}
    cr_brecive $b1name $cmd [concat $b2chan $nick $text]
  } else {
    if {[string match "*\[CA\]*" $b1modes]} {set nick [cr_modep $nick $b1chan $cmd]}
    foreach x $b1users {
      if {$x == $nick || $x == "\*"} {
        if {$cmd == "cr_topc" && $nick == $b1name} {continue}
        if {($cmd == "cr_topc") && [string match "*\[AT\]*" $b1modes]} {append cmd "s"}
        if {($cmd == "cr_pubm" || $cmd == "cr_act") && [string match "*N*" $b1modes]} {set nick "\*"}
        if {[catch {putbot $b2name "$cmd $b1pri $b2chan $nick $text"} err]} {putlog "$x bot error: $err"}
      }
    }
  }
}
proc cr_send {cmd chan nick text} {
  global botnick cr
  regsub -all ï $text Ÿ text
  foreach i $cr(sets) {
    if {[llength $i] != 8} {continue}
    set b1name   [xindex $i 0]
    set b1chan   [xindex $i 1]
    set b1modes   [xindex $i 2]
    set b1users   [xindex $i 3]
    set b2name   [xindex $i 4]
    set b2chan   [xindex $i 5]
    set b2modes   [xindex $i 6]
    set b2users   [xindex $i 7]
    if {$b1name == $botnick && $b1chan == $chan} {
      cr_send2 "$b1name $b1chan $b1modes $b1users" "$b2name $b2chan $b2modes $b2users" $cmd $nick $text
    } elseif {$b2name == $botnick && $b2chan == $chan} {
      cr_send2 "$b2name $b2chan $b2modes $b2users" "$b1name $b1chan $b1modes $b1users" $cmd $nick $text
    }
  } 
}

proc cr_pubm {nick uhost hand chan text} {cr_send cr_pubm $chan $nick $text}
proc cr_act {nick uhost hand chan keyw text} {cr_send cr_act $chan $nick $text}
proc cr_nick {nick uhost hand chan newnick} {cr_send cr_nick $chan $nick $newnick}
proc cr_mode {nick uhost hand chan mc victim} {
  if {$nick == "" && $hand == "\*"} {
    cr_send cr_mode $chan $uhost "$chan $mc $victim"
  } else {
    cr_send cr_mode $chan $nick "$chan $mc $victim"
  }
}
proc cr_join {nick uhost hand chan} {
  cr_send cr_join $chan $nick "$chan $uhost"
  cr_send cr_ulistreq $chan $nick "$chan"
}
proc cr_part {nick uhost hand chan msg} {cr_send cr_part $chan $nick "$chan $uhost"}
proc cr_sign {nick uhost hand chan reason} {cr_send cr_sign $chan $nick "$uhost $reason"}
proc cr_topc {nick uhost hand chan topic} {if {$nick == "\*"} {return}; cr_send cr_topc $chan $nick "$chan $topic"}
proc cr_kick {nick uhost hand chan target reason} {cr_send cr_kick $chan $nick "$target $reason"}

proc cr_putx {pri text} {
  switch $pri {
    1 {putquick $text}
    2 {putserv $text}
    3 {puthelp $text}
    default {putlog "ERROR: Wrong priority ($pri) for message '$text'"}
  }
}
proc cr_brecive {frombot cmd arg} {
  global cr server
  if {$server == ""} {return}
  if {[lsearch $cr(netbots) $frombot] == -1} {return}
  set pri  [xindex $arg 0]
  set chan [xindex $arg 1]
  set nick [xindex $arg 2]
  set text [xrange $arg 3 end]
  switch $cmd {
    cr_pubm {if {$nick == "*"} {cr_putx $pri "PRIVMSG $chan :$text"} else {cr_putx $pri "PRIVMSG $chan :\<$nick\> $text"}}
    cr_act {if {$nick == "*"} {putact $chan $text} else {cr_putx $pri "PRIVMSG $chan :\* $nick $text"}}
    cr_nick {cr_putx $pri "PRIVMSG $chan :\*\*\* $nick is now known as $text"}
    cr_mode {cr_putx $pri "PRIVMSG $chan :\*\*\* $nick sets [xindex $text 0] mode: [xrange $text 1 end]"}
    cr_sign {cr_putx $pri "PRIVMSG $chan :\*\*\* $nick ([xindex $text 0]) Quit ([xrange $text 1 end])"}
    cr_join {cr_putx $pri "PRIVMSG $chan :\*\*\* $nick ([xindex $text 1]) has joined [xindex $text 0]"}
    cr_part {cr_putx $pri "PRIVMSG $chan :\*\*\* $nick ([xindex $text 1]) has left [xindex $text 0]"}
    cr_topc {cr_putx $pri "PRIVMSG $chan :\*\*\* $nick changes [xindex $text 0] topic to '[xrange $text 1 end]'"}
    cr_topcs {cr_putx $pri "PRIVMSG $chan :\*\*\* $nick changes [xindex $text 0] topic to '[xrange $text 1 end]'"; if {[botisop $chan]} {putserv "TOPIC $chan :[xrange $text 1 end] ($nick)"}}
    cr_kick {cr_putx $pri "PRIVMSG $chan :\*\*\* [xindex $text 0] was kicked from $chan by $nick ([xrange $text 1 end])"}
    cr_dorehash {putbot $frombot cr_rehashing; putlog "REHASH request from $frombot"; rehash}
    cr_rehashing {putlog "  $frombot: rehashing..."}
    cr_report {cr_putx $pri "PRIVMSG $chan :\! Relay bot (${frombot}) reporting: $text"}
    cr_ulistreq {putbot $frombot "cr_ulist 3 $text $nick [b][llength [chanlist $chan]][b] users on [b]$chan[b]: [join [lsort [chanlist $chan]] {, }]"}
    cr_ulist {cr_putx $pri "NOTICE $nick :\[$chan\] $text"}
  }
}
proc cr_sendrehash {hand idx arg} {
  global cr botnick
  putlog "Sending REHASH request to [llength $cr(netbots)] bots..."
  foreach x $cr(netbots) {
    if {$x == $botnick} {continue}
    if {![islinked $x]} {putlog "$x bot is not currently linked"; continue}
    if {[catch {putbot $x "cr_dorehash"} err]} {putlog "$x bot error: $err"}
  }
  putlog "Send completed. Rehashing myself..."; rehash
}
proc cr_need {chan type} {
  if {$type == "unban"} {cr_send cr_report $chan - "need unban on $chan"}
}
# </procs>

# <binds>
bind dcc n cr_rehash cr_sendrehash
bind need - * cr_need
bind pubm - * cr_pubm
bind ctcp - ACTION cr_act
bind nick - * cr_nick
bind mode - * cr_mode
bind join - * cr_join
bind part - * cr_part
bind sign - * cr_sign
bind topc - * cr_topc
bind kick - * cr_kick
bind bot - cr_pubm cr_brecive
bind bot - cr_act cr_brecive
bind bot - cr_nick cr_brecive
bind bot - cr_mode cr_brecive
bind bot - cr_join cr_brecive
bind bot - cr_part cr_brecive
bind bot - cr_sign cr_brecive
bind bot - cr_topc cr_brecive
bind bot - cr_topcs cr_brecive
bind bot - cr_kick cr_brecive
bind bot - cr_dorehash cr_brecive
bind bot - cr_rehashing cr_brecive
bind bot - cr_report cr_brecive
bind bot - cr_ulistreq cr_brecive
bind bot - cr_ulist cr_brecive
# </binds>

# <c>
putlog "  chan-relay v$cr(version) by shred, 2001 <shreder@tsu.tmn.ru>"
# </c>


and what im wanting to add, is another variable to the list @ the top for a keyword and whenever that word is said in a channel, it relays only that line of text on the recieving channel.

thanks in advance if you can help me out.
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Sat Aug 13, 2005 2:09 am    Post subject: Reply with quote

Code:

proc cr_send {cmd chan nick text} {
  global botnick cr
  regsub -all ï $text Ÿ text
  foreach i $cr(sets) {
    if {[llength $i] != 9} {continue}
    set b1name   [xindex $i 0]
    set b1chan   [xindex $i 1]
    set b1modes   [xindex $i 2]
    set b1users   [xindex $i 3]
    set b2name   [xindex $i 4]
    set b2chan   [xindex $i 5]
    set b2modes   [xindex $i 6]
    set b2users   [xindex $i 7]
    set filter [xindex $i 8]
    if {$b1name == $botnick && $b1chan == $chan} {
      if ![string match -noc *${filter}* $text] {continue}
      cr_send2 "$b1name $b1chan $b1modes $b1users" "$b2name $b2chan $b2modes $b2users" $cmd $nick $text
    } elseif {$b2name == $botnick && $b2chan == $chan} {
      if ![string match -noc *${filter}* $text] {continue}
      cr_send2 "$b2name $b2chan $b2modes $b2users" "$b1name $b1chan $b1modes $b1users" $cmd $nick $text
    }
  }
}


use the usual Tcl string matching rules ("*" matches any word)


Last edited by demond on Sat Aug 13, 2005 2:14 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
johne
Voice


Joined: 19 Jul 2005
Posts: 29

PostPosted: Sat Aug 13, 2005 2:12 am    Post subject: Reply with quote

damn, you are the man, i still could never get that damned rss script to work *sigh*
Back to top
View user's profile Send private message
johne
Voice


Joined: 19 Jul 2005
Posts: 29

PostPosted: Sat Aug 13, 2005 2:14 am    Post subject: Reply with quote

also, is there a way to make this into one of the variables, like say adding a z to the configuration? and should i replace this part of the script with the new code, or add it later
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Sat Aug 13, 2005 2:21 am    Post subject: Reply with quote

replace proc cr_send with my code

the conf part becomes:
Code:

set cr(sets) {
  "dnr #distributed cN {dctievent} duron #distributed - {} foo"
  "dnr #distributed cN {dctievent} chasm #distributed - {} bar"
  "dnr #distributed cN {dctievent} chasm #dnet.ru - {} *"
  "dnr #distributed cN {dctievent} Cluster #distributed - {} *"
  "chasm #nnm.ru A {*} duron #noname uc {shred} *"
  "ZED #qw.ru A {*} duron #qw.ru ucjn1 {shred} *"
  "Cluster #atom a {*} duron #tyumen u {shred} *"
  "dnr #qq A {*} duron #eggdrop A {*} *"
}

first two lines will match and send only lines containing "foo" or "bar" (case-insensitive); the rest match and send any text ("*")
Back to top
View user's profile Send private message Visit poster's website
johne
Voice


Joined: 19 Jul 2005
Posts: 29

PostPosted: Sat Aug 13, 2005 2:24 am    Post subject: Reply with quote

Smile k im off to test it, once again, you are the man!
Back to top
View user's profile Send private message
johne
Voice


Joined: 19 Jul 2005
Posts: 29

PostPosted: Sat Aug 13, 2005 2:41 am    Post subject: Reply with quote

Sad lol...and again nothing ever works for me...

and none of it is relaying now with the script change

does it matter that my keyword is like !news
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Sat Aug 13, 2005 7:35 am    Post subject: Reply with quote

what's your configuration? i.e. the cr(sets) array
Back to top
View user's profile Send private message Visit poster's website
johne
Voice


Joined: 19 Jul 2005
Posts: 29

PostPosted: Tue Aug 16, 2005 12:08 am    Post subject: Reply with quote

sorry i was a fool...it works Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    egghelp.org community Forum Index -> Archive 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