alias kquote {
;Set what database to use, if not the default.
var %db = quote. $+ $iif($prop,$prop,default), %dbfile = $^qt($scriptdir $+ %db $+ .dat)
if (!$hget(%db)) {
hmake %db 100
if ($isfile(%dbfile)) {
hload -b %db %dbfile
}
else {
write -c %dbfile
}
}
;Check if its an identifier.
if ($isid) {
;Check if $1 is 'add'
if ($1 == add) {
;make sure all parameters are given
if (($3 == $null) || ($numtok($2,32) > 1) || ($2 == $null)) {
return $false
}
;set key variables, such as the author, ID of the quote, etc.
var %author = $2, %quote = $3-, %id = $calc($hget(%db,0).item + 1), %verify = $hget(%db,%id), %addtime = $ctime, %deleted = $false
;make sure we don't over write a quote
while (%verify) {
var %id = $calc(%id + 1), %verify = $hget(%db,%id)
}
; add the quote
hadd %db %id %addtime %deleted %author %quote
hsave -b %db %dbfile
; check if it was added
if ($hget(%db,%id) == %addtime %deleted %author %quote) {
;return the quote ID, and $true
return $true %id
}
else {
;i'm not sure how this will happen, but its good to have 'just in case'
return $false unexpected_error
}
}
elseif ($1 == get) {
;Find out if there are any quotes in the database or not.
if ($hget(%db,0).item == 0) {
return $false empty
}
; Get the quote, and check if it exists, is deleted, etc.
var %quote = $iif($2 != $null,$2,$rand(1,$hget(%db,0).item)), %gquote = $hget(%db,%quote), %del = $gettok(%gquote,2,32)
if (%gquote == $null) {
return $false non-existant %quote
}
elseif (%del) {
; Quote has been deleted
return $false deleted %quote
}
else {
; Return the quote #, quote, author and creation time.
return $true %quote $gettok(%gquote,1,32) $gettok(%gquote,3-,32)
}
}
elseif ($1 == del) {
; Check if all parameters are given
if ($2 == $null) {
return $false
}
; check if there are quotes in the database
if ($hget(%db,0).item == 0) {
;return empty since there are no quotes in the database.
return $false empty $2
}
; Check if the quote exists
var %quote = $2, %gquote = $hget(%db,%quote)
if (%gquote == $null) {
;if the quote dosen't exist, return false
return $false non-existant %quote
}
elseif ($gettok(%gquote,2,32) == $true) {
;check if its already deleted
return $false already-deleted %quote
}
else {
;delete the quote...
hadd %db %quote $gettok(%gquote,1,32) $true $gettok(%gquote,3-,32)
;return sucessfull
return $true %quote
}
}
elseif ($1 == version) {
return $!kquote $+(v,$qver) by Kardafol @ Gamesurge [#Kardafol]
}
}
}
alias -l qver {
return 0.4
}
alias -l ^qt {
return $iif("*" iswm $$1-,$1-,$iif("* iswm $1-,$+($1-,"),$iif(*" iswm $1-,$+(",$1-),$+(",$1-,"))))
}