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