What is Tcl?
Binds
Procs
Varibles
Output Commands (messages, notices etc...)
Timers
Files (Reading, Writing, Modifying)
Strings
Arrays
Special Charachters
Formatting Text
Raw Events
If, Elseif, Else
Error Handling
What is Tcl?
Binds
The first thing you need to understand about Tcl scripting
is how to trigger an event. Events in Tcl generally are
triggered by binds.
There are many more but you get the idea of some of the
types of binds.
EVEN T - well this is where you tell the script what to look
for, e.g. what the actual trigger is (!food etc).
some examples:
Procs
Procs are where all the binds are routed and where much of
the programming as to what outcome an event will have takes
place.
commands/arguements etc...
The argument list for data being routed from a channel will
often look like: {nickname Userhost Handle Channel Rest} -
but this obviously depends on where the variables are being
routed from, as a proc does not necessarily have to have
any arguements
..........
..........
}
As you see above the arguments can be shortened and they
can even be renamed to anything you choose, but it always
is best to keep the same convention to make things easier
to follow e.g.
proc pub_hello {n u h c r} {
..........
..........
Varibles
unset country
$country
$name
$number
As you can see country and colour were set outside the proc
and where declared as global variables within the proc.
number was set within the proc and did not need any such
declaration.
incr $number
decr $number
incr $number 3
vers ion - The version of your eggdrop - the first item will
be the text format, the second the numerical format of the
version and any following items will be the names of
patches added ('1.6.17 1061700' & '1.6.11+channel_tcldocs
1061103 CVS 1021687856 channel_tcldocs')
serv er-onl ine - The unixtime value for when the bot
connected to its server
isju ped - Will return the value 1 if the bot has been
juped, 0 otherwise.
Please note that all config file variables are also global.
Output Commands
The first place you might was to output a command might be
to a channel. This can be achieved in various ways, most
achieving the same result. If i wanted to write "Good
Morning" to a channel called #egginfo I could use any of
the below:
For dcc binds those are the 3 arguments that are sent to a
proc. hand refers to handle, the nick you use on the bot.
This will of course only ping a user it will not return any
results to you. To do that you would have to use ctcr (CTCP
reply events) as below:
The above would send any ctcp ping reply sent to the bot to
a channel called #Botnet. expr is used to do any
calculation addition, subtraction, multiplication etc.
Above it would take the current unixtime and subtract it
from the time that was sent back with the ping reply (which
would be identical to the one you sent out when you first
pinged the user).
Timers
There are 2 timers that are available for use time r and
utim er . Timers are useful if you want the bot to have a
certain amount of delay before it continues to process a
command. Situations that timers are commonly used are
delaying voicing and/or opping users, or displaying certain
a text block in a channel after every x minutes.
timers
utimers
Will return a list of secondly set timers that have not
been executed yet.
Returns: List of timers in the format of "{seconds ProcName
TimerID}"
killtimer TimerID
killutimer TimerID
These will both remove a timer and/or utimer from the queue
to be executed.
alltool.tcl snippet
proc timerexists {command} {
foreach i [timers] {
return [lindex $i 2]
return
foreach i [utimers] {
return
timerexists ProcName
utimerexists ProcName
killtimer $var
break
# break stops the search, as the timer is found and there
is no need to continue.
Files
This will open the file for reading only, the file must
already exist. If you do not specify the permissions it
will be "r" as default.
Open the file for writing only. If the file doesn't exist,
create a new empty file. Set the initial access position to
the end of the file.
set x [open FileName r+]
Open the file for both reading and writing; the file must
already exist.
Open the file for reading and writing. If the file doesn't
exist, create a new empty file. Set the initial access
position to the end of the file.
Once you are done with a file you should remember to close
it again, rather then the bot accessing it continuously.
close $x
e.g.
You need to remeber to open the filename before you can put
any data into it. If the file has not been opened you will
get an error similar to "can not find channel named
"FileName.txt"".
Now lets put everything together:
set x [open mylogs.txt
puts $x "I love eggdrops"
close $x
gets $x [variable]
close $x
Strings
Strings are variables that consist of more then a single
element
set where {
Netherlands
England
Italy
Romania
Russia
}
Now say we want the 2nd country in the list we would use:
[lindex $where 1]
[lindex $where 4]
[lrange $where 3 4]
This would return the 1st five charachters i.e. "abc d".
The space is also counted in this instance.
Syntax:
With string you can use wildcards in the patter (* and ?),
you can also use the nocase option so when checking it pays
no attention to the case difference between the string and
pattern.
Returns 0
Returns 1
Returns 1
Returns 1
Syntax:
Syntax:
=====> abc
=====> abc!!!
=====> !!!abc
=====> !!!abc!!!
Special Charachters
[]
""
{}
- Line continuation
#
- A line beginning with a hash, in Tcl is considered a
comment and will not be processed by the script.
Formatting Text
BOLD
UNDERLINED
ITALIC
REVERSE
and in various....
COLOURS
Any format that you can achieve with your own irc client
can be achieved by an eggdrop.
The number 4 represents red and the \003 at the end tells
it to stop formatting the text in red.
o 1 ― black
o 2 ― darkblue
o 3 ― darkgreen
o 4 ― red
o 5 ― brown
o 6 ― magenta
o 7 ― orange
o 8 ― yellow
o 9 ― lightgreen
o 10 ― darkcyan
o 11 ― lightcyan
o 12 ― lightblue
o 13 ― pink
o 14 ― darkgrey
o 15 ― lightgrey
You only need to use \001 (required) to end the event and
not \001ACTION in this case. The above would give a result
on irc like so:
Associative Arrays
Now to get a list of colours you just set you could do the
following
This would simply return a list of all the colours you set
in the order you set them and you would get:
Red Teal Blue Pink Green Grey
Raw Events
etc...
} else {
$a != $b $a is not equal to $b
isbotnick <nick>
botisop [channel]
botisvoice [channel]
botonchan [channel]
isop <nickname> [channel]
wasop <nickname> <channel>
isvoice <nickname> [channel]
onchan <nickname> [channel]
if {[botisop $chan]} {
} else {
if {[botisop $chan]} {
} else {
Error Handling
When you create scripts you will undoubtedly run into some
teething problems when running them for the first time.
Often this can be because of missing braces { and }. Too
few closing braces and the eggdrop will crash. This can
usually be the most common reason for the bot to crash
after a new Tcl is loaded.