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.

Learning tcl for 1 day now

Old posts that have not been replied to for several years.
Locked
b
badfreman

Post by badfreman »

im creating a barman bot binds are ok no problem there, and im useing lrang where command has more than 1 word
if {[lrange $text 0 end] == "and orange"

how would i make it work with what is below
!vodka
!vodka and orange
!vodka and coke
!vodka and lime
!vodka and lemonade
!vodka and blackcurrant
where text can be either "and orang", "and coke", or "and lime" etc
b
badfreman

Post by badfreman »

dont worry peeps i have found out how to
if {%text ==""} elseif {%text==""} etc
P
Petersen
Owner
Posts: 685
Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK

Post by Petersen »

be very careful about using list commands (eg lrange) on strings as you just did in your examples. go read the tcl manual about the verbs 'split' and 'join'.
b
badfreman

Post by badfreman »

i may have incounterd a bigger problem
with my barman bot its going to have a very large drinking habbit
i think im going to be close to 300 binds may be more
would this be to much or is there an easyer way of doing this than below

bind pub - !vodka vodka
proc vodka {nick host handle chan text} {
if {$text == "and lime"} {
puthelp "PRIVMSG $chan :01ACTION gives 4$nick 12a glass of vodka and lime"
} elseif {$text == "and orange"} {
puthelp "PRIVMSG $chan :01ACTION gives 4$nick 12a glass of vodka and ornage"
} elseif {$text == "and coke"} {
puthelp "PRIVMSG $chan :01ACTION gives 4$nick 12a glass of vodka and coke"
} else {
puthelp "PRIVMSG $chan :01ACTION gives 4$nick 12a glass of vodka"
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Here's one possible solution, I don't know if it'll be perfect. You can define all of the extras in a global list:

Code: Select all

set extras {
  "coke"
  "orange"
  "lime"
  ...
}
Then in your bind, you can use a 'foreach' loop to see if any of those things are mentioned in the text:

Code: Select all

proc vodka {nick host handle chan text} {
  global extras

  # Go through the whole list
  foreach extra $extras {
    # See if it's mentioned anywhere
    if {[string match "*$extra*" $text]} {
      puthelp "PRIVMSG $chan :[1code]
proc vodka {nick host handle chan text} {
  global extras

  # Go through the whole list
  foreach extra $extras {
    # See if it's mentioned anywhere
    if {[string match "*$extra*" $text]} {
      puthelp "PRIVMSG $chan :01ACTION gives $nick a glass of vodka and $extra 01"
      return 0
    }
  }
  # If we made it this far, none of the extras were mentioned
  puthelp "PRIVMSG $chan :01ACTION gives $nick a glass of vodka01"
  return 0
}
[/code1]01ACTION gives $nick a glass of vodka and $extra [1code]
proc vodka {nick host handle chan text} {
  global extras

  # Go through the whole list
  foreach extra $extras {
    # See if it's mentioned anywhere
    if {[string match "*$extra*" $text]} {
      puthelp "PRIVMSG $chan :01ACTION gives $nick a glass of vodka and $extra 01"
      return 0
    }
  }
  # If we made it this far, none of the extras were mentioned
  puthelp "PRIVMSG $chan :01ACTION gives $nick a glass of vodka01"
  return 0
}
[/code1]01"
      return 0
    }
  }
  # If we made it this far, none of the extras were mentioned
  puthelp "PRIVMSG $chan :[1code]
proc vodka {nick host handle chan text} {
  global extras

  # Go through the whole list
  foreach extra $extras {
    # See if it's mentioned anywhere
    if {[string match "*$extra*" $text]} {
      puthelp "PRIVMSG $chan :01ACTION gives $nick a glass of vodka and $extra 01"
      return 0
    }
  }
  # If we made it this far, none of the extras were mentioned
  puthelp "PRIVMSG $chan :01ACTION gives $nick a glass of vodka01"
  return 0
}
[/code1]01ACTION gives $nick a glass of vodka[1code]
proc vodka {nick host handle chan text} {
  global extras

  # Go through the whole list
  foreach extra $extras {
    # See if it's mentioned anywhere
    if {[string match "*$extra*" $text]} {
      puthelp "PRIVMSG $chan :01ACTION gives $nick a glass of vodka and $extra 01"
      return 0
    }
  }
  # If we made it this far, none of the extras were mentioned
  puthelp "PRIVMSG $chan :01ACTION gives $nick a glass of vodka01"
  return 0
}
[/code1]01"
  return 0
}
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Erm, it seems to have corrupted my post. I hope you can make it out hehe
b
badfreman

Post by badfreman »

erm i dont know where to start, dont know what has happend to you script i cant imagine an improvment being that long no fault of yours can u clear this up for me please. I have scripted a large amout of drinks so fare say 150+ below is a small exsample but i feel i am over useing code just to respond to a pub or a matched word that is in the script i intend to get every drink there is on the planet into this script :smile: i intend to have in the PRIVMSG responce random events with humour as i dont want the bot to keep doing the same thing like give's nick a pint of beer when he could also could respond with give's $nick a refreshing pint of beer, get my meaning

#v
bind pub - !valkovenalainen valkovenalainen
proc valkovenalainen {nick host handle chan text} {
puthelp "PRIVMSG $chan :01ACTION gives 4$nick 12a valkovenalainen cocktail"
}

#w
bind pub - !whisky whisky
proc whisky {nick host handle chan text} {
if { $text == "sour" } {
puthelp "PRIVMSG $chan :01ACTION gives 4$nick 12a whisky sour cocktail"
}
}


bind pub - !white white
proc white {nick host handle chan text} {
if { $text == "lady" } {
puthelp "PRIVMSG $chan :01ACTION gives 4$nick 12a white lady cocktail"
} elseif { $text == "russian" } {
puthelp "PRIVMSG $chan :01ACTION gives 4$nick 12a white russian cocktail"
}
}


#v
bind pub - !ville ville
proc ville {nick host handle chan text} {
if { $text == "vallaton" } {
puthelp "PRIVMSG $chan :01ACTION gives 4$nick 12a !ville vallaton cocktail"
}
}


bind pub - !violetta violetta
proc violetta {nick host handle chan text} {
puthelp "PRIVMSG $chan :01ACTION gives 4$nick 12a violetta cocktail"
}
bind pub - !vodka vodka
proc vodka {nick host handle chan text} {
if { $text == "gimlet" } {
puthelp "PRIVMSG $chan :01ACTION gives 4$nick 12a vodka gimlet cocktail"
} elseif { $text == "martini" } {
puthelp "PRIVMSG $chan :01ACTION gives 4$nick 12a vodka martini cocktail"
} elseif { $text == "polar" } {
puthelp "PRIVMSG $chan :01ACTION gives 4$nick 12a vodka polar cocktail"
} elseif { $text == "and lime" } {
puthelp "PRIVMSG $chan :01ACTION gives 4$nick 12a glass of vodka and lime"
} elseif { $text == "and orange" } {
puthelp "PRIVMSG $chan :01ACTION gives 4$nick 12a glass of vodka and orange"
} elseif { $text == "and coke" } {
puthelp "PRIVMSG $chan :01ACTION gives 4$nick 12a glass of vodka and coke"
} else {
puthelp "PRIVMSG $chan :01ACTION gives 4$nick 12a glass of vodka"
}
}


<font size=-1>[ This Message was edited by: badfreman on 2002-05-09 06:02 ]</font>
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

If you have 150 drinks, it's going to be long no matter what. What I showed you was how to elimidate some redundancy: Whether the drink is vodka, rum, jack daniels, or whatever, you can use the same code to have "and coke", "and lime", "and ...".
b
badfreman

Post by badfreman »

do i use ur script the way it is set out i dont mind about it going to be a long haul
thats expected with scripting can u help me with setting up random replys also if you have the time
i am now at 242 (english) drinks and i have not touched softdrinks, spirts or wins yet not to mention tea or coffe lol

<font size=-1>[ This Message was edited by: badfreman on 2002-05-09 21:14 ]</font>
Locked