| View previous topic :: View next topic |
| Author |
Message |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Mon Sep 14, 2020 11:30 am Post subject: chanset via pub command |
|
|
i was using this nice small tcl wich sets chanset via pub command but somehow doesnt set all chansettings for example this doesnt seem to work:
.chanset ap:repeatl 2:10 60 k:kb 2
it sets the first param only 2:10
| Code: |
bind pub n|n .chanset pub:chanset
proc pub:chanset {nick uhost hand chan arg} {
foreach {set value} [split $arg] {break}
if {![info exists value]} {
catch {channel set $chan $set} error
} {
catch {channel set $chan $set $value} error
}
if {$error == ""} {
putnow "NOTICE $nick :Successfully set $arg"
} {
putnow "NOTICE $nick :Error setting $arg: [lindex $error 0]..."
}
}
|
|
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Mon Sep 14, 2020 12:18 pm Post subject: |
|
|
The split command cut $args in 5 pieces (split is on " ") and set the first to $set (bad idea of variable name) and the second to $value (bad idea too). The script wasn't thought for complex values.
You can use scan and a regexp to set $set and $value, or do it in 2 times whith:
| Code: | set set [lindex [split $arg] 0]
set value [join [lrange [split $arg] 1 end]] |
_________________ 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: Mon Sep 14, 2020 1:55 pm Post subject: |
|
|
| excellent tnx CrazyCat |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue Sep 15, 2020 4:23 am Post subject: |
|
|
You shouldn't use set, arg or args cos they have special meanings in TCL.
Here's a nice trick with lassign:
| Code: |
% set text "ap:repeatl 2:10 60 k:kb 2"
ap:repeatl 2:10 60 k:kb 2
% set value [lassign $text mode]
2:10 60 k:kb 2
% puts $mode
ap:repeatl
% puts $value
2:10 60 k:kb 2
|
_________________ 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: Tue Sep 15, 2020 3:01 pm Post subject: |
|
|
you mean like this caesar:
| Code: |
proc pub:chanset {nick host hand chan text} {
set text [lindex [split $text] 0]
set value [lassign $text mode]
if {![info exists value]} {
catch {channel set $chan $set} error
} {
catch {channel set $chan $set $value} error
}
if {$error == ""} {
putnow "NOTICE $nick :Successfully set $text"
} {
putnow "NOTICE $nick :Error setting $text: [lindex $error 0]..."
}
}
|
|
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Tue Sep 15, 2020 6:17 pm Post subject: |
|
|
No, he means (if I'm not wrong):
| Code: | proc pub:chanset {nick host hand chan text} {
set value [lassign $text mode]
if {![info exists value] || $value eq ""} {
catch {channel set $chan $mode} error
} else {
catch {channel set $chan $mode $value} error
}
if {$error == ""} {
putnow "NOTICE $nick :Successfully set $text"
} else {
putnow "NOTICE $nick :Error setting $text: [lindex $error 0]..."
}
} |
_________________ 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: Tue Sep 15, 2020 7:16 pm Post subject: |
|
|
| tnx for that crazycat tried that didnt seem to work properly tho same result of just setting parts of the settings |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Wed Sep 16, 2020 12:54 am Post subject: |
|
|
Did you add a putlog line to see what mode and value would be set and what error do you get? Something like:
| Code: |
putlog "trying to set $mode to $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 Sep 16, 2020 10:44 am Post subject: |
|
|
ive added this caesar but it didnt output anything
putserv "privmsg $chan :trying to set $mode to $value" |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Wed Sep 16, 2020 11:04 am Post subject: |
|
|
I think you don't know how to debug a script...
Try this code, and copy us the command you type in chan and what happens in party-line
| Code: | proc pub:chanset {nick host hand chan text} {
set value [lassign $text mode]
putlog "getting mode: *$mode* and value: *$value*"
if {![info exists value] || $value eq ""} {
putlog "value seems to not be set"
catch {channel set $chan $mode} error
} else {
putlog "ok, value is set"
catch {channel set $chan $mode $value} error
}
putlog "error is *$error*"
if {$error == ""} {
putnow "NOTICE $nick :Successfully set $text"
} else {
putnow "NOTICE $nick :Error setting $text: [lindex $error 0]..."
}
} |
Using .console +d is a good way to see errors. And if an error appear, type .set errorInfo to have more detals _________________ 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 Sep 16, 2020 12:35 pm Post subject: |
|
|
| tried your last posted code and didnt output any error CrazyCat |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Wed Sep 16, 2020 12:45 pm Post subject: |
|
|
list doesn't contain element 2
while executing
"lreplace $items 2 2" |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Wed Sep 16, 2020 12:51 pm Post subject: |
|
|
So you have an error, but not in that proc, because there is no lreplace in it.
You'd better give us your full script, or find which of your script did this error. _________________ 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 Sep 16, 2020 1:06 pm Post subject: |
|
|
| cleared all tcls and left only the chanset one and seems to work now |
|
| Back to top |
|
 |
|