Example of what this code does (visitant is the hub, leaftant and another_leaf are leafs):
1.4: Apparently if botnet-nick does not exist in your conf file, it is not set until after everything is sourced, so I've accounted for this in the startup portion of the botnet code now. Heh, it also seems I forgot to paste a line in here in startup too.(visitant, another_leaf, and leaftant are all in the same channel)
(10:32:18) <@incith> !layout http://incith.com
(10:32:18) <@visitant> URL: http://incith.com/ \\ TITLE: incith.com => main menu
(10:32:24) +|+ visitant has quit [Client Quit]
(10:32:33) <@incith> !layout http://incith.com
(10:32:35) <@another_leaf> URL: http://incith.com/ \\ TITLE: incith.com => main menu
(10:33:01) +|+ another_leaf has quit [Client Quit]
(10:33:03) <@incith> !layout http://incith.com
(10:33:05) <@leaftant> URL: http://incith.com/ \\ TITLE: incith.com => main menu
1.3: removed the 'unbind' else area. Oops.
1.2: Found some bugs in 1.1, cleaned it up. Putlogs being sent when they shouldn't be and bots being added to the static array unnecessarily. Whether you choose to bind disc or not I leave up to the authors.
In your scripts startup, add the below. This initializes an array to remember certain things going on. I use [clock seconds] in order to decide which bot is 'first'.
Code: Select all
namespace eval incith::layout {
variable botnet 1
variable debug 0
variable version {r79}
global botnet-nick nick
if {${botnet-nick} == ""} { set botnet-nick ${nick} }
array set static {}
if {${incith::layout::botnet} >= 1} {
set static(botnet,${botnet-nick},time) [clock seconds]
} else {
set static(botnet,${botnet-nick},time) "noswarm"
}
if {![info exists static(botnet,bots)]} {
set static(botnet,bots) ${botnet-nick}
}
}
Code: Select all
# bind the botnet binds
if {${incith::layout::botnet} >= 1} {
bind bot - incith:layout incith::layout::bot_msg
bind link - * incith::layout::bot_link
# it really depends what works better for you, checking if
# the bot is onchan or just making sure they are linked.
# bind disc - * incith::layout::bot_disc
}
Code: Select all
namespace eval incith::layout {
proc bot_msg {from cmd text} {
upvar #0 incith::layout::static static
if {${incith::layout::debug} >= 1} {
putlog "${incith::layout::version} (botmsg): <${from}> ${cmd} ${text}"
}
# receiving a bots load time
if {[string match "time ?*" $text]} {
regexp -- {time (.*)} $text - time
set static(botnet,${from},time) $time
# make sure this bot is in our bot list
if {![string match "*${from}*" $static(botnet,bots)]} {
putlog "${incith::layout::version} (botnet): ${from} has joined the incith:layout swarm."
append static(botnet,bots) ";${from}"
regsub -all -- {;;} $static(botnet,bots) {;} static(botnet,bots)
set static(botnet,bots) [string trimright $static(botnet,bots) {;}]
}
}
}
proc bot_link {bot hub} {
global botnet-nick
upvar #0 incith::layout::static static
# send our time to the bots
putallbots "incith:layout time $static(botnet,${botnet-nick},time)"
}
proc bot_disc {bot} {
upvar #0 incith::layout::static static
if {[string match "*${bot}*" $static(botnet,bots)]} {
if {$static(botnet,${bot},time) != "noswarm"} {
putlog "${incith::layout::version} (botnet): ${bot} has left the incith:layout swarm."
}
}
# remove this bot from our bot list. If they were merely unlinked
# then this code will make it all fail. They can be unlinked and still
# serve seperately since the time will be stored, and they'd have to
# leave the channel additionally before another bot takes over.
regsub -all -- $bot $static(botnet,bots) {} static(botnet,bots)
regsub -all -- {;;} $static(botnet,bots) {;} static(botnet,bots)
set static(botnet,bots) [string trimright $static(botnet,bots) {;}]
# remove their time? If they just lost link, they might still be [onchan]
# unset static(botnet,${bot},time)
}
}
Code: Select all
namespace eval incith::layout {
proc some_public_procedure {nick uhand hand chan input} {
global botnet-nick
upvar #0 incith::layout::static static
set input(where) $chan
# botnet
if {${incith::layout::botnet} >= 1 && $input(where) != "private"} {
foreach bot [split $static(botnet,bots) ";"] {
# skip ourselves, bots not on the input channel, and bots not participating
if {${bot} == ${botnet-nick} || ![onchan ${bot} $input(where)] || $static(botnet,${bot},time) == "noswarm"} {
continue
# bots that load first will serve first. change < to > to reverse.
} elseif {$static(botnet,${bot},time) < $static(botnet,${botnet-nick},time)} {
if {${incith::layout::debug} >= 1} {
putlog "${incith::layout::version} (botnet): $bot loaded before me."
}
return
# should 2 bots have the same time, set a new random time (this did happen in testing)
} elseif {$static(botnet,${bot},time) == $static(botnet,${botnet-nick},time)} {
if {${incith::layout::debug} >= 1} {
putlog "${incith::layout::version} (botnet): $bot had the same load time as me, fixing."
}
set static(botnet,${botnet-nick},time) [expr [clock seconds] + int(rand()*60)+1]
putallbots "incith:layout time $static(botnet,${botnet-nick},time)"
return
}
}
# looks like we're serving, make sure we keep the botnet up to date
putallbots "incith:layout time $static(botnet,${botnet-nick},time)"
}
}
}
Code: Select all
namespace eval incith::layout {
putallbots "incith:layout time $static(botnet,${botnet-nick},time)"
}