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 Reply Script

Help for those learning Tcl or writing their own scripts.
Post Reply
S
Sbarkeri
Voice
Posts: 15
Joined: Tue Aug 11, 2009 12:01 am

Auto Reply Script

Post by Sbarkeri »

Hi I am very new to eggdrops and TCL scripting however I want to make a very simple auto reply script.

I want the bot to scan the public chat in around 3 channels, when someone types something such as !rules or !help I want it to display a string of text to the channel however this string of text will be different for each of the 3 channels.

Code: Select all

bind pub - !rules rules
proc rules {nickname userhost handle channel arguments} {
puthelp "PRIVMSG #clanbase.mw2 :HI! $nick Rules for Call of Duty 4 http://clanbase.ggl.com/rules.php?lid=5709"
}
I have so far managed to make that embarrassing efford for a script, it works well however there are a few more things I want to get it to do.
1. If someone types the same command in a different channel I want it to reply with a different message.
2. For it to change the channel mode to [-c] before it sends the message and [+c] just after it has sent it, I had a play around with the PUTMODE command however failed miserably.
3. Somehow enable the use of wildcards so that it detects the text anywhere in the chat and not just at the beggining of the sentence.

I really hope someone can help me here, I am very much a visual basic guy so this TCL stuff is very alien to me.

Cheers :lol:
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

In order to send different messages to different channels, use one of the various conditional constructs, and test the value of the variable channel. Here I'll go with the switch construct, as it is easily extended to handle many different values of the tested variable. I also use a command (string tolower) to make sure the channel name is always in lower case, since switch cares for case:

Code: Select all

proc rules {nickname userhost handle channel arguments} {
  switch [string tolower $channel] {
    "#clanbase.mw2" {
      putserv "MODE #clanbase.mw2 -c"
      putserv "PRIVMSG #clanbase.mv2 :Hi $nick! Rules for Call of Duty 4 http://clanbase.ggl.com/rules.phpp?lid=5709"
      putserv "MODE #clanbase.mw2 +c"
    }
    "#clanbase.other" {
      putserv "MODE #clanbase.mw2 -c"
      putserv "PRIVMSG #clanbase.other :Hi $nick! Rules for Other yet to come"
      putserv "MODE #clanbase.mw2 +c"
    }
  }
}
With putmode, I assume you're thinking of pushmode. Pushmode has the ability to group up mode changes to the most efficient sets (depending on settings). As such, it will not issue the changes directly, but put them in a list that will be tended to once the proc ends. Any double or contradictive mode-changes will then be ignored, and modes stacked as efficiently as possible.

In the code above, I used the putserv instead, which sends the mode command directly to the SERV-queue (fairly fast queue in eggdrop), so the commands should be sent out in the order I issue them.

If you'd like to trigger on anything containing !rules, rather than starting with !rules, you'll need to change your binding from the public command binding (pub), into the public match (pubm):

Code: Select all

bind pubm - "% *!rules*" rules
NML_375
S
Sbarkeri
Voice
Posts: 15
Joined: Tue Aug 11, 2009 12:01 am

Post by Sbarkeri »

Wow, can't thank you enough, you just solved my 2 days of install various TCL scripts in 20 minutes!

Really though cheers mate can't thank you enough.

Just one small question that I'm sure requires 1 or 2 lines of code, I want to send a message cross channel (the bot is in both channels so it should be fine just to use PRIVMSG). I want one of the admins in the channel #clanbase.crew.mw2 to be able to type "!wars USERHERE" and then a message to appear in #clanbase.mw2 saying "*Notice for USERHERE* Please do not search for wars here, it is a support channel". I am thinking a variable needs to be created for the USERNAME the admin enters however not sure how to go about it in TCL.

Cheers once again.
b
blake
Master
Posts: 201
Joined: Mon Feb 23, 2009 9:42 am
Contact:

Post by blake »

Code: Select all

bind pub o|o !wars wars_proc

proc wars_proc { nick uhost hand chan arg } {
  putserv "PRIVMSG #clanbase.mw2  :Notice for $nick Please do not search for wars here, it is a support channel"
}
type !wars nickname that should work
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

Code: Select all

 bind pub -|- !wars pub:wars

 proc pub:wars {nick host hand chan text} {
  if {![string match [string tolower $chan] "#clanbase.mw2"]} {
   return 0
  }
  if {[llength $text] == 0} {
   puthelp "PRIVMSG $chan :\002Please do no search for wars here!\002 This is a Support Channel Only!"
  } else {
   set target [lindex [split $text] 0]
   puthelp "PRIVMSG $chan :\002$target\002 Please do not search for wars here! This is a Support Channel Only!"
  }
 }
