Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alias rsearch {
- var %x = 0
- ;--------------iterate through quotes table
- while (%x <= $hget(quotes,0).item) {
- ;--------------set string data(the quote text);;;;;;;;;;
- var %string = $hget(quotes,%x).data
- ;--------------perform a regular expression match on the search parameters
- if ($regex(%string, /(.* $+ %search $+ .*)/i)) {
- ;--------------found a match, add it to the results table
- hadd -m results $hget(quotes,%x).item $hget(quotes,%x).data
- ;--------------set quote number and it's item referral
- var %qnumber %qnumber $+($chr(35),$hget(quotes,%x).item,=,%x)
- inc %x
- }
- inc %x
- }
- var %results = 1
- ;--------------iterate through the results table
- while (%results <= $hget(results,0).item) {
- ;--------------set quote number with the # sign for the return values
- set -u3 %quotes %quotes $chr(35) $+ $hget(results, %results).item
- inc %results
- }
- ;--------------sets a random number between 1 and $numtok(%qnumber,32), this variable determines the quote number displayed
- var %rquote = $rand(1,$numtok(%qnumber,32))
- ;--------------this is the item number of the quote in the table
- var %item.no = $gettok($gettok(%qnumber,%rquote,32),2,61)
- ;--------------this is the quote number of the quote in the table
- var %quote.no = $remove($gettok($gettok(%qnumber,%rquote,32),1,61),$chr(35))
- ;--------------this is the quote text
- var %quote = $hget(quotes,%item.no).data
- ;--------------!%find represents the !randquote command used to trigger this script.
- if (!%find) {
- ;--------------found matches for our search parameters...
- if (%quote != $null) {
- ;--------------Display the number of matches found for the search parameters...
- msg $chan 09Found1107 $hget(results,0).item 09entries.
- ;--------------Display the quote details.
- msg $chan 09Quote Number11:04 %quote.no 09Quote11: $replace($gettok(%quote,1,191),%search,09 $+ %search $+ ) $&
- 14-09 $gettok($gettok($read(quotes.txt,%quote.no),2,191),1,58) $+ 11: $+ 07 $+ $gettok($gettok($read(quotes.txt,%quote.no),2,191),2,58) $+ 09 $&
- $gettok($gettok($read(quotes.txt,%quote.no),3,191),1,58) $+ 11:07 $+ $gettok($gettok($read(quotes.txt,%quote.no),3,191),2,58)
- ;--------------determines if more than 1 match was found, if so, notices the requesting nick the quote numbers for the remaining entries matched via the supplied search parameters.
- if ($calc($numtok(%quotes,32) - 1) > 0) {
- ;--------------notices the requesting nick the remaining matches
- .notice $nick 09 $+ $calc($numtok(%quotes,32) - 1) other related entries11:07 $remove(%quotes, $chr(35) $+ %quote.no)
- }
- }
- ;--------------no matches found, error.
- else {
- msg $chan 09Error11:07 There's no quotes containing what you specified.
- unset %quotes
- }
- }
- ;--------------!findquote intext searchparameters command was used.
- else {
- ;--------------found matches for our search parameters
- if (%quote != $null) {
- ;--------------Display result total
- msg $chan 09Found1107 $hget(results,0).item 09entries.
- ;--------------Send quote data
- msg $chan 09Entries11:07 $hget(results,0).item 09Quote Number:04 %quote.no $+ $replace($gettok(%quote,1,191),%search,09 $+ %search $+ ) $&
- 14-09 $gettok($gettok($read(quotes.txt,%quote.no),2,191),1,58) $+ : $+ 07 $+ $gettok($gettok($read(quotes.txt,%quote.no),2,191),2,58) $+ 09 $&
- $gettok($gettok($read(quotes.txt,%quote.no),3,191),1,58) $+ :07 $+ $gettok($gettok($read(quotes.txt,%quote.no),3,191),2,58)
- ;--------------checks if more than 1 result was found.
- if ($calc($numtok(%quotes,32) - 1) > 0) {
- ;--------------notices requesting nick the remaining quote numbers matching our search parameters
- notice $nick 09 $+ $calc($numtok(%quotes,32) - 1) other related entries11:07 $remove(%quotes, $chr(35) $+ %quote.no)
- unset %quotes
- }
- unset %quotes
- }
- ;--------------No matches found, error.
- else {
- ;--------------send error.
- msg $chan 09Error11:07 There's no quotes containing what you specified.
- unset %quotes
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement