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.

banned words script [Solved]

Help for those learning Tcl or writing their own scripts.
Post Reply
j
jeremie
Voice
Posts: 9
Joined: Thu Aug 30, 2007 3:35 pm

banned words script [Solved]

Post by jeremie »

I am amending my script to check for the banned words on actions.

I want to strip out the users name from the text and just check the rest of the text.

I tried using this :-

Code: Select all

foreach user [split [chanlist $chan] " "] {
    set found [string match -nocase *$user* $text]
    if {$found} {
      regsub -all -nocase -- $user $text [string tolower $user] text
    }
which works on normal pubm but not action.

I also tried using these :-

Code: Select all

set text [string trim [string range $text $nick+1 e]]

Code: Select all

set text [string trim $text {$nick+1} e]

Code: Select all

set text [string trim $text [expr $nick+1] e]
and various combinations using both {} and [] tound the $nick+1 in each

All of the above codes came up with this return :-

bad index "whatever the action was": must be integer or end?-integer?

Can somebody please help me to solve this problem?
Last edited by jeremie on Mon Sep 24, 2007 11:09 am, edited 1 time in total.
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Try

Code: Select all

regsub -nocase -all [list [join [chanlist $chan] |]] $text {} text
Edit: Added -all switch.
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Just some piece of advice:

Code: Select all

set text [string trim [string range $text $nick+1 e]]
set text [string trim $text {$nick+1} e]
set text [string trim $text [expr $nick+1] e]
You cannot perform mathematrical operations on a string which is NOT AN INTEGER, such as $nick. Since IRCd's restrict nicks to be alphanumeric.

Hence you can only perform mathematical operations such as add, sub, mul, div etc on strings which are integers.

Example:

Code: Select all

if {[string is integer $mydata]} {
 set newtext [string range $text [expr $mydata+1] end]
}
And by bad index it refers, this should be:

Code: Select all

set text [string trim $text [expr $nick+1] e]

this:
set text [string range $text [expr $nick+1] end]
#or
set text [string range $text [expr $nick+1] end-1]
set text [string range $text [expr $nick+1] end-2]

#and
set text [string trim $text e]
set text [string trimright $nick a]
set text [string trimleft $ident ~]
#etc
String trim is only for trimming certain words in a string, it cannot be used with indexes. See the tcl manual for string range for more help.
Last edited by awyeah on Mon Sep 24, 2007 1:14 pm, edited 1 time in total.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
j
jeremie
Voice
Posts: 9
Joined: Thu Aug 30, 2007 3:35 pm

Solved

Post by jeremie »

Thank you Sir_Fz for your suggestion.

Thank you awyeah for the help you have given about strings I'm sure that will be very useful for future projects.

After thinking about the problem and remebering what I said in my first post about the code working in my normal pubm proc, the solution I have come up with is to just filter the action text in my action proc and then push it through to my pubm proc.

I have done a quick test on my script and it now seems to work correctly, I will test it with all the different variables then make it live on my bots.

Once again thank you both :)
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Re: banned words script [Solved]

Post by Sir_Fz »

jeremie wrote:

Code: Select all

foreach user [split [chanlist $chan] " "] {
    set found [string match -nocase *$user* $text]
    if {$found} {
      regsub -all -nocase -- $user $text [string tolower $user] text
    }
This does not strip the nicknames from the message, instead it replaces the nicknames with their lower-case form. Not sure if that was your intention.
j
jeremie
Voice
Posts: 9
Joined: Thu Aug 30, 2007 3:35 pm

Post by jeremie »

Yes sorry Sir_Fz I was testing so many different pieces of code and this is what I am using.

Code: Select all

foreach user [split [chanlist $chan] " "] {
    set found [string match -nocase *$user* $text]
    if {$found} {
      regsub -all -nocase -- $user $text "" text
    }
 }
If I used your sugestion of the regsub would it work better?

Code: Select all

regsub -nocase -all [list [join [chanlist $chan] |]] $text {} text


Would I just replace mine with yours or does your one line replace all my code?

Sorry if that's a dumb question but I am still learning.

:oops:
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Yes, that line replaces your code (the foreach-statement). Give it a try.
j
jeremie
Voice
Posts: 9
Joined: Thu Aug 30, 2007 3:35 pm

Post by jeremie »

Thank you Sir_Fz I tried it and it works.

:)
Post Reply