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 

banned words script [Solved]

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
jeremie
Voice


Joined: 30 Aug 2007
Posts: 9

PostPosted: Sun Sep 23, 2007 6:39 pm    Post subject: banned words script [Solved] Reply with quote

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:
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:
set text [string trim [string range $text $nick+1 e]]


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


Code:
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
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sun Sep 23, 2007 7:26 pm    Post subject: Reply with quote

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


Edit: Added -all switch.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Mon Sep 24, 2007 1:02 am    Post subject: Reply with quote

Just some piece of advice:

Code:

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:

if {[string is integer $mydata]} {
 set newtext [string range $text [expr $mydata+1] end]
}


And by bad index it refers, this should be:
Code:

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.
_________________
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================


Last edited by awyeah on Mon Sep 24, 2007 1:14 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
jeremie
Voice


Joined: 30 Aug 2007
Posts: 9

PostPosted: Mon Sep 24, 2007 7:54 am    Post subject: Solved Reply with quote

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 Smile
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Mon Sep 24, 2007 1:40 pm    Post subject: Re: banned words script [Solved] Reply with quote

jeremie wrote:
Code:
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.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
jeremie
Voice


Joined: 30 Aug 2007
Posts: 9

PostPosted: Mon Sep 24, 2007 3:12 pm    Post subject: Reply with quote

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

Code:
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:
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.

Embarassed
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Mon Sep 24, 2007 3:17 pm    Post subject: Reply with quote

Yes, that line replaces your code (the foreach-statement). Give it a try.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
jeremie
Voice


Joined: 30 Aug 2007
Posts: 9

PostPosted: Mon Sep 24, 2007 3:34 pm    Post subject: Reply with quote

Thank you Sir_Fz I tried it and it works.

Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help 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