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.

Complete Newbie - Needing Basic Script With Basic Triggers

Help for those learning Tcl or writing their own scripts.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

foreach item $::mycommands {
  puts stdout [split $item \|]
}
In doing it this way, it is assumed we have a list. If we have a list, this works great. If we don't have a list, this can also work great (you just need to do it wisely). Now if we add [split] to either of these, it will actually cause the behavior we are seeing. Adding list doesn't correct it either, because when you added the
  • you also have removed the [split]. This should be done in either case with or without
    • . ;D

      So simply changing

      Code: Select all

         foreach item [split $::mycommands] { 
      and removing the [split] present would function the same way as actually, erm, having a list. Since the same rules apply regarding escaped special characters and list field element restrictions, even without the use of
      • . Because there is implied use during the foreach, and without the [split] the code will behave the same with or without the use of
        • . Try it yourself. Now using list, and avoiding split like the plague might be perferable, but then it might confuse things with the newlines injected, etc. That is why I chose to keep it a string, up until the point the foreach attempts to make use of it.

          Code: Select all

          variable mycommands {
            "!trigger1|#channel|privmsg %c :message"
            "!trigger2|#channel|privmsg %c :message"
            "!trigger3|#channel|privmsg %c :message"
            "!trigger4|#channel|anything etc can go here you can send to a server, a mode, a kick, etc"
          }
          
          # Script begins - change nothing below here
          bind pub -|- "!test" mycommands_proc
          
          proc mycommands_proc {nick uhand hand chan input} {
             set lne 0
             foreach item $::mycommands {
                incr lne
                set ldx -1
                while {$ldx < 2} {
                   incr ldx 1
                   set message "privmsg $chan :index 0=[lindex [split $item \|] 0] index 1=[lindex [split $item \|] 1] range 2-end=[join [lrange [split $item \|] 2 end]]"
                   regsub -all -nocase {%n} $message $nick message
                   regsub -all -nocase {%c} $message $chan message
                   putserv $message
                }
             }
          }
          <bot> index 0=!trigger1 index 1=#channel lrange 2-end=privmsg #test :message
          <bot> index 0=!trigger2 index 1=#channel range 2-end=privmsg #test :message
          <bot> index 0=!trigger3 index 1=#channel range 2-end=privmsg #test :message
          <bot> index 0=!trigger4 index 1=#channel range 2-end=anything etc can go here you can send to a server, a mode, a kick, etc
L
Lanh
Voice
Posts: 6
Joined: Fri Jul 04, 2008 1:55 am

Post by Lanh »

Hi,

Am I right in thinking that the section I have bolded was the change?
speechles wrote:proc mycommands_proc {nick uhand hand chan input} {
foreach item $::mycommands {
if {[string match -nocase [lindex [split $item \|] 0] [lindex [split $input] 0]]} {
Just trying to understand the scripting.

The script loads but it is unresponsive in the channel, I am going to try a few things and I'll come back and let you know if I can get it working, hopefully I can make it work correctly without requesting further assistance.

The other discussion in here, is way beyond my comprehension at the moment, but I will revisit that when I become more familiar with this whole thing.

I really appreciate the time everyone is taking to monitor and participate in this thread, things are slowly making more sense to me.

Thank you.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

# Multi-Bind Messaging (the easy way to do this)
# AKA, PutServ-O-Matic v1.0
# by speechles (w/help from egghelp! yay!)

# Construct your triggers|channel|message
# here using the format below:
# "TRIGGER|#CHANNEL|METHOD AND MESSAGE"
# add as little, or as many as you want but you
# MUST use the format described above!
# You also have a few variables to use
# %b - will be replaced with $::botnick (bots current nickname)
# %n - will be replaced with $nick (person triggering)
# %c - will be replaced with $chan (channel triggered in)
# %u - will be replaced with $uhost (person triggering unique host)
# %h - will be replaced with $hand (person triggering handle)
# %t - will be replaced with users trigger (very first word)
# %i - will be replaced with user $input (entire thing)
# %i1 - will be replaced with user $input (just the first word)
# %i2 - will be replaced with user $input (second to last words)
# below are merely some examples.
variable mycommands {
  "*slaps %b*|#test|privmsg %c :\001action blocks the slap and kicks %n in the face.\001"
  "!notice*|#test|notice %n :notice message"
  "!query*|#test|privmsg %n :query/private message"
  "!kickme*|#test|kick %c %n :kick fulfilled.. hehe \037:P\037"
  "!voiceme*|*|mode %c +v %n"
  "!voiceme*|*|privmsg %c :\002%n\002, feel the \002Power\002 of voice!"
  "!repeat*|*|privmsg %c :%n just said \002%i\002 :P"
  "!voicenick*|*|mode %c +v %i1"
  "!kickbannick*|*|mode %c +b %i1!*@*"
  "!kickbannick*|*|kick %c %i1 :%i2 (Requested by %n)"
  "!kicknick*|*|kick %c %i1 :%i2 (Requested by %n)"
}

# Script begins - change nothing below here
bind pubm -|- "*" mycommands_proc

proc mycommands_proc {nick uhand hand chan input} {
   foreach item $::mycommands {
      set trig [lindex [split $item \|] 0]
      regsub -all -nocase {%b} $trig $::botnick trig
      regsub -all -nocase {%n} $trig $nick trig
      regsub -all -nocase {%c} $trig $chan trig
      regsub -all -nocase {%u} $trig $uhand trig
      regsub -all -nocase {%h} $trig $hand trig
      regsub -all -nocase {%t} $trig [lindex [split $input] 0] trig
      regsub -all -nocase {%i1} $trig [lindex [split $input] 1] trig
      regsub -all -nocase {%i2} $trig [join [lrange [split $input] 2 end]]] trig
      regsub -all -nocase {%i} $trig [join [lrange [split $input] 1 end]]] trig
      if {[string match -nocase $trig $input]} {
         if {[string match -nocase [lindex [split $item \|] 1] $chan]} {
            set message [join [lrange [split $item \|] 2 end]]
            regsub -all -nocase {%b} $message $::botnick message
            regsub -all -nocase {%n} $message $nick message
            regsub -all -nocase {%c} $message $chan message
            regsub -all -nocase {%u} $message $uhand message
            regsub -all -nocase {%h} $message $hand message
            regsub -all -nocase {%t} $message [lindex [split $input] 0] message
            regsub -all -nocase {%i1} $message [lindex [split $input] 1] message
            regsub -all -nocase {%i2} $message [join [lrange [split $input] 2 end]]] message
            regsub -all -nocase {%i} $message [join [lrange [split $input] 1 end]]] message
            putserv "$message"
         }
      }
   }
}

putlog "Multi-bind messaging with action missles script loaded."
<speechles> !voiceme
* bot sets mode: +v speechles
<bot> speechles, feel the Power of voice!
<speechles> !kickme
you were kicked by bot (kick fulfilled.. hehe :P)
<funny> haha.. your own bot kicks you :P
<speechles> !kick funny haha.. not so funny now is it?
funny was kicked by bot (haha.. not so funny now is it? (Requested by speechles))
**EDIT: The code above requires knowledge of tcl special characters and proper list arrangements.

Code: Select all

variable mycommands [list "!notice|#test|notice %n :notice message" \
  "!query|#test|privmsg %c :query/private message" \
  "!kickme|#test|kick %c %n :kick fulfilled.. hehe \037:P\037" \
  "!voiceme|*|mode %c +v %n" \
  "!voiceme|*|privmsg %c :\002%n\002, feel the \002Power\002 of voice!" \
  "!repeat|*|privmsg %c :you just said \002%i\002" \
  "!voicenick|*|mode %c +v %i1" \
  "!kickbannick|*|mode %c +b %i1*!*@*" \
  "!kickbannick|*|kick %c %i1 :%i2 (Requested by %n)" \
  "!kicknick|*|kick %c %i1 :%i2 (Requested by %n)" ] 
This is the correct way to encapsulate the list, without crafting it by hand. Those having issues of any sort should use the correct way (the list method above). Those more experienced can of course, craft the list by hand just fine (it's original state).

Mycommands Configuration: (for those new to tcl this should explain it)
"*slaps %b*|#test|privmsg %c :\001action blocks the slap and kicks %n in the face.\001"
If anyone slaps the bot, it will block the slap and kick them in the face.

"!notice|#test|notice %n :notice message"
obvious, it will notice the nickname 'notice message'

"!query|#test|privmsg %n :query/private message"
another obvious one, will query the nickname 'query/private message'

"!kickme|#test|kick %c %n :kick fulfilled.. hehe \037:P\037"
kinda obvious. kicks the person requesting a kick.

"!voiceme|*|mode %c +v %n"
voices you if you ever cared to be voiced.

"!voiceme|*|privmsg %c :\002%n\002, feel the \002Power\002 of voice!"
this is to show a 2nd handler for a trigger, this will be carried out after the one above it. Basically telling you voice has power or smish..

"!repeat|*|privmsg %c :%n just said \002%i\002 :P"
basically mirrors whatever you type, to show the variable %i is entire input.

"!voicenick|*|mode %c +v %i1"
this is to show the power of %i1 the first word of input. Voices a nickname u put.

"!kickbannick|*|mode %c +b %i1!*@*"
This is to show the power of %n and %i1/%i2 combined. First the mode to ban them is set, using their nickname.

"!kickbannick|*|kick %c %i1 :%i2 (Requested by %n)"
Now we kick them down here with our message. And for courtesy, the bot is merely the messenger so attched the requested by nickname message.

"!kicknick|*|kick %c %i1 :%i2 (Requested by %n)"
This was to mirror the kick command above but because it's tied to ban, we need a new name so just the kick part will occur.

Hope this explains most of how to 'script' the mycommands section. Basically, _anything_ you can have putserv'd can be your message, all of the variables can be used on either
Last edited by speechles on Tue Jan 05, 2010 8:32 pm, edited 18 times in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Removing the split of mycommands, as suggested, does improve the behavior of the script. However, given the nature of this forum and the vast range of knowledge (from "what's tcl" to "expert programmer"), it would be advisable to post code that is "theoretically correct"; that is, make no assumptions that whoever is going to use the script has any knowledge 'bout advanced list structures or other. Using the list command provides a valid list, no matter of the input (each argument becomes a separate list item), whereas crafting list structures by hand requires a lot of experience.

Many new coders will search these threads and use code-snippets as learning examples, and in my opinion, it is far better to use proper coding rather than advanced "hacks". I am not questioning your ability to create proper list structures by hand, I'm just saying that you can't expect anyone reading this example to be able to accomplish the same.
NML_375
L
Lanh
Voice
Posts: 6
Joined: Fri Jul 04, 2008 1:55 am

Post by Lanh »

I just want to say thank you to everybody who has contributed to this thread, your help and encouragement has been hugely appreciated and has been invaluable.

I have been able to not only get the triggers that I would like but also to use a number of other scripts, modify them for our use in our channel which will make things a lot easier in the long run.

Thank you everybody.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Nice to hear of your progress. If you get stuck on anything, don't hesitate to ask, and we'll gladly do our best to help.
NML_375
R
Repdientu
Voice
Posts: 37
Joined: Thu Apr 30, 2009 3:45 am
Location: Viet Nam
Contact:

Post by Repdientu »

Hi Speechles

Code: Select all

# Multi-Bind Messaging (the easy way to do this)
# AKA, PutServ-O-Matic v1.0
# by speechles (w/help from egghelp! yay!)

# Construct your triggers|channel|message
# here using the format below:
# "TRIGGER|#CHANNEL|METHOD AND MESSAGE"
# add as little, or as many as you want but you
# MUST use the format described above!
# You also have a few variables to use
# %b - will be replaced with $::botnick (bots current nickname)
# %n - will be replaced with $nick (person triggering)
# %c - will be replaced with $chan (channel triggered in)
# %u - will be replaced with $uhost (person triggering unique host)
# %h - will be replaced with $hand (person triggering handle)
# %i - will be replaced with user $input (entire thing)
# %i1 - will be replaced with user $input (just the first word)
# %i2 - will be replaced with user $input (second to last words)
# below are merely some examples.
variable mycommands {
  "*slaps %b*|#test|privmsg %c :\001action blocks the slap and kicks %n in the face.\001"
  "!notice*|#test|notice %n :notice message"
  "!query*|#test|privmsg %n :query/private message"
  "!kickme*|#test|kick %c %n :kick fulfilled.. hehe \037:P\037"
  "!voiceme*|*|mode %c +v %n"
  "!voiceme*|*|privmsg %c :\002%n\002, feel the \002Power\002 of voice!"
  "!repeat*|*|privmsg %c :%n just said \002%i\002 :P"
  "!voicenick*|*|mode %c +v %i1"
  "!kickbannick*|*|mode %c +b %i1!*@*"
  "!kickbannick*|*|kick %c %i1 :%i2 (Requested by %n)"
  "!kicknick*|*|kick %c %i1 :%i2 (Requested by %n)"
}

# Script begins - change nothing below here
bind pubm -|- "*" mycommands_proc

proc mycommands_proc {nick uhand hand chan input} {
   foreach item $::mycommands {
      set trig [lindex [split $item \|] 0]
      regsub -all -nocase {%b} $trig $::botnick trig
      if {[string match -nocase $trig $input]} {
         if {[string match -nocase [lindex [split $item \|] 1] $chan]} {
            set message [join [lrange [split $item \|] 2 end]]
            regsub -all -nocase {%b} $message $::botnick message
            regsub -all -nocase {%n} $message $nick message
            regsub -all -nocase {%c} $message $chan message
            regsub -all -nocase {%u} $message $uhand message
            regsub -all -nocase {%h} $message $hand message
            regsub -all -nocase {%i1} $message [lindex [split $input] 1] message
            regsub -all -nocase {%i2} $message [join [lrange [split $input] 2 end]]] message
            regsub -all -nocase {%i} $message [join [lrange [split $input] 1 end]]] message
            putserv "$message"
         }
      }
   }
}

putlog "Multi-bind messaging with action missles script loaded."

can i used file /data/command.txt for variable mycommands ?
and can add some command via: !addcmd !mode*|#myroom|mode %c %i1 to command.txt ?
D
Daedalus
Voice
Posts: 24
Joined: Wed Jun 27, 2007 7:12 pm

Post by Daedalus »

I have a question.

How would I make this work with actions? Currently, it does not.

Basically, I'm making a "character" bot, that replies to some simple, specific stimulus in channel that relates to some very random things she says at random intervals. So if she says

"How do I get these rhinoes into the jar?"

a user might say

"There are no rhinoes!"

to which she would say

"sadface:("

...so basically it's a REALLY simple way of doing "AI" with less chance of having really stupid responses that are out of context.

Now, the "character" likes having her tummy tickled. But people can't do that, because she doesn't understand

/me tickles the bot's tummy

...any ideas?

I could just write action procs, but this would defeat the object of this script.
Post Reply