| View previous topic :: View next topic |
| Author |
Message |
Football Master
Joined: 26 Dec 2008 Posts: 205 Location: Quakenet, #Football
|
Posted: Mon Aug 16, 2010 1:59 pm Post subject: Specific Relay Script |
|
|
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. |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Mon Aug 16, 2010 3:53 pm Post subject: |
|
|
| Code: |
# 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 |
|
| Back to top |
|
 |
Football Master
Joined: 26 Dec 2008 Posts: 205 Location: Quakenet, #Football
|
Posted: Mon Aug 16, 2010 5:18 pm Post subject: |
|
|
[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. |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Mon Aug 16, 2010 8:52 pm Post subject: |
|
|
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: | | 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. |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Mon Aug 16, 2010 8:56 pm Post subject: |
|
|
Oh, oops, somehow I managed to stick an extra brace in there. Change | Code: | while {[gets $fs line] >= 0} {
puthelp "NOTICE $nick :$line"
}
}
close $fs
}
|
to
| Code: | while {[gets $fs line] >= 0} {
puthelp "NOTICE $nick :$line"
}
close $fs
}
|
|
|
| Back to top |
|
 |
Football Master
Joined: 26 Dec 2008 Posts: 205 Location: Quakenet, #Football
|
Posted: Tue Aug 17, 2010 2:17 pm Post subject: |
|
|
It only relays if someone writes "hello" or "goodbye"... it doesn't use the word.txt at all.. _________________ Idling at #Football, Quakenet. |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Wed Aug 18, 2010 8:33 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Football Master
Joined: 26 Dec 2008 Posts: 205 Location: Quakenet, #Football
|
Posted: Thu Aug 19, 2010 4:25 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Thu Aug 19, 2010 9:48 am Post subject: |
|
|
| Oh! Lol, I see. That makes more sense. M'kay, let me see what I can do with that... |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Thu Aug 19, 2010 10:44 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Thu Aug 19, 2010 10:49 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Football Master
Joined: 26 Dec 2008 Posts: 205 Location: Quakenet, #Football
|
Posted: Tue Aug 24, 2010 3:18 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
|