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.

String/list matching

Old posts that have not been replied to for several years.
Locked
s
scr0llwheel
Voice
Posts: 17
Joined: Fri Jan 03, 2003 12:37 am

String/list matching

Post by scr0llwheel »

First off, the code:

Code: Select all

proc per_say { nick host hand args } {
  if { [string match "#*" $args] } {
    puthelp "PRIVMSG [lindex $args 1] :[join [lrange $args 2 end]]"
  } else {
    puthelp "PRIVMSG [lindex $args 0] :[join [lrange $args 1 end]]"
  }
}
Ok, I'm trying to make the bot say something when:
a) .say [#channel] <text> ..... this is a pub cmd and [#channel] is optional. If it isn't mentioned, then the proc is executed in the channel where the cmd was run.
OR
b) /msg bot say <#channel> <text> ..... this is a msg cmd and <#channel> is required.

Basically, it's not working, at all. I think I've got multiple problems wrong with it since when I add a "Text" to the output, it just shows "Text" when messaging a channel. (Yeah, I suck at explaining).

Anyway, any help/ideas/suggestions would be greatly appreciated.
Thanks,
scr0llwheel
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

2 things: you forgot the 'chan' argument, and you shouldn't use 'args' in this scenario.

proc whatever {nick uhost hand chan text}

that's about how it should look.

Then what you want to do, is use split and lindex to get the first word of text. Then see if it starts with a #, like you already did. From there your script is basically right.
s
scr0llwheel
Voice
Posts: 17
Joined: Fri Jan 03, 2003 12:37 am

Post by scr0llwheel »

That would work for pub commands but I want this to work for both public and msg commands. And with msg commands, the 'chan' argument isn't there!

That's the problem :)
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

You should use somthing like

Code: Select all

proc per_say {nick host uh args} {
  if {[llength $args] == 2} {
    if {[validchan [set t [lindex [split [lindex $args 1]] 0]]]} {
      set chan $t
      set text [join [lrange [split [lindex $args 1]] 1 end]]
    } else {
      set chan [lindex $args 0]
      set text [lindex $args 1]
    }
  } else {
    if {![validchan [set t [lindex [split [lindex $args 0]] 0]]} {
      # This was a MSG bind. No channel was given, so don't attempt to send
      return
    }
    set chan $t
    set text [lrange [split [lindex $args 0]] 1 end]
  }
  puthelp "PRIVMSG $chan :$text"
}
Locked