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.

Auto responder (need help with regsub)

Old posts that have not been replied to for several years.
Locked
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Auto responder (need help with regsub)

Post by awyeah »

Here is the script I made. Still alot of things needed to be fixed in it.

Code: Select all

set responsetimer "1/2"
set responsetime "2secs"
#1 = defined time
#2 = random

set responsechans "#bla1 #bla2 #bla3"
set responsechantype "1/2"
set nobotnick "1/2"
set randomreply "0/1/2"
set randomreplyno "5"
set responsetimer "0/1"


set respond_words {
{ "lol" } { "Laughs Out Loud" "haha %nick" "yahoo!" }
{ "brb" } { "Be Right Back %nick" "ok" "I'm right here on %chan" }
{ "cya" } { "See you" "ok dude" "bye bye, %nick!" }
{ "hi" "hello" } { "hey %nick" "hows ya doing, %nick?" "whats up, %nick?" } }
#You can use %nick, %chan, %uhost and %hand for the reponses too,

#Example
set respond_words {
{ "trigger1" } { "random reply 1" "random reply 2" }
{ "trigger1" } { "random reply 1" "random reply 2" "random reply 3" }
{ "trigger1" "trigger2" } { "random reply 1" "random reply 2" "random reply 3" }
{ "trigger1" "trigger2" "trigger3" } { "random reply 1" "random reply 2" }
{ "trigger1" "trigger2" "trigger3" } { "random reply 1" "random reply 2" "random reply 3" }
{ "trigger1" "trigger2" "trigger3" } { "random reply 1" "random reply 2" "random reply 3" "random reply 4" }
#You can set any amount of triggers and random replies.
#Minimum for atleast 1 trigger there must be a reply set or vice versa.


if {($responsetype == 3) || ($responsetype == 4)} { bind notc - * check_word }
if {($responsetype == 2) || ($responsetype == 4)} { bind ctcp - ACTION check_word }
if {($responsetype == 1) || ($responsetype == 4)} { bind pubm - * check_response_word }

proc check_response_word {nick uhost hand chan text} {
 global respond_words responsechantype nobotnick randomreply
 if {([isbotnick $nick]) || ([isbotnick $chan]) || (![string equal "#" [string index $chan 0]])} { return 0 }
 if {($responsechantype == 1) && ([lsearch -exact [split [string tolower $responsechans]] [string tolower $chan]] == -1)} { return 0 }
  foreach {triggers responses} $respond_words {; foreach trigger $triggers {
  if {($responsetimer == 2)} { set responsetime [rand 10] }
  set filteredresponses [response:filter $filteredresponses $nick $uhost $hand $chan]
  if {(($responsetimer == 1) && ($reponsetime != "") && ($reponsetime > 0)) || ($responsetimer == 2)} {
   if {($randomreply == 0) && ($nobotnick == 1) && ([string match -nocase "* $botnick *" " $text "]) && ([string match -nocase "* $trigger *" " $text "])} {
    utimer $responsetime [list putserv "PRIVMSG $chan :[lindex $filteredresponses [rand [llength $filteredresponses]]]"]; return 0 }
   if {($randomreply == 0) && ($nobotnick == 2) && (![string match -nocase "* $botnick *" " $text "]) && ([string match -nocase "* $trigger *" " $text "])} {
    utimer $responsetime [list putserv "PRIVMSG $chan :[lindex $filteredresponses [rand [llength $filteredresponses]]]"]; return 0 }
   if {($randomreply == 1) && ([rand 2] == 1) && ($nobotnick == 1) && ([string match -nocase "* $botnick *" " $text "]) && ([string match -nocase "* $trigger *" " $text "])} {
    utimer $responsetime [list putserv "PRIVMSG $chan :[lindex $filteredresponses [rand [llength $filteredresponses]]]"]; return 0 }
   if {($randomreply == 1) && ([rand 2] == 1) && ($nobotnick == 2) && (![string match -nocase "* $botnick *" " $text "]) && ([string match -nocase "* $trigger *" " $text "])} {
    utimer $responsetime [list putserv "PRIVMSG $chan :[lindex $filteredresponses [rand [llength $filteredresponses]]]"]; return 0 }
   if {($randomreply == 2) && ($randomreplyno != "") && ($randomreplyno > 0) && ($nobotnick == 1) && ([string match -nocase "* $botnick *" " $text "]) && ([string match -nocase "* $trigger *" " $text "])} {
    utimer $responsetime [list putserv "PRIVMSG $chan :[lindex $filteredresponses [rand [llength $filteredresponses]]]"]; return 0 }
    if {($randomreply == 2) && ($randomreplyno != "") && ($randomreplyno > 0) && ($nobotnick == 2) && (![string match -nocase "* $botnick *" " $text "]) && ([string match -nocase "* $trigger *" " $text "])} {
    utimer $responsetime [list putserv "PRIVMSG $chan :[lindex $filteredresponses [rand [llength $filteredresponses]]]"]; return 0 } }
   if {($responsetimer == 0)} {
   if {($randomreply == 0) && ($nobotnick == 1) && ([string match -nocase "* $botnick *" " $text "]) && ([string match -nocase "* $trigger *" " $text "])} {
    putserv "PRIVMSG $chan :[lindex $filteredresponses [rand [llength $filteredresponses]]]"; return 0 }
   if {($randomreply == 0) && ($nobotnick == 2) && (![string match -nocase "* $botnick *" " $text "]) && ([string match -nocase "* $trigger *" " $text "])} {
     putserv "PRIVMSG $chan :[lindex $filteredresponses [rand [llength $filteredresponses]]]"; return 0 }
   if {($randomreply == 1) && ([rand 2] == 1) && ($nobotnick == 1) && ([string match -nocase "* $botnick *" " $text "]) && ([string match -nocase "* $trigger *" " $text "])} {
    putserv "PRIVMSG $chan :[lindex $filteredresponses [rand [llength $filteredresponses]]]"; return 0 }
   if {($randomreply == 1) && ([rand 2] == 1) && ($nobotnick == 2) && (![string match -nocase "* $botnick *" " $text "]) && ([string match -nocase "* $trigger *" " $text "])} {
     putserv "PRIVMSG $chan :[lindex $filteredresponses [rand [llength $filteredresponses]]]"; return 0 }
   if {($randomreply == 2) && ($randomreplyno != "") && ($randomreplyno > 0) && ($nobotnick == 1) && ([string match -nocase "* $botnick *" " $text "]) && ([string match -nocase "* $trigger *" " $text "])} {
    putserv "PRIVMSG $chan :[lindex $filteredresponses [rand [llength $filteredresponses]]]"; return 0 }
    if {($randomreply == 2) && ($randomreplyno != "") && ($randomreplyno > 0) && ($nobotnick == 2) && (![string match -nocase "* $botnick *" " $text "]) && ([string match -nocase "* $trigger *" " $text "])} {
      putserv "PRIVMSG $chan :[lindex $filteredresponses [rand [llength $filteredresponses]]]"; return 0 }
      }
   }
}


proc check_word_act {nick uhost hand chan key text} {
 check_response_word $nick $uhost $hand $chan $text
}

proc check_word_notc {nick uhost hand text {chan ""}} {
  check_response_word $nick $uhost $hand $chan $text
}


proc response:filter {data nick uhost hand chan} {
 global botnick
 regsub -all -- %nick $data $nick data ; regsub -all -- %uhost $data $uhost data
 regsub -all -- %botnick $data $botnick data
 regsub -all -- %hand $data $hand data ; regsub -all -- %chan $data $chan data
 regsub -all -- %b $data  data ; regsub -all -- %r $data  data
 regsub -all -- %u $data  data ; regsub -all -- %c $data  data
 return $data
}
The way I have made the triggers and responses is it the best way todo them like this? Because I want an AI reply from the bot meaning any random reply from any of the single/multiple triggers.

The main problem I am having problem with the regsub. I want $nick to replace %nick in the triggers, %uhost for $uhost, %chan for $chan and so on...

But it doesn't seem to work correct. Can anyone help me? Would be kindly appreciated! :mrgreen:
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Check out subst.
Once the game is over, the king and the pawn go back in the same box.
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Not quite the solution, but anyway I will give it a look, kthx. :lol:
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: Auto responder (need help with regsub)

Post by user »

awyeah wrote:Not quite the solution, but anyway I will give it a look, kthx. :lol:
All you have to do to switch to 'subst' is replace % with $ and enclose your messages in braces instead of quotes. (and add variables for those color codes - and enclose variable names in braces where needed) As a bonus you get backslash/command substitution too (unless you turn it off). You should invoke 'subst' on the message right before it's sent, to avoid doing any redundant/unneeded work. If you for some reason want to do it the hard way, 'string map' would be much faster than 'regsub'.
Have you ever read "The Manual"?
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

So this should be it I guess.

Code: Select all

[subst [lindex $filteredresponses [rand [llength $filteredresponses]]]]
What about the braces? Do we really need to switch the triggers and responses, quotes to braces? But why?! Those are easier to set up multiple triggers and not messy or complicated. :roll:
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
K
KevKev
Halfop
Posts: 67
Joined: Fri Oct 03, 2003 5:15 am

Post by KevKev »

have you considered using the switch function?
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

I did think of it first, but as you can see my logic is a bit complicated so I need to go with the if and else conditions and not the switching function.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
K
KevKev
Halfop
Posts: 67
Joined: Fri Oct 03, 2003 5:15 am

Post by KevKev »

awyeah wrote:I did think of it first, but as you can see my logic is a bit complicated so I need to go with the if and else conditions and not the switching function.
Spiffy :) just worked great for me when i was trying to do dimilar things (trying to parse command options from user input in a reasonable manner that didn;t make me go cross eyed). Worked great for me and figured i'd suggest it based on a cursory glance at your code :)
Locked