PtokaX forum

Archive => Archived 5.0 boards => Finished Scripts => Topic started by: Dessamator on 15 May, 2005, 14:52:37

Title: SearchCount-V.1.3
Post by: Dessamator on 15 May, 2005, 14:52:37
--SearchCount-V.1.3
--30.9.03 by c h i l l e r
--lua 5 by Dessamator
-- added tth filter

--To enable right click write --> true
Rightclick = false
--This number stands for the maximum of shown items
Max1 = 100
--This number stands for the maximum of stored items
Max2 = 1000
--Timespan in minutes between each saving
Max3 = 60

--------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------

File1 = "txt/TopSearches.txt"
SearchItems={}

sec = 1000
min = 60 * sec

function Main()
local handle = io.open(File1,"r")
if handle then
dofile(File1)
else
io.output(File1)
io.write("")          -- creates the file
       io.output()
end
SetTimer(Max3 * min )
StartTimer()
end

--user command(right click)
function NewUserConnected(user)
if Rightclick == true then
user:SendData("$UserCommand 1 3 Search logger\\Most Wanted $<%[mynick]> !mostwanted||")
if user.bOperator then
user:SendData("$UserCommand 1 3 Search logger\\Clear Logs $<%[mynick]> !clrslog||")
end
end
end
OpConnected = NewUserConnected
--
function OnExit()
OnTimer()
end

function OnTimer()
SaveToFile(File1,SearchItems, "SearchItems")
end

function ChatArrival(curUser, data)
data = string.sub(data,1,string.len(data)-1)
s,e,cmd = string.find(data, "%b<>%s+(%S+)")
if cmd=="!mostwanted" then
curUser:SendData("\r\n".."\t\t\THE    MOST   WANTED\r\n"..
"\t"..string.rep("-",70).."\r\n"..
"\t\- - HITS - -\t\- - ITEM - -\r\n"..
TopSearches().."\r\n"..
"\t"..string.rep("-",70))
return 1
elseif cmd=="!clrslog" and curUser.bOperator then
SearchItems="nil"
SearchItems={}
curUser:SendData("Searchlogger","All previous searches have been purged from the logs")
return 1
end
end
function SearchArrival(User, data)
local _,_,sestring = string.find( data, "$Search %S+%s%S+?%S+?%S+?%S+?(.*)" )
local s,e, findtth = string.find(sestring,"(TTH%:)")
if sestring and string.len(sestring) < 50 and not(findtth) then
sestring = string.sub(sestring,1,string.len(sestring)-1)
sestring = string.lower(sestring)
sestring = string.gsub(sestring, "$+", " ")
if SearchItems[sestring]==nil then
SearchItems[sestring]=1
else
SearchItems[sestring]=SearchItems[sestring]+1
end
end
end
------------------------------------------------------------------------------------------------------------------
function TopSearches()
local TCopy={}
for i,v in SearchItems do
table.insert( TCopy, {tonumber(v),i} )
end
table.sort( TCopy, function(a, b) return (a[1] > b[1]) end)
local msg ="\r\n"
for i = 1,Max1 do
if TCopy[i] then
msg = msg.."                     "..TCopy[i][1].."                    "..TCopy[i][2].."\r\n"
end
end
local TCopy={}
return msg
end
------------------------------------------------------------------------------------------------------------------
function Serialize(tTable, sTableName, sTab)
        assert(tTable, "tTable equals nil");
        assert(sTableName, "sTableName equals nil");
 
        assert(type(tTable) == "table", "tTable must be a table!");
        assert(type(sTableName) == "string", "sTableName must be a string!");
 
        sTab = sTab or "";
        sTmp = ""
 
        sTmp = sTmp..sTab..sTableName.." = {\n"
 
        for key, value in tTable do
                local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
 
                if(type(value) == "table") then
                        sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
                else
                        local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
                        sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
                end
 
                sTmp = sTmp..",\n"
        end
 
        sTmp = sTmp..sTab.."}"
        return sTmp
end
 
function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
        handle:write(Serialize(table, tablename))
handle:flush()
        handle:close()
end
------------------------------------------------------------------------------------------------------------------
Title:
Post by: chettedeboeuf on 31 May, 2005, 18:44:21
tth:r2hmiaeu5ir7ia6io43gteynjbozczau6qstcza


Is it possible to filter this type of searches ???
Title:
Post by: chettedeboeuf on 31 May, 2005, 21:41:35
Thank you Dessamator
Title:
Post by: Dessamator on 31 May, 2005, 21:42:12
ur welcome :)
Title:
Post by: Oz on 01 June, 2005, 17:24:51
why tth filter doesent work? :(
Title: Thank u
Post by: XPMAN on 01 June, 2005, 18:04:13
Thanx for this usefull script :)

One small request though anyway when you list the hub record:


