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.
L
Lanh
Voice
Posts: 6
Joined: Fri Jul 04, 2008 1:55 am

Complete Newbie - Needing Basic Script With Basic Triggers

Post by Lanh »

Hi,

I am a complete newbie to all this kind of thing having previously run triggers from my copy of X-Chat, I have recently upgraded to an eggdrop bot and would like to run the triggers from there.

At the moment our triggers are in the format of:-

!trigger|#room|notice %n message

Basically the person wanting the information types "!trigger" in the room and they receive a notice back with the information they want.

There are around 50 of these triggers, but all I need to get me started converting them from is an example of 1. It is a very, very basic script that I am looking for, I just don't know where to begin.

There are no permissions complications, they should be available to everyone and the bot should respond whether it is a user, half-op or op in the room that it is in.

Is something like this possible? Could someone tell me where to look to learn how to create such a script? Is someone able to post an example which I could then expand upon for all the commands?

Any help at all would be appreciated as I have reached a place where I am now completely lost!

Also, could someone let me know if when the script is uploaded if it is updated to others in real time or if the eggdrop would need to be rehashed/restarted before it would show the updated information?

Thank you for reading,

Lanh
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

First you need to learn the [bind] command. Read about it in Tcl-commands.doc.
bind <type> <flags> <keyword/mask> [proc-name]
Description: You can use the 'bind' command to attach Tcl procedures
to certain events. flags are the flags the user must have to trigger
the event (if applicable). proc-name is the name of the Tcl procedure
to call for this command (see below for the format of the procedure
call). If the proc-name is omitted, no binding is added. Instead, the
current binding is returned (if it's stackable, a list of the current
bindings is returned).
Returns: name of the command that was added, or (if proc-name was
omitted), a list of the current bindings for this command
You need to bind to pub, the pub bind is also explained in Tcl-commands.doc.
PUB
bind pub <flags> <command> <proc>
procname <nick> <user@host> <handle> <channel> <text>

Description: used for commands given on a channel. The first word
becomes the command and everything else is the text argument.
So basically, you want something like this:

Code: Select all

# a pub bind that calls pub:trigger procedure
# whenever ANYONE (notice the '-') types !trigger in a channel
bind pub - !trigger pub:trigger

proc pub:trigger {nick uhost hand chan arg} {
 # $nick is the nickname of the use who wrote !trigger
 # $uhost is user@host of $nick
 # $hand is the handle of $nick (on the bot)
 # $chan is the channel-name in which the trigger was sent
 # $arg contains all text after !trigger (it's a string)
}
When you update a script, you need to at least .rehash your Eggdrop for the changes to be committed.
L
Lanh
Voice
Posts: 6
Joined: Fri Jul 04, 2008 1:55 am

Post by Lanh »

Having read the documentation and tried to play with the script for the past 3 hours to make it respond to me in the room, sadly, I am no wiser.

I've been completely unable to get the script to respond to me in any way either in the channel, in a notice or in a private message.

Is there a tutorial anywhere which can guide someone with absolutely no tcl experience at all through the different steps needed to create what I presumed (based on the xchat trigger script that I had been using) would be a very simple script like what I am trying to achieve?

It really needs to begin at the very beginning and to preferably include examples.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Did you read about the [puthelp], [putserv], and [putquick] commands? You can also check other scripts and learn from them.
L
Lanh
Voice
Posts: 6
Joined: Fri Jul 04, 2008 1:55 am

Post by Lanh »

Yep and attempted to use them. No luck, like I said I am flying completely blind here, complete and utter novice.

I mistakenly thought that it would be as easy as creating and maintaining the triggers like manually in x-chat through "uberscript" which is a level I almost understand, (editing txt files with a list of triggers in them).

I spent some time before I logged in here originally going through some of the scripts here and on other sites, I tried manipulating them and everything I tried in terms of modification either caused the bot to refuse to rehash (error in the script) or simply just didn't respond.

