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.

Specific Relay Script

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Specific Relay Script

Post by Football »

Hey guys need some help,

I need a script that will relay from one channel to another, however, unlike a relay script I need it to relay only sentences that contain certain words - and these words are all listed in a .txt file called "words"

For example, the words.txt file would contain words like "Hello" & "Goodbye"
And then when someone says "Hello" or "Goodbye" in a sentence, the script will automaticlly relay the whole sentence from one channel to another.
* Notice that it could contain one than one word like "Hello there" and then it will look for "Hello there" in a sentence and relay the whole sentence.

Would be great if it would relay the line and ignore bold/colors/underlines.
Also would be great if you can add public commands to view the list & add or remove words from it.

Please help.
Idling at #Football, Quakenet.
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Code: Select all

# Set here, the channel you want the bot to listen for messages on                        

set mchan "#chan"

# Set here, the channel you want the messages to be relayed to.                          

set rchan "#chan2"

bind pubm * * relay
proc relay {nick host hand chan text} {
 global mchan rchan
    if {[string equal -nocase $chan $mchan]} {
     if {[regexp -nocase -- {.*(hello).*} [stripcodes bcruag [join [lrange [split $text] 0 end]]] msg word] || [regexp -nocase -- {.*(goodbye).*}  [stripcodes bcruag [join [lrange [split $text] 0 end]]] msg word]} {
       if {![validchan $rchan]} {
 return
       }
    putserv "PRIVMSG $rchan :$nick: $msg"  
      } else {return 0}
    } else {return 0}
 set mfs "words.txt"
    if {![file exists $mfs]} {
        close [open $mfs w]
    }
 set fs [open $mfs]
 set data [read -nonewline $fs]
  close $fs
    if {![string length $data]} {
 set fs [open $mfs w]
    } else {
 set fs [open $mfs a]
    }
 puts $fs "$word"
  close $fs
}

bind pub o|o !relays relays

# Syntax is: !relays

proc relays {nick host hand chan text} {
 global mchan
 if {[string equal -nocase $mchan $chan]} {
 set fs [open "words.txt"]
 set data [read -nonewline $fs]
  close $fs
   if {![string length $data]} {
  putserv "NOTICE $nick :I don't currently have any messages to relay."
 return 0
   }
  putserv "NOTICE $nick :My list of relay messages is as follows:"
set fs [open "words.txt"]
  seek $fs 0 start
    while {[gets $fs line] >= 0} {
  puthelp "NOTICE $nick :$line"
    }
 close $fs
    }
 return
}

bind pub o|o !msgclr msgclear

# Syntax is: !msgclr

proc msgclear {nick host hand chan text} {
  close [open "words.txt" w]
}
Moderator edit: fixed.
Last edited by Luminous on Thu Aug 19, 2010 11:18 am, edited 1 time in total.
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Post by Football »

[00:16:19] <Football> [21:16] can't read "fs": no such variable
[00:16:19] <Football> while executing
[00:16:19] <Football> "close $fs "
[00:16:19] <Football> (file "scripts/relay.tcl" line 55)
[00:16:19] <Football> invoked from within
[00:16:19] <Football> "source scripts/relay.tcl"
Idling at #Football, Quakenet.
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

You must have missed a brace or something because that reports no such error for me.
Either that, or you didn't fix the spacing in this line:

Code: Select all

if {[regexp -nocase -- {.*(hello).*} [stripcodes bcruag [join [lrange [split $text] 0 end]]] msg word] || [regexp -nocase --{ .*(goodbye).*}  [stripcodes bcruag [join [lrange [split $text] 0 end]]] msg word]} { 
That is supposed to be a simgle command.
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Oh, oops, somehow I managed to stick an extra brace in there. Change

Code: Select all

  while {[gets $fs line] >= 0} {
  puthelp "NOTICE $nick :$line"
    }
}
 close $fs
}
to

Code: Select all

  while {[gets $fs line] >= 0} {
  puthelp "NOTICE $nick :$line"
    }
 close $fs
}
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Post by Football »

It only relays if someone writes "hello" or "goodbye"... it doesn't use the word.txt at all..
Idling at #Football, Quakenet.
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

It matches any line that has "hello" or "goodbye" in it... I don't know what to tell you, this works fine for me. :S I guess make sure that nothing got sent over to a new line on accident, etc... that can happen when pasting.
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Post by Football »

no no, you didn't understand me properly
I gave "hello" and "goodbye" as an example
The purpose of the script is to scan any words in a file called "words.txt" and if when someone types one of the words that are on "words.txt" it will relay the whole line to another channel.

And not just "hello" and "goodbye" the words I used an example :)
Idling at #Football, Quakenet.
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Oh! Lol, I see. That makes more sense. M'kay, let me see what I can do with that...
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Wtf, why is this here? I clicked edit, not "new post". -_-
Last edited by Luminous on Thu Aug 19, 2010 4:45 pm, edited 1 time in total.
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Edit: Okay, you know what.... I wrote this script like 4 times. The final few I was just trying to perfect a few things and everytime I did, something totally unrelated broke. It ignored my llength statement. It refused to search through all lines of the file, sent me lines that no longer existed, told me things existed when they did not, etc, etc.... none of these things are new to me, I have scripts hundreds of lines long that use these same techniques for same reason,. but tcl is so unpredictable and inconsistent, I always get different results and I am just not going to spend any more time on this.

So, sorry... I tried... Hopefully someone else can take what I did and finish it.
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Post by Football »

Hey Luminous, that works great for me, thank you very much!

Could anyone modify it so it will relay even when the words.txt has more than one word per line?

for instance, if the first line on words.txt is: Hello there sir

When someone writes "hello there sir" or even "hello there sir how are you today?"
It`ll relay the line, instead of just looking for "hello"
Idling at #Football, Quakenet.
Post Reply