Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- on *:load: {
- set %_mschan #elite-chat | hmake ms 10000 | .timerms 0 300 hload ms ms.tmp
- ;.timermssave 0 300 _mspurge
- set %_msb !mostsearched
- }
- on *:start: {
- hmake ms 10000
- if $isfile(ms.tmp) { .hload ms ms.tmp }
- .timerms 0 300 hsave ms ms.tmp
- ;.timermssave 0 300 _mspurge
- }
- on *:unload:hfree ms | unset %_ms* | if $isfile(ms.tmp) { .remove ms.tmp } | .timerms* off
- on *:quit:hsave ms ms.tmp
- on *:exit:hsave ms ms.tmp
- ; $_mstotal :: returns the total number of indexed releases
- alias _mstotal { return $hget(ms,0).item }
- ; Purge command the bot runs every 5 minutes to purge the database of all entries with a value of 5 or less.
- alias _mspurge {
- var %x 1, %xx 0, %m $_mstotal
- while %x <= %m {
- if $hget(ms,%x).data <= 5 {
- hdel ms $hget(ms,%x).item
- ; inc %xx
- }
- inc %x
- }
- ; ** Commented out because the bot now purges itself on a timer
- ; if $_mstotal > %xx { msg %_mschan %_msb :: %xx items purged }
- ; elseif $_mstotal == %xx { msg %_mschan %_msb :: 0 items purged }
- }
- ; This loops thru all entries and sorts them to determine the highest to lowest
- alias _mslist {
- var %count = 1
- if ($window(@Sort1,state)) { window -c @Sort1 } | if ($window(@Sort2,state)) { window -c @Sort2 }
- window -h @Sort1 | window -h @Sort2
- while (%count <= $_mstotal) { aline @Sort1 $hget(ms,%count).item $hget(ms,%count).data | inc %count }
- ;command to filter and sort the results asscending
- filter -wwucte 2 32 @Sort1 @Sort2 *
- ; ** Change value of %v below to change the number of results to display (default is 10).
- var %x = 1, %v = $iif($hget(ms,0).item <= 10, $ifmatch,10) | while (%x <= %v) { msg %_mschan $+(,%x,.,) Release Name: $gettok($line(@Sort2,%x),1,32) :: Searched: $gettok($line(@Sort2,%x),2,32) times. | inc %x }
- window -c @Sort1 | window -c @Sort2
- }
- alias mss {
- msg %_mschan %_msb :: Listing [Top 10] Most Searched Terms...
- _mslist
- msg %_mschan %_msb :: [EOF]
- }
- ; this hinc's the index and lets u do the !mostsearched commands, merge, purge, and help references.
- on *:text:*:%_mschan:{
- ; flood protection, so each nick can only do !mostsearched once every 5 seconds
- if !%msfld. [ $+ [ $nick ] ] {
- set -u5 %msfld. [ $+ [ $nick ] ] 1
- ; change spaces to periods, needs for tokens.
- if $2 { var %msr = $replace($2-,$chr(32),$chr(46)) }
- ; increase the value of the term searched anytime someone does a !s or !search.
- if (($1 == !s || $1 == !search)) && $2- { hinc ms %msr | halt }
- ; if user only types !mostsearched, then run command _mslist which lists top 10.
- if $1 == !mostsearched && !$2- {
- if $_mstotal > 0 {
- mss | halt
- }
- else msg %_mschan %_msb :: No Searches Indexed yet...
- }
- ; !mostsearched commands
- elseif $1 == !mostsearched && $2- {
- ; Code for help
- if $2 != merge && $2 == help {
- msg # :: Sending %_msb :: Help Command Reference to $+(,$nick,) via pm.
- msg $nick %_msb :: Help Command Reference
- msg $nick :: If a user only types !mostsearched, then list top 10 most searched terms.
- msg $nick :: If a user types !mostsearched release.name.here (periods required), it will show the number of searches that release has.
- msg $nick :: If an op (@) or halfop (%) types !mostsearched merge release.name1.here release.name2.here - it will merge the 2 values of the specified releases, then delete release.name1.here. You are merging the first into the second, then deleting the first.
- ; msg $nick :: If an op (@) or halfop (%) types !mostsearched purge (This deletes all items in the database with a value of 5 or less.
- msg $nick %_msb :: EOF
- halt
- }
- ; Code for !mostsearched release.name
- if $2 != merge {
- if $hget(ms,%msr) {
- msg # %_msb :: Number of searches for %msr is $iif($replace($hget(ms,%msr),$chr(32),$chr(46)),$ifmatch,0) $+ .
- halt
- }
- else msg # %_msb :: Error: $+(,%msr,) doesn't exist. Please check your spelling. | halt
- }
- }
- ; ** Commented out because the bot now purges itself on a timer
- ; Purge command for ops and halfops to purge the database of all entries with a value less than 5.
- ; Usage: !mostsearched purge :: loops thru the entire database and deletes all below 5.
- ; if ($1 == !mostsearched) && ($2 == purge) && (($nick isop #) || ($nick ishop #)) {
- ; if !$3 {
- ; msg # %_msb :: Purging database...
- ; _mspurge
- ; msg # %_msb :: Purging Complete.
- ; }
- ; }
- ; Merge command for ops and halfops to merge the values of one search term into a 2nd. (adds the 2 values to the second release.name, then deletes the first release.name)
- ; Usage: !mostsearched merge first.release.name second.release.name
- if ($1 == !mostsearched) && ($2 == merge) && ($3) && ($4) {
- ;&& (($nick isop #) || ($nick ishop #))
- ; no spaces
- if $chr(32) !iswm $3 {
- if $hget(ms,$3) {
- if $hget(ms,$replace($4,$chr(32),$chr(46))) {
- var %mc $calc($hget(ms,$3) + $hget(ms,$replace($4,$chr(32),$chr(46))))
- hadd ms $replace($4,$chr(32),$chr(46)) %mc | hdel ms $3
- msg # %_msb :: Merge Successful! $+(,$3,) has been merged with $+(,$replace($4,$chr(32),$chr(46)),) and the new value is $+(,%mc,.) The first release specified, $+(,$3,) $+ , has been deleted.
- halt
- }
- ; Merge Error Messages
- else msg # %_msb :: Error: Second Release specified, $+(,$4,) doesn't exist. Check your spelling.
- }
- else msg # %_msb :: Error: First Release specified, $+(,$3,) doesn't exist. Check your spelling.
- }
- else msg # %_msb :: Error: Release names indexed do not have spaces in the titles, use periods.
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement