| View previous topic :: View next topic |
| Author |
Message |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Wed Jul 29, 2020 2:18 am Post subject: |
|
|
| simo wrote: | | Thanx crazycat except the thing is i already used split in the set im not sure its a good idea to have duplicate split text |
I don't understand what you mean...
I said you to do:
| Code: | bind pub n .k pub:kicker
proc pub:kicker {nick host hand chan text} {
global botnick
if {![botisop $chan]} {
puthelp "NOTICE $nick :I'm not oped on $chan."
return
}
set users [list]
set reason [join [lrange [split $text "."] 1 end] "."]
set text [lindex [split $text "."] 0]
if {$reason eq ""} { set reason Requested }
foreach user [split $text] {
set user [join $user]
if {![onchan $user $chan]} {
putserv "NOTICE $nick $user is not on channel $chan"
} else {
lappend users $user
}
}
stackKicks $chan [join $users] $reason 4
} |
Just add a line after the foreach. _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Wed Jul 29, 2020 8:48 am Post subject: |
|
|
tnx CrazyCat i tried that one and gave me same result it stripped the {} and returns: Aron is not on channel
while the nick is actually {Aron}
also doesnt the :
lappend users $user
already store the nicks ? instead of using another :
set user [join $user]
Last edited by simo on Wed Jul 29, 2020 9:24 am; edited 1 time in total |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Jul 29, 2020 9:09 am Post subject: |
|
|
Figured I'd butt my head in here...
There is indeed issues with mixing list- and string-types in this script:
Starting from the initial script:
| Code: | set users [list]
set reason [join [lrange [split $text "."] 1 end] "."]
set text [lindex [split $text "."] 0] |
users is an (empty) list
reason is a (sub)string of everything past the first "." on the "commandline"
text is a (sub)string of everything before the first "." on the "commandline"
Moving on...
| Code: | | foreach user [split $text] { |
We want to build a list of users; text is a string presumably with an enumeration of nicks separated with space. Thus, we use split to get a list of strings (nicknames).
| Code: | | set user [join $user] |
This is just wrong; foreach iterates through each list-member - which in this instance is a string. Don't try to join it here, or you'll try to parse {} as list delimiters (and they'll disappear, or the code breaks due to a malformed list).
Next...
| Code: | if {![onchan $user $chan]} {
putserv "NOTICE $nick $user is not on channel $chan"
} else {
lappend users $user
} |
Unless you are using some arcane IRC-server that I havn't kept up to date with, the text-argument for a NOTICE-command needs to be prefixed with : if it contains spaces
| Code: | | putserv "NOTICE $nick :$user is not on channel $chan" |
lappend appends the (string) user to the list users. That is legit.
Finally...
| Code: | | stackKicks $chan [join $users] $reason 4 |
Here we take our list of nicks to be kicked, and squash it into a string; which is not so good given that stackKicks actually expects a list of nicknames, not a string...
Drop the join.
Now, for stackKicks:
| Code: | proc stackKicks {chan kicklist reason {max 4}} {
set count [llength $kicklist]
while {$count > 0} { |
So we expect kicklist to be a list of nicks, and we iterate over it using a while-loop.
| Code: | if {$count > $max} {
set users [join [lrange $kicklist 0 [expr {$max - 1}]] ","]
set kicklist [lrange $kicklist $max end]
incr count -$max |
If there's more than max entities remaining in the list, grab the first max items, and squash then down to a string with "," as separator.
Then trim the first max entities off the kicklist.
Edit: disregard this part, as it's not really valid:
You could probably gain some readability and performance by using lreplace instead of set ... [lrange ...], but it's still fully functional.
Finally decrement count so we don't get stuck in an infinite loop. Good!
| Code: | } else {
set users [join $kicklist ","]
set count 0
} |
Otherwise, we just grab the whole (remaining) list, and squash it.
| Code: | | putnow "KICK $chan $users $reason" |
Finally, we send a KICK-command to the server; once again, if the last argument contains spaces, it should be prefixed with :
Sorry if I got a bit lengthy... _________________ NML_375, idling at #eggdrop@IrcNET
Last edited by nml375 on Wed Jul 29, 2020 10:05 am; edited 1 time in total |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Wed Jul 29, 2020 9:40 am Post subject: |
|
|
excellent tnx nml375 that fixed it
and about the stackicks proc could you show me how to use the lreplace in it as im kinda confused how to integrate it
i assume you meant the :
set users [join [lrange $kicklist 0 [expr {$max - 1}]] ","]
Last edited by simo on Wed Jul 29, 2020 9:45 am; edited 1 time in total |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Wed Jul 29, 2020 9:44 am Post subject: |
|
|
You wrote your post as I was testing.
I was thinking the trouble was in the $user, but it is when appending the list $users. Adding a string which contains special chars adds {} to protect it.
Small test:
| Code: | bind pub - .k pub:kicker
proc pub:kicker {nick uhost handle chan text} {
set text [lindex [split $text "."] 0]
set users [list]
foreach user [split [string trim $text]] {
#putlog "looking for *$user*"
if {![onchan $user $chan]} {
putlog "Can't find *$user*"
} else {
putlog "Will kill *$user*"
lappend users $user
}
}
putlog "List is //$users//"
foreach user2 $users {
putlog "And now *$user2*"
}
}
|
IRC: .k [Guru] Galaad CrazyCat {test0r} .my reason
| Code: | [15:19] Will kill *[Guru]*
[15:19] Will kill *Galaad*
[15:19] Will kill *CrazyCat*
[15:19] Will kill *{test0r}*
[15:19] list is //{[Guru]} Galaad CrazyCat {{test0r}}//
[15:19] And now *[Guru]*
[15:19] And now *Galaad*
[15:19] And now *CrazyCat*
[15:19] And now *{test0r}* |
So, the trouble is just in stackKicks where the list is badly managed _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Wed Jul 29, 2020 9:46 am Post subject: |
|
|
| thank you CrazyCat apreciated |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Jul 29, 2020 10:03 am Post subject: |
|
|
| CrazyCat wrote: | ...
So, the trouble is just in stackKicks where the list is badly managed |
I'm sorry I don't quite follow you there...
stackKicks expects a list of nicks, and properly handles that list as a list as far as I can tell. For me, it would only break if you pass something other than a list to it (such as squashing the list with that join in the end). Would you mind elaborate how it is badly managed?
| simo wrote: | ...
and about the stackicks proc could you show me how to use the lreplace in it as im kinda confused how to integrate it
i assume you meant the :
set users [join [lrange $kicklist 0 [expr {$max - 1}]] ","] |
No, that part is perfectly fine. It's the second line, where you remove the first elements:
| Code: | | set kicklist [lrange $kicklist $max end] |
However, iterating over that code yet another time, I realize I messed up on that one; lreplace expects a list as input, not a varName - thus we'd still have to use set to update the variable. Must've had lappend in my mind (which obviously does the complete opposite to what we are trying to achieve here).
However, for reference this is how you'd use lreplace in your scenario:
| Code: | | set kicklist [lreplace $kicklist 0 [expr {$max -1}]] |
Not sure if this actually ended up more readable... (would make more sense if you'd have to change or remove items in the middle of the list). _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Wed Jul 29, 2020 10:37 am Post subject: |
|
|
tnx for the explanation nml375
ive come another issue with the custom kick reason added
when i do:
it kicks fine with the default kick reason but when i do like:
| Quote: | | .k nick {nick} .some custom reason |
it complains with :
but it kicks both tho so that part works except the custom reason part
i suspect it sees the kick reason as a nick to kick as well |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Wed Jul 29, 2020 10:46 am Post subject: |
|
|
| nml375 wrote: | | CrazyCat wrote: | ...
So, the trouble is just in stackKicks where the list is badly managed |
I'm sorry I don't quite follow you there... |
Sorry, I badly said the thing...
stackKicks may work, but the way the list was sent seems strange to me:
| Code: | | stackKicks $chan [join $users] $reason 4 |
So, $users is a list, and it's joined when sending to stackKicks ? Bad idea imho:
| Code: | % set text "\[Guru\] Galaad CrazyCat {test0r}"
[Guru] Galaad CrazyCat {test0r}
% set users [list]
% foreach user [split $text] { lappend users $user }
% puts $users
{[Guru]} Galaad CrazyCat {{test0r}}
% puts [join $users]
[Guru] Galaad CrazyCat {test0r} |
It's not anymore a list _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Jul 29, 2020 10:47 am Post subject: |
|
|
On my mobile right now, so I'll be brief...
The problem is that the trailing space in the enumeration of nicks becomes an empty element when you split the substring.
I think you'd be able to use something like string trim to remove the space(s) once you've separated the reason from the nicks...
Edit: See code by CrazyCat in a previous post for a good example how to implement this. _________________ NML_375, idling at #eggdrop@IrcNET
Last edited by nml375 on Wed Jul 29, 2020 11:53 am; edited 1 time in total |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Wed Jul 29, 2020 10:50 am Post subject: |
|
|
| nml375 wrote: | The problem is that the trailing space in the enumeration of nicks becomes an empty element when you split the substring.
I think you'd be able to use something like string trim to remove the space(s) once you've separated the reason from the nicks... |
simo, see my previous code (my test in http://forum.egghelp.org/viewtopic.php?p=108811#108811 ):
| Code: | | foreach user [split [string trim $text]] { |
_________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Wed Jul 29, 2020 10:59 am Post subject: |
|
|
| excellent CrazyCat that fixed it much apreciated so far all working well thnx CrazyCat and nml375 |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Jul 29, 2020 11:51 am Post subject: |
|
|
| CrazyCat wrote: | ...
Sorry, I badly said the thing...
stackKicks may work, but the way the list was sent seems strange to me:
| Code: | | stackKicks $chan [join $users] $reason 4 |
|
Fair enough, was afraid I had overlooked something in there.
Sorry about not noticing the addition of string trim in your sample-code, or I would had cited it in my previous reply. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Wed Jul 29, 2020 2:17 pm Post subject: |
|
|
@simo btw, since you added the max as 4th argument and got it set with a default value as 4 in this:
| Code: |
proc stackKicks {chan kicklist reason {max 4}} {
|
there's no need to call the function like:
| Code: |
stackKicks $chan $users $reason 4
|
if it's 4 as well. Or you plan to have a different value? _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Wed Jul 29, 2020 8:48 pm Post subject: |
|
|
| good point caesar thank you |
|
| Back to top |
|
 |
|