$nick is equal to the person that issued the command, not the nickname given with the command. :idea: :arrow: the above code, allows for !wars and !wars nickname
S
Sbarkeri
Voice
Posts: 15
Joined: Tue Aug 11, 2009 12:01 am

Post by Sbarkeri »

TCL_no_TK just tried the script you posted now and it works like a charm! How can I edit to script to monitor 2 "host" channels and send different messages to 2 different "client" channels.

For example I will have the bot in the channels, #clanbase.crew.cod4 and #clanbase.crew.mw2 (these are both admin channels). I will also have the bot in #clanbase.cod4 and #clanbase.mw2 (these are general support channels). I want the admin to type !wars in the crew channel and the message to display in the support channels, however I want 2 different messages to display for each channel respectivly.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Have you tried/looked at the Putserv-O-Matic script?

Code: Select all

"!wars|#clanbase.crew.mw2|privmsg #clanbase.mw2 :\002Please do no search for wars here!\002 This is the first message in one channel!" 
"!wars|#clanbase.crew.cod4|privmsg #clanbase.cod4 :\002Please do no search for wars here!\002 This is a second message in a different channel!"
Construct "mycommads" for it like above. There are several ways to use this but there limits to how far this goes. This should help you get most of what you want going with minimal ease.
S
Sbarkeri
Voice
Posts: 15
Joined: Tue Aug 11, 2009 12:01 am

Post by Sbarkeri »

Yes I did try it out before my initial post on here, however I couldn't figure out how to make it change the chanel mode of the TARGET channel before it sent the message to it. I've been trying to edit the script by TCL_no_TK which works great to all my needs as I have added the channel flag changer myself, however I cannot work out how to make it monitor 2 channels for the same !xxxx command and supply 2 different responces based on which channel requested it, I have been playing around with the "elseif" to see if I could add in a line or two of code however my eggdrop crashes upon a rehash clearly telling me that my TCL isn't good.
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

Code: Select all

  if {![string match [string tolower $chan] "#clanbase.mw2"]} {
   return 0
  } 
Makes the script only work on #clanbase.mw2 I've used $chan which due to the code at the top would be #clanbase.mw2 so you can change

Code: Select all

   puthelp "PRIVMSG $chan :
to

Code: Select all

   puthelp "PRIVMSG #clanbase.cod4 :
to send one of the warnings to #clanbase.cod4
(so lets make it send the warning to #clanbase.cod4 if a nickname is given with the !wars command)
Example:

Code: Select all

 bind pub -|- !wars pub:wars

 proc pub:wars {nick host hand chan text} {
  if {![string match [string tolower $chan] "#clanbase.mw2"]} {
   return 0
  }
  if {[llength $text] == 0} {
   puthelp "PRIVMSG $chan :\002Please do no search for wars here!\002 This is a Support Channel Only!"
  } else {
   set target [lindex [split $text] 0]
   puthelp "PRIVMSG #clanbase.cod4 :\002$target\002 Please do not search for wars here! This is a Support Channel Only!"
  }
 }
This would still only work in #clanbase.mw2 but if someone wanted to warn a nickname (i.e uses !wars <nickname> it would warn them in #clanbase.cod4 and not in #clanbase.mw2 :)

As for the differant messages for differant channels, you could try editing the code to something like

Code: Select all

 bind pub -|- !wars pub:wars

 proc pub:wars {nick host hand chan text} {
  if {[string match [string tolower $chan] "#clanbase.mw2"]} {
   # This is the warning we use for #clanbase.mw2 when someone uses !wars or !wars <nickname>
   set msg "Please do not search for wars here! This is a support channel only!"
  } else {
   # This is the warning we use for ANY other channel than #clanbase.mw2 when someone uses !wars or !wars <nickname>
   set msg "Please visit are channel rules http://are.channel.ru/les.php!"
  }
  if {[llength $text] == 0} {
    puthelp "PRIVMSG $chan :\002$msg\002"
  } else {
   set target [lindex [split $text] 0]
   puthelp "PRIVMSG #clanbase.cod4 :\002$target\002 $msg"
  }
 }
Hopefully i explained it a little better for you to edit it and play around with the code a bit :D
Post Reply