Advertisement
contr0l

!Mostsearched - 11-5-1016

Nov 5th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 5.90 KB | None | 0 0
  1. on *:load: {
  2.   set %_mschan #elite-chat | hmake ms 10000 | .timerms 0 300 hload ms ms.tmp
  3.   ;.timermssave 0 300 _mspurge
  4.   set %_msb !mostsearched
  5. }
  6. on *:start: {
  7.   hmake ms 10000
  8.   if $isfile(ms.tmp) { .hload ms ms.tmp }
  9.   .timerms 0 300 hsave ms ms.tmp
  10.   ;.timermssave 0 300 _mspurge
  11. }
  12. on *:unload:hfree ms | unset %_ms* | if $isfile(ms.tmp) { .remove ms.tmp } | .timerms* off
  13. on *:quit:hsave ms ms.tmp
  14. on *:exit:hsave ms ms.tmp
  15.  
  16. ; $_mstotal :: returns the total number of indexed releases
  17. alias _mstotal { return $hget(ms,0).item }
  18.  
  19. ; Purge command the bot runs every 5 minutes to purge the database of all entries with a value of 5 or less.
  20. alias _mspurge {
  21.   var %x 1, %xx 0, %m $_mstotal
  22.   while %x <= %m {
  23.     if $hget(ms,%x).data <= 5 {
  24.       hdel ms $hget(ms,%x).item
  25.       ;  inc %xx
  26.     }
  27.     inc %x
  28.   }
  29.  
  30.   ; ** Commented out because the bot now purges itself on a timer
  31.   ;  if $_mstotal > %xx { msg %_mschan %_msb :: %xx items purged }
  32.   ;  elseif $_mstotal == %xx { msg %_mschan %_msb :: 0 items purged }
  33.  
  34. }
  35.  
  36. ; This loops thru all entries and sorts them to determine the highest to lowest
  37. alias _mslist {
  38.   var %count = 1
  39.   if ($window(@Sort1,state)) { window -c @Sort1 } | if ($window(@Sort2,state)) { window -c @Sort2 }
  40.   window -h @Sort1 | window -h @Sort2
  41.   while (%count <= $_mstotal) { aline @Sort1 $hget(ms,%count).item $hget(ms,%count).data | inc %count }
  42.  
  43.   ;command to filter and sort the results asscending
  44.   filter -wwucte 2 32 @Sort1 @Sort2 *
  45.  
  46.   ; ** Change value of %v below to change the number of results to display (default is 10).
  47.   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 }
  48.   window -c @Sort1 | window -c @Sort2
  49. }
  50. alias mss {
  51.   msg %_mschan %_msb :: Listing [Top 10] Most Searched Terms...
  52.   _mslist
  53.   msg %_mschan %_msb :: [EOF]
  54. }
  55. ; this hinc's the index and lets u do the !mostsearched commands, merge, purge, and help references.
  56. on *:text:*:%_mschan:{
  57.   ; flood protection, so each nick can only do !mostsearched once every 5 seconds
  58.   if !%msfld. [ $+ [ $nick ] ] {
  59.     set -u5 %msfld. [ $+ [ $nick ] ] 1
  60.  
  61.     ; change spaces to periods, needs for tokens.
  62.     if $2 { var %msr = $replace($2-,$chr(32),$chr(46)) }
  63.  
  64.     ; increase the value of the term searched anytime someone does a !s or !search.
  65.     if (($1 == !s || $1 == !search)) && $2- { hinc ms %msr | halt }
  66.  
  67.     ; if user only types !mostsearched, then run command _mslist which lists top 10.
  68.     if $1 == !mostsearched  && !$2- {
  69.       if $_mstotal > 0 {
  70.         mss | halt
  71.       }
  72.       else msg %_mschan %_msb :: No Searches Indexed yet...
  73.     }
  74.  
  75.     ; !mostsearched commands
  76.     elseif $1 == !mostsearched && $2- {
  77.       ; Code for help
  78.       if $2 != merge && $2 == help {
  79.         msg # :: Sending %_msb :: Help Command Reference to $+(,$nick,) via pm.
  80.         msg $nick %_msb :: Help Command Reference
  81.         msg $nick :: If a user only types !mostsearched, then list top 10 most searched terms.
  82.         msg $nick :: If a user types !mostsearched release.name.here (periods required), it will show the number of searches that release has.
  83.         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.
  84.         ;        msg $nick :: If an op (@) or halfop (%) types !mostsearched purge (This deletes all items in the database with a value of 5 or less.
  85.         msg $nick %_msb :: EOF
  86.         halt
  87.       }
  88.  
  89.       ; Code for !mostsearched release.name
  90.       if $2 != merge {
  91.         if $hget(ms,%msr) {
  92.           msg # %_msb :: Number of searches for %msr is $iif($replace($hget(ms,%msr),$chr(32),$chr(46)),$ifmatch,0) $+ .
  93.           halt
  94.         }
  95.         else msg # %_msb :: Error: $+(,%msr,) doesn't exist. Please check your spelling. | halt
  96.       }
  97.     }
  98.     ; ** Commented out because the bot now purges itself on a timer
  99.     ; Purge command for ops and halfops to purge the database of all entries with a value less than 5.
  100.     ; Usage: !mostsearched purge :: loops thru the entire database and deletes all below 5.
  101.     ;    if ($1 == !mostsearched) && ($2 == purge) && (($nick isop #) || ($nick ishop #)) {
  102.     ;      if !$3 {
  103.     ;        msg # %_msb :: Purging database...
  104.     ;        _mspurge
  105.     ;        msg # %_msb :: Purging Complete.
  106.     ;      }
  107.     ;    }
  108.  
  109.     ; 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)
  110.     ; Usage: !mostsearched merge first.release.name second.release.name
  111.     if ($1 == !mostsearched) && ($2 == merge) && ($3) && ($4) {
  112.       ;&& (($nick isop #) || ($nick ishop #))
  113.       ; no spaces
  114.       if $chr(32) !iswm $3 {
  115.         if $hget(ms,$3) {
  116.           if $hget(ms,$replace($4,$chr(32),$chr(46))) {
  117.             var %mc $calc($hget(ms,$3) + $hget(ms,$replace($4,$chr(32),$chr(46))))
  118.             hadd ms $replace($4,$chr(32),$chr(46)) %mc | hdel ms $3
  119.             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.
  120.             halt
  121.           }
  122.           ; Merge Error Messages
  123.           else msg # %_msb :: Error: Second Release specified, $+(,$4,) doesn't exist. Check your spelling.
  124.         }
  125.         else msg # %_msb :: Error: First Release specified, $+(,$3,) doesn't exist. Check your spelling.
  126.       }
  127.       else msg # %_msb :: Error: Release names indexed do not have spaces in the titles, use periods.
  128.     }
  129.  
  130.   }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement