This is a simple zBot, made to work somewhat like the Unreal IRCD's Zbot.
It's made for those servers that doesnt have a module of that sort.
It's very simple to use.
To manage it, you need Operator (@) access in the channel.
Commands are:
!learn
!replace
!forget
!last (optional)
!append <description
? <- This one is the "search engine"
If you find any bugs, please tell me and ill try to fix em.
I havent really tested this in any greater way, but it should work.
Make sure you type !zbot activate (as an op) in your channel to activate it.
!zbot deactivate disabled it in the channel.
Updated the TEXT event of ?
; -----------------------------------------
; zBot script by Lindrian
; Do not modify anything below if you do not know what you are doing!
; -----------------------------------------
on *:start: {
var %x = $var(%zbot.table.*,0)
while (%x) {
var %r = $var(%zbot.table.*,%x).value
if (!$hget($gettok(%r,1-2,32))) .hmake $gettok(%r,1-2,46) 1000
if $exists(%r) { hload $gettok(%r,1-2,46) %r }
dec %x
}
unset %zbot.table.*
}
on *:unload: unset %zbot.*
on *:exit: {
var %x = $hget(0)
while (%x) {
tokenize 46 $hget(%x)
if (zbot* iswm $1) && ($2) {
var %tbl = $+(zbot,.,$2)
.hsave -o %tbl %tbl $+ .hsh
set $+(%,zbot,.,table,.,%tbl,.hsh) %tbl $+ .hsh
}
dec %X
}
}
on *:disconnect: {
var %x = $hget(0)
while (%x) {
tokenize 46 $hget(%x)
if (zbot* iswm $1) && ($2) {
var %tbl = $+(zbot,.,$2)
.hsave -o %tbl %tbl $+ .hsh
set $+(%,zbot,.,table,.,%tbl,.hsh) %tbl $+ .hsh
}
dec %X
}
}
alias zbot.add {
var %tbl = $+(zbot,.,$1)
if ($3) {
if (!$hfind(%tbl,$2,1,w)) {
hadd -m %tbl $2 $3-
return $b($2) $+ : $3-
}
else {
return $b($2) is already defined
}
}
else {
return Syntax: $b(!learn <key> <description>)
}
}
alias zbot.remove {
var %tbl = $+(zbot,.,$1)
if ($2) {
if ($hfind(%tbl,$2,1,w)) {
hdel -w %tbl $2
return $b($2) has been deleted
}
else {
return $b($2) is not defined
}
}
else {
return Syntax: $b(!forget <key>)
}
}
alias zbot.replace {
var %tbl = $+(zbot,.,$1)
if ($3) {
if ($hfind(%tbl,$2,1,w)) {
hdel -w %tbl $2
hadd -m %tbl $2 $3-
return $b($2) $+ : $3-
}
else {
return $b($2) is not defined
}
}
else {
return Syntax: $b(!replace <key> <description>)
}
}
alias zbot.append {
var %tbl = $+(zbot,.,$1)
if ($3) {
if ($hfind(%tbl,$2,1,w)) {
var %x = $hfetch($1,$v1)
var %t = $hget(%tbl,%x).data
hadd -m %tbl $2 %t $3-
return $b($2) $+ : %t $3-
}
}
}
alias zbot.last {
var %tbl = $+(zbot,.,$1)
if ($hget(%tbl,0).item == 0) return There is nothing defined
var %x = 1, %t = $iif($2,$2,25), %z, %y = $iif(%t > $hget(%tbl,0).item,$v2,$v1)
if (%t isnum 0-200) && (%x <= %t) {
while (%x <= %t) {
if ($hget(%tbl,%x).item) {
%z = %z $v1
}
inc %x
}
return Last $b(%y) entries: %z
}
else {
return Invalid number, $b($hget(%tbl,0).item) or below. Syntax: $b(!last <number>)
}
}
alias zbot.find {
var %tbl = $+(zbot,.,$1)
if ($2) {
if ($hfind(%tbl,$2,1,w)) {
var %x = $hfetch($1,$v1)
return $b($v1) $+ : $hget(%tbl,%x).data
}
else {
return $b($2) is not defined
}
}
else {
return Syntax: $b(?<key>)
}
}
alias hfetch {
var %tbl = $+(zbot,.,$1)
var %x = $hget(%tbl,0).item, %i = $2
while (%x) {
if ($hget(%tbl,%x).item == %i) {
return %x
}
dec %x
}
}
alias -l b return $+(,$1-,)
on *:TEXT:!zbot *:#: {
if ($nick isop $chan) {
if ($2 == activate) {
if (!$istok(%zbot.chan,$chan,32)) {
msg $chan zBot has been activated for $b($chan) $+ .
set %zbot.chan %zbot.chan $chan
}
else {
msg $chan zBot is already activated for $b($chan) $+ .
}
}
elseif ($2 == deactivate) {
if ($istok(%zbot.chan,$chan,32)) {
msg $chan zBot for $b($chan) has been deactivated.
set %zbot.chan $deltok(%zbot.chan,$findtok(%zbot.chan,$chan,1,32),32)
}
else {
msg $chan zBot for $b($chan) is not activated.
}
}
}
else {
.notice $nick You must be an operator or above to use this command
}
}
on *:TEXT:!*:#: {
if ($istok(%zbot.chan,$chan,32)) {
if ($1 == !learn) msg $chan $zbot.add($chan,$2,$3-)
elseif ($1 == !forget) msg $chan $zbot.remove($chan,$2)
elseif ($1 == !append) msg $chan $zbot.append($chan,$2,$3-)
elseif ($1 == !replace) msg $chan $zbot.replace($chan,$2,$3-)
elseif ($1 == !last) msg $chan $zbot.last($chan,$2)
elseif ($1 == !commands) {
.notice $nick The commands are: !learn <key> <description>, !replace <key> <description>, !forget <key>, !last <number> (optional),!append <key> <description>, ? <key>
}
}
}
on *:TEXT:? *:#: {
if ($istok(%zbot.chan,$chan,32)) && ($1 == $chr(63)) {
msg $chan $zbot.find($chan,$2)
}
}
; -----------------------------------------
; End of file
; -----------------------------------------