----------------------------------------------------------------------------------------------------
Record Value Date - Time
----------------------------------------------------------------------------------------------------
Share 100.2 MB 06/01/05 11:03:14
Users 1 user(s)
---------------------------------------------------------------------------------------------------  

It can also list the Nick of the user that shares the most in the hub. Other words have  :  share record , users , then also list top sharer.. example:

Top share    XPMAN    550 Gigs


All underneath each other.
Title: Plese move
Post by: XPMAN on 01 June, 2005, 18:10:10
Can a mod please move this post to the Record bot. I mis posted....yea, thats what i did .... "rolll eyes"
Title:
Post by: Dessamator on 01 June, 2005, 19:35:35
QuoteOriginally posted by Oz
why tth filter doesent work? :(

done, post edited !
Title:
Post by: jiten on 01 June, 2005, 20:24:42
QuoteOriginally posted by XPMAN
Thanx for this usefull script :)

One small request though anyway when you list the hub record:


----------------------------------------------------------------------------------------------------
Record Value Date - Time
----------------------------------------------------------------------------------------------------
Share 100.2 MB 06/01/05 11:03:14
Users 1 user(s)
---------------------------------------------------------------------------------------------------  

It can also list the Nick of the user that shares the most in the hub. Other words have  :  share record , users , then also list top sharer.. example:

Top share    XPMAN    550 Gigs


All underneath each other.
Heya m8.
When I get some free time I'll add this to the Record Bot.

Cheers
Title:
Post by: chettedeboeuf on 02 June, 2005, 08:25:35
Hi,
The filter doesn't work !
Title:
Post by: catwo on 02 June, 2005, 08:33:09
Very nice script, any chance of it displaying the actual file name searched for rather than the tth name?  As always thanks for the script and your time and efforts.
Title:
Post by: Dessamator on 02 June, 2005, 10:41:07
QuoteOriginally posted by catwo
Very nice script, any chance of it displaying the actual file name searched for rather than the tth name?  As always thanks for the script and your time and efforts.

Done! , post edited
Title:
Post by: Dessamator on 02 June, 2005, 12:58:56
--SearchCount-V.1.4b
--30.9.03 by c h i l l e r
--lua 5 by Dessamator
-- Added categories/types
-- added tth filter
-- fixed loopy loop bug and sort bug(thnx jiten)

--To enable right click write --> true
Rightclick = false
--This number stands for the maximum of shown items
Max1 = 100
--This number stands for the maximum of stored items
Max2 = 1000
--Timespan in minutes between each saving
Max3 = 60

--------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------

File1 = "txt/TopSearches.txt"
SearchItems={}
cat={[1]="Unknown",[2]="Audio",[3]="Compressed",[4]="Document",[5]="Executable",[6]="Picture",[7]="Video",[8]="Directory",[9]="TTH"}
sec = 1000
min = 60 * sec

function Main()
local handle = io.open(File1,"r")
if handle then
dofile(File1)
else
io.output(File1)
io.write("")          -- creates the file
       io.output()
end
SetTimer(Max3 * min )
StartTimer()
end

--user command(right click)
function NewUserConnected(user)
if Rightclick == true then
user:SendData("$UserCommand 1 3 Search logger\\Most Wanted $<%[mynick]> !mostwanted||")
if user.bOperator then
user:SendData("$UserCommand 1 3 Search logger\\Clear Logs $<%[mynick]> !clrslog||")
end
end
end
OpConnected = NewUserConnected
--
function OnExit()
OnTimer()
end

function OnTimer()
SaveToFile(File1,SearchItems, "SearchItems")
end

function ChatArrival(curUser, data)
data = string.sub(data,1,string.len(data)-1)
s,e,cmd = string.find(data, "%b<>%s+(%S+)")
if cmd=="!mostwanted" then
curUser:SendData("\r\n".."\t\t\THE    MOST   WANTED\r\n"..
"\t"..string.rep("-",70).."\r\n"..
"\t\- - HITS - - \t\- - TYPE - -\t\t\- - ITEM - -\r\n"..
TopSearches().."\r\n"..
"\t"..string.rep("-",70))
return 1
elseif cmd=="!clrslog" and curUser.bOperator then
SearchItems="nil"
SearchItems={}
curUser:SendData("Searchlogger","All previous searches have been purged from the logs")
return 1
end
end
function SearchArrival(User, data)
local _,_,category,sestring = string.find( data, "$Search %S+%s%S+?%S+?%S+?(%S+)?(.*)" )
local s,e, findtth = string.find(sestring,"(TTH%:)")
if sestring and string.len(sestring) < 50 and not(findtth) then
sestring = string.sub(sestring,1,string.len(sestring)-1)
sestring = string.lower(sestring)
sestring = string.gsub(sestring, "$+", " ")
if SearchItems[sestring]==nil then
SearchItems[sestring]={}
SearchItems[sestring]["times"] = 1
SearchItems[sestring]["Category"] = cat[tonumber(category)]
else
SearchItems[sestring]["times"]=SearchItems[sestring]["times"]+1
end
end
end
------------------------------------------------------------------------------------------------------------------
function TopSearches()
local TCopy,TCat={},{}

for i,v in SearchItems do
table.insert( TCopy, {SearchItems[i]["times"],i,SearchItems[i]["Category"]} )
end
table.sort(TCopy,function(a,b) return (a[1] > b[1]) end)
local msg ="\r\n"
for i = 1,Max1 do
if TCopy[i] then
msg = msg.."\t"..TCopy[i][1]
msg = msg.."\t\t"..TCopy[i][3]
if string.len(TCopy[i][3]) < 10 then
msg = msg.."\t\t\t"..TCopy[i][2].."\r\n"
end
if string.len(TCopy[i][3]) >= 10 then
msg = msg.."\t\t"..TCopy[i][2].."\r\n"
end
end
end
local TCopy={}
return msg
end
------------------------------------------------------------------------------------------------------------------
function Serialize(tTable, sTableName, sTab)
        assert(tTable, "tTable equals nil");
        assert(sTableName, "sTableName equals nil");
 
        assert(type(tTable) == "table", "tTable must be a table!");
        assert(type(sTableName) == "string", "sTableName must be a string!");
 
        sTab = sTab or "";
        sTmp = ""
 
        sTmp = sTmp..sTab..sTableName.." = {\n"
 
        for key, value in tTable do
                local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
 
                if(type(value) == "table") then
                        sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
                else
                        local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
                        sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
                end
 
                sTmp = sTmp..",\n"
        end
 
        sTmp = sTmp..sTab.."}"
        return sTmp
end
 
function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
        handle:write(Serialize(table, tablename))
handle:flush()
        handle:close()
end
Title:
Post by: chettedeboeuf on 02 June, 2005, 13:31:46
:D  :D

Numbers appear on my central chat !!

LoL
Title:
Post by: Dessamator on 02 June, 2005, 14:08:18
lol, it was a debugging "material", i forgot to remove that when it was done, either way post edited :)
Title:
Post by: chettedeboeuf on 02 June, 2005, 14:15:54
Yes, when I start the script, numbers appear on the central chat

[14:15] 44
[14:15] 21

etc ......

With 1.3 no problem
Title:
Post by: Dessamator on 02 June, 2005, 14:28:09
QuoteOriginally posted by chettedeboeuf
Yes, when I start the script, numbers appear on the central chat

[14:15] 44
[14:15] 21

etc ......

With 1.3 no problem
yap i solved the error, copy the script again :)
Title:
Post by: chettedeboeuf on 02 June, 2005, 14:38:35
Thank you dessamator
Title:
Post by: Dessamator on 02 June, 2005, 14:56:53
ur welcome !
Title:
Post by: chettedeboeuf on 02 June, 2005, 18:49:30
I've this error :

[17:57] Syntax ...kaX\HUB 0.3.3.0 17.08\scripts\Hit Des Recherches.lua:150: bad argument #1 to `find' (string expected, got nil)

Line 150 :
local s,e, findtth = string.find(sestring,"(TTH%:)")

Thank you
Title:
Post by: Dessamator on 02 June, 2005, 20:01:07
post edited, btw no errors here, that should never happen unless, u edited some part of the script, or unless u didnt search for anything !
Title:
Post by: chettedeboeuf on 02 June, 2005, 20:17:33
What means 'btw' in French, please
Thank you
Title:
Post by: Dessamator on 02 June, 2005, 20:22:28
btw=  by the way = d'ailleurs(at least  google's translator says so)
Title:
Post by: jiten on 02 June, 2005, 20:27:29
QuoteOriginally posted by Dessamator
btw=  by the way = d'ailleurs(at least  google's translator says so)
Nice one m8. I had forgotten the meaning of it too :D
Title:
Post by: Oz on 02 June, 2005, 21:05:07
hi :) how to align colump???


Title:
Post by: Dessamator on 02 June, 2005, 22:37:25
lol, aligning the column, well, it can be done the problem is, u can search for a thing with more than 200 characters, and it wont be able to align that it will always come out distorted, if u suggest a maximum characters, ill try to add it :)
Title:
Post by: jiten on 03 June, 2005, 11:29:14
QuoteOriginally posted by XPMAN
Thanx for this usefull script :)

One small request though anyway when you list the hub record:

It can also list the Nick of the user that shares the most in the hub. Other words have  :  share record , users , then also list top sharer.. example:

Top share    XPMAN    550 Gigs


All underneath each other.
Check the Record Bot thread again ;)

Best regards
Title:
Post by: Dinok on 07 June, 2005, 11:13:08
at command !mostwanted - such mistake
Syntax ...Ptokax\0.3.3.0.b17.08.nt.dbg\scripts\SearchCount.lua:185: attempt to compare number with nil
Title:
Post by: Dessamator on 07 June, 2005, 12:34:06
hmm, no errors here, i just tested it a few mins ago,try copying the script again, and erasing the Topsearches.txt, and then starting the script.

QuoteOriginally posted by Oz
hi :) how to align colump???

Done ! post edited
Title:
Post by: Dinok on 09 June, 2005, 05:24:41
QuoteOriginally posted by Dessamator
hmm, no errors here, i just tested it a few mins ago,try copying the script again, and erasing the Topsearches.txt, and then starting the script.

works, thank you
Title:
Post by: ConejoDelMal on 09 June, 2005, 06:00:14
this script is great! i dont know how i didnt come across it sooner...

There is a problem though... it doesnt saves the Type correctly, for instance, if i search for "telelista" once, with type any, i stays normal:

 Times                 Type                       Item

1 Unknown           fabio junior
1 Unknown           telelista
1 Video               sin city ts xvid invfx cd1 avi
1 Video               the fifth element divx avi
1 Unknown   san andreas
1 Unknown           meu dengo

After someone makes another search, the type doesnt moves, just the Item:
- - Times - - - - Type - - - - Item - -

2 Unknown   san andreas
1 Unknown   fabio junior
1 Video               telelista
1 Video               the fifth element divx avi
1 Unknown   sin city ts xvid invfx cd1 avi
1 Unknown   meu dengo

or maybe its just me....still didnt sleep  :P
Title:
Post by: Dessamator on 09 June, 2005, 10:42:19
lol, i did that on purpose, it shouldnt save as "any", because its isnt specific, what type/ category  is "any"??? in other words any == unknown !

hope u understand !

but if u still want that, just change this ::

cat={[1]="Unknown",[2]="Audio",[3]="Compressed",[4]="Document",[5]="Executable",[6]="Picture",[7]="Video",[8]="Directory",[9]="TTH"}


to this:

cat={[1]="Any",[2]="Audio",[3]="Compressed",[4]="Document",[5]="Executable",[6]="Picture",[7]="Video",[8]="Directory",[9]="TTH"}
Title:
Post by: jiten on 09 June, 2005, 11:22:05
If I'm not wrong, [AT]conejodelmal is talking about the tabbing that isn't that accurate.
Maybe you could use nErBoS' DoTabs function. It is almost perfect ;)

Cheers
Title:
Post by: ConejoDelMal on 09 June, 2005, 17:24:08
hmm... i think you didnt understand me  :D

notice the word "Telelista", in the first display, with one search, it's searched as Unknown, after someone searches something else, it changed to Video, but no one searched for "Telelista" with Type Video...

Hope its more understandable now  :P
Title:
Post by: Dessamator on 09 June, 2005, 17:43:17
ooh, i see so theres a bug in the searching, but how can u be so sure it wasnt searched?, either way ill check it out !
Title:
Post by: ConejoDelMal on 09 June, 2005, 17:46:20
I can be sure it wasnt searched as Video, cause in the first time i typed the command, it was there with one search and as unknown, after a few seconds, i typed it again, and still with one search only it changed do Video.

The same with "sin city ts xvid invfx cd1 avi" first it was searched as Video, after it displayed it as Unknown  :(
Title:
Post by: Dessamator on 09 June, 2005, 18:06:45
Fixed, post edited !
Title:
Post by: ConejoDelMal on 09 June, 2005, 18:37:21
(I'm already getting annoying, I know :P)

Still not really perfect.. the last problem looks solved, but right now i searched for " Queens of the Stone Age " as Audio, and it displays it as:

   1      Unknown         queens of the stone age

If its too much work to fix it, I'm considering to remove the Type.. as anyway most people search as Any
Title:
Post by: Dessamator on 09 June, 2005, 23:48:46
i searched for that and it worked perfectly for me, u must have done something wrong either way, post edited, maybe it will solve ur bug :)
Title:
Post by: Oz on 27 June, 2005, 16:35:16
I have error :(

Syntax ...0.3.3.0.b17.08.nt.dbg\scripts\SearchCount-V.1.4b.lua:153: bad argument #1 to `find' (string expected, got nil)
Title:
Post by: Dessamator on 27 June, 2005, 17:34:49
try this :

1.Stop the script
2. delete the file in the txt folder named : TopSearches.txt
3. Start the script !
Title:
Post by: Oz on 27 June, 2005, 18:19:45
Ok, i try :)

big thx
Title:
Post by: Dessamator on 27 June, 2005, 21:05:45
ur welcome(if it works)