egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Complete Newbie - Needing Basic Script With Basic Triggers
Goto page Previous  1, 2
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Thu Jul 24, 2008 9:40 pm    Post subject: Reply with quote

Code:
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 [list] you also have removed the [split]. This should be done in either case with or without [list]. ;D

So simply changing
Code:
   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 [list]. Because there is implied use during the foreach, and without the [split] the code will behave the same with or without the use of [list]. 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:
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
      }
   }
}
Quote:
<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

_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
Lanh
Voice


Joined: 04 Jul 2008
Posts: 6

PostPosted: Thu Jul 24, 2008 10:51 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Fri Jul 25, 2008 12:05 am    Post subject: Reply with quote

Code:
# 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."
Quote:
<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:
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 Razz"
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
_________________
speechles' eggdrop tcl archive


Last edited by speechles on Tue Jan 05, 2010 8:32 pm; edited 18 times in total
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Fri Jul 25, 2008 8:05 am    Post subject: Reply with quote

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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Lanh
Voice


Joined: 04 Jul 2008
Posts: 6

PostPosted: Sat Aug 02, 2008 11:17 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sun Aug 03, 2008 10:03 am    Post subject: Reply with quote

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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Repdientu
Voice


Joined: 30 Apr 2009
Posts: 33
Location: Viet Nam

PostPosted: Wed Jul 29, 2009 1:50 am    Post subject: Reply with quote

Hi Speechles
Code:
# 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 ?
Back to top
View user's profile Send private message Visit poster's website
Daedalus
Voice


Joined: 27 Jun 2007
Posts: 24

PostPosted: Wed Jul 29, 2009 6:13 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber