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 

Modifying decision.tcl

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


Joined: 20 May 2008
Posts: 2
Location: Finland

PostPosted: Tue May 20, 2008 5:33 pm    Post subject: Modifying decision.tcl Reply with quote

Hello.

I found this great script which can make some decisions for me. It works like this:

<user> [ ] option 1 [ ] option 2 [ ] option 3
<bot> [x] option 1 [ ] option 2 [ ] option 3

The idea is great but I'd like to modify it a bit. The best way to avoid channel flooding is to set the user input on private messages and the actual output on the channel. Example:

User sends a private message to bot: "[ ] option 1 [ ] option 2 [ ] option 3"
Bot chooses randomly an option and prints the output on #channel:
<bot> user on private: [ ] option 1 [x] option 2 [ ] option 3

So I modified the code like this (Note: I haven't touched the actual text manipulating. I've only changed the first four lines and the puthelp-line):

Code:

set channl #channel
bind msg - \[ proc:decision
proc proc:decision {nick host hand arguments} {
global channl

   set arguments [split $arguments]
   set count 1
   set klammer_count 0
   if {([lindex $arguments 0] == "]") || ([string first "]" [lindex $arguments 0]] == 0)} {
      incr klammer_count
   } else {
      return
   }
   while {$count != [llength $arguments]} {
      if {[lindex $arguments $count] == "\["} {
         set tmp $count
         incr tmp
         if {([lindex $arguments $tmp] == "]") || ([string first "]" [lindex $arguments $tmp]] == 0)} {
            incr klammer_count
         }
      }
      incr count
   }
   set count 0
   set myrand [rand $klammer_count]
   set klammer_count 0
   if {$myrand == 0} {
      set output "\[x"
      while {$count != [llength $arguments]} {
         set output "$output[lindex $arguments $count] "
         incr count
      }
   } else {
      set output "\["
      while {$count != [llength $arguments]} {
         if {[lindex $arguments $count] == "\["} {
            set tmp $count
            incr tmp
            if {([lindex $arguments $tmp] == "]") || ([string first "]" [lindex $arguments $tmp]] == 0)} {
               incr klammer_count
            }
         }
         if {$klammer_count == $myrand} {
            if {([lindex $arguments $count] == "]") || ([string first "]" [lindex $arguments $count]] == 0)} {
               set output "[string range $output 0 end]x"
            } else {
               set output "$output "
            }
         } else {
            set output "$output "
         }
         set output "$output[lindex $arguments $count]"
         incr count
      }

   }
   puthelp "PRIVMSG $channl :$nick on private: '$output'"
}


But the code doesn't seem to work. At first I thought the problem was in the bind part as I'm using MSG, but it treats everything identically as PUB.

So could someone help me? I'm really running out of ideas. Thanks in advance.

P.S. My first post Smile
Back to top
View user's profile Send private message
Papillon
Owner


Joined: 15 Feb 2002
Posts: 724
Location: *.no

PostPosted: Wed May 21, 2008 6:32 am    Post subject: Reply with quote

your problem most likely is in the very first line
Code:
set channl #channel

tcl interpret everything following # on a line as a comment, so you need to do
Code:
set channl "#channel"

for $channl not to be an empty variable
_________________
Elen sila lúmenn' omentielvo
Back to top
View user's profile Send private message MSN Messenger
droune
Voice


Joined: 20 May 2008
Posts: 2
Location: Finland

PostPosted: Wed May 21, 2008 6:52 am    Post subject: Reply with quote

Papillon wrote:
your problem most likely is in the very first line
Code:
set channl #channel

tcl interpret everything following # on a line as a comment, so you need to do
Code:
set channl "#channel"

for $channl not to be an empty variable


Ahh, so that's the problem. It works now. Thanks a lot Smile
Back to top
View user's profile Send private message
Papillon
Owner


Joined: 15 Feb 2002
Posts: 724
Location: *.no

PostPosted: Wed May 21, 2008 10:35 am    Post subject: Reply with quote

I got really bored, so redesigned it abit. Don't shoot me if any errors occur as I am unable to test it on an eggdrop and my tcl abilities might be a bit rusty
Code:
set channl "#chaneelyouwant"
bind msg - \[ making_choices
proc making_choices {nick host hand arg} {
   set arg [fixthearg "$arg"]
   set opts [regexp -all {\[\]} $arg]
   if {[lindex [split $arg] 0] == {\[\]} || $opts == 1} { return }
   set inx [lsearch -all [split $arg] {\[\]}]
   set ran [rand $opts]
   set showlist [list ""]
   for {set st 0} {$st <= [expr $opts -1]} {incr st} {
      set putin ""
      if {$st == [expr $opts -1]} {
         set inx_str [join [lrange [split $arg] [expr [lindex $inx $st] +1] end]]
      } else {
         set inx_str [join [lrange [split $arg] [expr [lindex $inx $st] +1] [expr [lindex $inx [expr $st +1]] -1]]]
      }
      if {$inx_str == {}} { continue }
      if {$st == $ran} { set putin x }
      lappend showlist [join "\[$putin\] $inx_str"]
   }
   puthelp "PRIVMSG $::channl :[join $showlist]"
}

proc fixthearg {arg} {
   regsub -all {\[\]} "\[$arg" " \[\] " arg
   regsub -all {  } $arg { } arg
   return "$arg"
}

It should be able to handle abit more faulty inputs... hopefully Very Happy
_________________
Elen sila lúmenn' omentielvo
Back to top
View user's profile Send private message MSN Messenger
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