Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- on *:start: {
- set %_mschan #elite-chat | set %_msb !mostsearched | set %_msdir $+($mircdir,mostsearched\) | set %_msitems $+(",%_msdir,msitems.txt,") | whilefix
- if !$exists(%_msdir) { mkdir %_msdir } | if !$exists(%_msitems) { write -c %_msitems }
- ; Make a copy of the database daily
- .timermscopy 0 86400 _mscopy
- ; Every 10 minutes purge the database of all entries with less than 3 searches for that term. Speeds up processing.
- .timermspurge 0 600 _mspurge
- }
- ; Clean up if unloaded. Deletes database and all backups, and then deletes the 'mostsearched' folder from your $mircdir then cleans up variables.
- on *:unload: { var %i $findfile(%_msdir,*.*,0,.remove $1-) | .remove %_msdir | unset %_ms* }
- ; whilefix alias uses whilefix.dll so mirc doesnt freeze during big loops.
- ; Just add /whilefix every iteration of your loops and mirc wont freeze. (whilefix.dll needs to be in $mircdir)
- alias whilefix { dll WhileFix.dll WhileFix . }
- ; convert spaces to periods.
- alias ' { return $replace($1-,$chr(32),$chr(46)) }
- ; msg chan the toal number of searched items indexed.
- alias _mstotal { return $lines(%_msitems) }
- ;msg channel total number of search terms indexed.
- alias mst { msg %_mschan %_msb There are $+(,$bytes($_mstotal,b),) total searches Indexed. }
- ; Import old data from hash tables into text file.
- alias _msimport { var %i $hget(ms,0).item | while %i { whilefix | write %_msitems $hget(ms,%i).data $hget(ms,%i).item | dec %i } }
- ; backup database once a day in case of data loss.
- alias _mscopy { var %mscfn $+($remove(%_msitems,.txt,"),-BACKUP-,$asctime(mmddyy),-,$asctime(hhnntt),.txt) | copy -o %_msitems %mscfn | echo -a %_msb Backup made of the database. Name: $nopath(%mscfn) -Location: $+(,$nofile(%_msitems),) }
- ; Purge database of all entries that don't have atleast been searched 3 times.
- alias _mspurge {
- var %x $_mstotal | while %x {
- whilefix
- if $gettok($read(%_msitems,%x),1,32) <= 3 { write $+(-dl,%x) %_msitems }
- dec %x
- }
- }
- ; Sorts entries in ascending order by the number of searches, and lists top 10.
- 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
- ;write all lines to @Sort1
- while (%count <= $_mstotal) { whilefix | aline @Sort1 $gettok($read(%_msitems,%count),2-,32) $gettok($read(%_msitems,%count),1,32) | inc %count }
- ;command to filter and sort the results asscending
- filter -wwucte 2 32 @Sort1 @Sort2 *
- ; ** Display the Top 10 Most Searched Terms (or you can change the value below...)
- ; ** - Change value of %v below to change the number of results to display (default is 10).
- var %x = 1, %v = 10 | while (%x <= %v) { whilefix | msg %_mschan $+(,%x,.,) $gettok($line(@Sort2,%x),1,32) :: Searched: $gettok($line(@Sort2,%x),2,32) times. | inc %x }
- window -c @Sort1 | window -c @Sort2
- }
- ; Show list of top 10 most searched terms
- alias mss {
- msg %_mschan %_msb :: Listing [Top 10] Most Searched Terms of the $+(,$bytes($_mstotal,b),) Indexed.
- _mslist
- msg %_mschan %_msb :: [EOF]
- }
- 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 = $'($2-) }
- ; increase the value of the term searched anytime someone does a !s or !search.
- if (($1 == !s || $1 == !search)) && $2- {
- if $read(%_msitems, w, $+(*,%msr,*)) {
- var %msln $readn
- ; increase number of times this has been searched
- var %msval $calc($gettok($ifmatch,1,32) + 1), %msval2 $gettok($ifmatch,2-,32)
- ; delete the line with the search term.
- write $+(-dl,%msln) %_msitems
- ; write a line with new value increased by 1.
- write %_msitems %msval %msval2
- halt
- }
- ; if searched term has never been searched before, add with value of 1
- else write %_msitems 1 %msr
- }
- ; if user only types !mostsearched, then run command _mslist (/mss) which lists top 10.
- if $1 == !mostsearched && !$2- {
- if $_mstotal > 0 { mss | halt }
- else msg %_mschan %_msb :: No Searches Indexed yet...
- }
- ; !mostsearched commands
- if $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 %_msb :: EOF
- halt
- }
- ; Code for !mostsearched release.name - to show the number of searches for the specified search term.
- if $2 && $2 != merge && $2 != help {
- if $read(%_msitems, w, $+(*,$2-,*)) {
- var %_msrdn $readn
- msg # %_msb :: Number of searches for $+(,$2-,) is $iif($gettok($read(%_msitems,%_msrdn),1,32) > 0,$ifmatch,0) $+ .
- halt
- }
- else msg # %_msb :: Error: $+(,$2-,) doesn't exist. | halt
- }
- }
- ; 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) {
- ;if $nick isop # || $nick ishop # || $nick isvoice # {
- ; no spaces allowed
- if $chr(32) !iswm $3 && $chr(32) !iswm $4 {
- ; make sure first search term to merge exists, and set var with the line number
- if $read(%_msitems, w, $+(*,$'($3),*)) {
- var %ms3ln $readn
- ; make sure second search term to merge exists, and set var with the line number
- if $read(%_msitems, w, $+(*,$'($4),*)) {
- var %ms4ln $readn
- ; increase the value of first search term by adding the valueo f the second search term
- var %mc $calc($gettok($read(%_msitems,%ms3ln),1,32) + $gettok($read(%_msitems,%ms4ln),1,32))
- ; delete the first search term merged
- write $+(-dl,%ms3ln) %_msitems
- ; add a line with the new merged value
- write %_msitems %mc $'($4)
- ; msg chan the merge completed and it's new value
- msg # %_msb :: Merge Successful! $+(,$3,) has been merged with $+(,$'($4),) 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