I'll keep looking I guess, if I have no luck by the end of the month, I'll just have to pay someone to set it up for me! :lol:
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

You can get more help if you just show us what you've written so far.
p
pitbull
Voice
Posts: 13
Joined: Sun Aug 12, 2007 12:12 pm

Post by pitbull »

Why not help the guy out a little... Rather than read for hours and still be lost, give him a simple example.

bind pub - !notice pub_sendmeanotice

proc pub_sendmeanotice {nick uhost handle chan args} {
putserv "NOTICE $nick :This is a notice!"
}

bind pubm - !yellatme pub_yellatme

proc pub_yellatme {nick uhost handle chan} {
putserv "NOTICE $nick :WHY WOULD YOU WANT ME TO DO THAT?"
}

Hope this inspires you to learn more, not give up because of over complicated manuals.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

@pitbull

Code: Select all

bind pub - !notice pub_sendmeanotice

proc pub_sendmeanotice {nick uhost handle chan args} { 
You have used the 'special token' args in this. This will lead to problems for other users taking your advice. Use Arg or Text in this case, not args.

Code: Select all

bind pubm - !yellatme pub_yellatme

proc pub_yellatme {nick uhost handle chan} {
This is incorrect, a public message bind needs 5 parameters: nick, uhost, handle, chan, and text. If you meant msgm, then change 'chan' into 'text' as private messages to the bot are not passed a channel parameter.

In all of this it is safe to say, reading doesn't hurt at all. Perhaps reading manuals is something you should do as well. Reading is like power. You are giving up power in failing to read. A good place to start reading is Here. Specifically the bottom part dealing with args.
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)

# 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 two variables to use
# %n - will be replaced with $nick
# %c - will be replaced with $chan
variable mycommands {
  "!trigger1|#room|notice %n :message"
  "!trigger2|#room|privmsg %c :message"
}

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

proc mycommands_proc {nick uhand hand chan input} {
	foreach item $::mycommands {
		if {[string match -nocase [lindex [split $item \|] 0] [lindex [split $input] 0]]} {
			if {[string match -nocase [lindex [split $item \|] 1] $chan]} {
				set message [join [lrange [split $item \|] 2 end]]
				resub -all -nocase {%n} $message $nick message
				resub -all -nocase {%c} $message $chan message
				putserv "$message"
			}
		}
	}
}

putlog "Multi-bind messaging script loaded."
This should accomplish what you desire with minimum hassle. It will allow you to use the lists you already have basically. You will need to add a space and colon into your messages like so: "notice %n :message" or "notice %c :message". This does it without having hundreds of procedures. You are allowed to use wildcards in mycommands. So an entry of "!help|*|notice %n :There is no help for %c. %n, you are silly." is totally valid. It will allow use in ANY channel, because of the * (wildcard) in the channel field. This is how you should script things of this nature rather than building tons of stand-alone procedures. You can also have multiple messages as well, just repeat the same !trigger|#channel with the next message you want displayed.

Edit: try #2, game on.
Edit: try #3, game is better. game has finesse.
Last edited by speechles on Thu Jul 24, 2008 9:45 pm, edited 4 times in total.
L
Lanh
Voice
Posts: 6
Joined: Fri Jul 04, 2008 1:55 am

Post by Lanh »

Thanks guys, I appreciate the encouragement, I have had limited success.

I have spent a lot of time trying to learn by altering existing scripts, which is the same way that I learned html, and it's slow going, I am cross referencing everything in the manuals and using google, I got a few books from the library regarding IRC that I am also making my way through, so I haven't given up, lol, I will learn this stuff if it kills me.

Speechles, thank you for the example, it's appreciated, it throws up the following error, it's very similar to what I have seen before in my testing, I have not yet been able to fix it. The error is below...

Code: Select all

[00:48] missing close-brace
    while executing
"proc mycommands_proc {nick uhand hand chan input} {
   foreach item [split $::mycommands] {
      if {[string match -nocase [lindex [split $item \|]..."
    (file "scripts/triggers.tcl" line 20)
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

For some reason, speechles forgot to close the open-brace right before opening a new one.

Code: Select all

if {[string match -nocase [lindex [split $item \|] 0] [lindex [split $input] 0]] {
 if {[string match -nocase [lindex [split $item \|] 1] $chan] {
Add a close-brace (}) before the open-brace ({) at the end of each line in the code snippet above.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Sir_Fz wrote:For some reason, speechles forgot to close the open-brace right before opening a new one.
Most of that I wrote directly into the reply box and it's sorta, well not sorta, it's very very tiny and word wraps everything..lol :roll: It's almost like notepad but in an extremely crippled way. Next time I'll just whip out notepad and do it. I've had this happen before trying to write code directly into the snippet box.. lmao. It's too easy to overlook something because of the tiny box and word wrap. :lol:

Btw, I fixed the code above at least the problematic line. ;D
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I'm afraid that code will not quite work as intended, as the quotes will end up within the list items, rather than encapsulating them...

I would recommend storing the triggers in a proper list structure within ::mycommands from the beginning...

Code: Select all

...
variable mycommands [list \
  "!trigger1|#room|notice %n :message" \
  "!trigger2|#room|privmsg %c :message" \
]

...

   foreach item $::mycommands {
...

Also... there's no command called resub. Maybe regsub?
NML_375
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

nml375 wrote:I'm afraid that code will not quite work as intended, as the quotes will end up within the list items, rather than encapsulating them...

I would recommend storing the triggers in a proper list structure within ::mycommands from the beginning...

Code: Select all

...
variable mycommands [list \
  "!trigger1|#room|notice %n :message" \
  "!trigger2|#room|privmsg %c :message" \
]

...

   foreach item $::mycommands {
...

It does work as intended (albeit with the full understanding special tcl characters will of course need escaping or else will toss tcl errors), because the unofficial google scripts uses something exactly similar to do vocabulary aversion (swear word replacement). But it is better, agreed, to keep it as a list to begin with (this way there is nothing to understand, the list arrangement guarantees escaping and no tcl errors).
nml375 wrote:Also... there's no command called resub. Maybe regsub?
It could be a command I forgot a procedure.

Code: Select all

proc resub {args} {
  set condtion [eval regsub $args]
  return condition
}
lmao.. that is probably sadly incorrect, but yeah. I forgot the g there, regsub, was sposta substitute text.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

speechles wrote:
nml375 wrote:I'm afraid that code will not quite work as intended, as the quotes will end up within the list items, rather than encapsulating them...

I would recommend storing the triggers in a proper list structure within ::mycommands from the beginning...

Code: Select all

variable mycommands [list \
  "!trigger1|#room|notice %n :message" \
  "!trigger2|#room|privmsg %c :message" \
]

...

   foreach item $::mycommands {
...

It does work as intended (albeit with the full understanding special tcl characters will of course need escaping or else will toss tcl errors), because the unofficial google scripts uses something exactly similar to do vocabulary aversion (swear word replacement). But it is better, agreed, to keep it as a list to begin with (this way there is nothing to understand, the list arrangement guarantees escaping and no tcl errors).
...
I beg to differ, as I even verified the flaw in a native tcl shell..

Code: Select all

variable mycommands {
  "!trigger1|#room|notice %n :message"
  "!trigger2|#room|privmsg %c :message"
}

foreach item [split $::mycommands] {
  puts stdout [split $item \|]
}

#Output starts here:

{"!trigger1} #room notice
%n
:message"


{"!trigger2} #room privmsg
%c
:message"

As you can see, there are several empty lines, representing empty list items, and the trigger has a leading ", while the message has a trailing one.

If you do not specify a specific separator, split will use any and all whitespace characters, including newlines, spaces, and tabs. Also, it will not care for "long lines" grouping. Using newline as separator will neither solve the issue, as "" would still not be removed (of course, if mycommands is altered to not include those quotes, things would look better).
NML_375
Post Reply