-- FreshStuff v.3.3 -- original idea/script by chilla -- completely rewriten by plop -- if you were running 3.0 then you gotta delete the old file -- it's incompatible with this version -- deleting now goes by id number -- Name the commands to what U like -- This command adds stuff, syntax : +addalbum TYPE/CATAGORY THESTUFF2ADD cmd1 = "+addalbum" -- This command shows the stuff, syntax : +albums with options new/game/warez/music/movie cmd2 = "+albums" -- This command deletes an entry, syntax : +delalbum THESTUFF2DELETE cmd3 = "+delalbum" -- This command shows the latest stuff, syntax : +newalbums cmd4 = "+newalbums" -- This command reloads the txt file. syntax : +reloadalbums -- (this command is needed if you manualy edit the text file) cmd5 = "+reloadalbums" -- Max stuff shown on newalbums/entry MaxNew = 20 -- The file storing the stuff file = "txt/AlbumsAll.txt" -- you can add catagory's yourself ["trigger_name"]="catagory_name" Types = {["movie"] = "Movies", ["music"]="Music", ["warez"]="Warez", ["game"]="Games"} --------------------- don't change anything below here AllStuff = {} NewestStuff = {} function ShowRel(Table) Msg = "\r\n" if Table == NewestStuff then if Count2 == 0 then MsgNew = "\r\n\r\n".." --------- The Latest Releases -------- \r\n\r\n No releases on the list yet\r\n\r\n --------- The Latest Releases -------- \r\n\r\n" else for i=1, Count2 do s,e,typ,who,when,title=string.find(NewestStuff[i], "(.+)$(.+)$(.+)$(.+)") if title then Msg = Msg.." "..when.." -- "..who.." -- "..typ.." -- "..title.."\r\n" else Msg = Msg..NewestStuff[i].."\r\n" end end MsgNew = "\r\n\r\n".." --------- The Latest "..MaxNew.." Releases -------- "..Msg.."\r\n --------- The Latest "..MaxNew.." Releases -------- \r\n\r\n" end return MsgNew else if Count == 0 then MsgAll = "\r\n\r\r\n".." --------- All The Releases -------- \r\n\r\n No releases on the list yet\r\n\r\n --------- All The Releases -------- \r\n\r\n" else MsgHelp = " use "..cmd2.." to see only the selected types" for i=1, Count do s,e,typ,who,when,title=string.find(AllStuff[i], "(.+)$(.+)$(.+)$(.+)") if title then Msg = Msg.." ID: "..i.." -- "..when.." -- "..who.." -- "..typ.." -- "..title.."\r\n" else Msg = Msg..AllStuff[i].."\r\n" end end MsgAll = "\r\n\r\r\n".." --------- All The Releases -------- "..Msg.."\r\n --------- All The Releases -------- \r\n"..MsgHelp.."\r\n" end return MsgAll end end function ShowRelType(what) Msg = "\r\n" tmp = 0 if Count == 0 then MsgType = "\r\n\r\n".." --------- All The "..Types[what].." -------- \r\n\r\n No "..strlower(Types[what]).." yet\r\n\r\n --------- All The "..Types[what].." -------- \r\n\r\n" else for i=1, Count do s,e,typ,who,when,title=string.find(AllStuff[i], "(.+)$(.+)$(.+)$(.+)") if typ == what then tmp = tmp + 1 Msg = Msg.." "..when.." -- "..who.." -- "..title.."\r\n" end end if tmp == 0 then MsgType = "\r\n\r\n".." --------- All The "..Types[what].." -------- \r\n\r\n No "..strlower(Types[what]).." yet\r\n\r\n --------- All The "..Types[what].." -------- \r\n\r\n" else MsgType= "\r\n\r\n".." --------- All The "..Types[what].." -------- \r\n"..Msg.."\r\n --------- All The "..Types[what].." -------- \r\n\r\n" end end return MsgType end function AddRel(user, what, typ) Count = Count + 1 AllStuff[Count]=(typ.."$"..user:getNick().."$"..os.date("%x").."$"..what) SaveRel() ReloadRel() return (what.." is added to the releases as "..typ) end function DelRel(user, what) if tonumber(what) then what = tonumber(what) if AllStuff[what] then local s,e,which=string.find(AllStuff[what], "([^%$]+)$") AllStuff[what]=nil SaveRel() ReloadRel() return (which.." is deleted from the releases") else return (what.." wasn't found in the releases") end else return ("I need the ID number to delete a releas") end end function SaveRel() text = io.open ( file , "w") for i=1,Count do if AllStuff[i] then tmp = tostring( AllStuff[i] ).."\n" text:write( tmp ) end end text:close ( ) end function OpenRel() AllStuff = nil NewestStuff = nil AllStuff = {} NewestStuff = {} Count = 0 Count2 = 0 text = io.input ( file ) for line in text:lines() do Count = Count +1 AllStuff[Count]=line end text:close( ) if Count > MaxNew then local temp = Count - MaxNew + 1 for i=temp, Count do Count2 = Count2 + 1 NewestStuff[Count2]=AllStuff[i] end else for i=1, Count do Count2 = Count2 + 1 NewestStuff[Count2]=AllStuff[i] end end end function ReloadRel() OpenRel() ShowRel(NewestStuff) ShowRel(AllStuff) end function DelRelOld(user, what) Okie = nil for a,b in AllStuff do s,e,title=string.find(b, ".+$(.+)$") if title == what then AllStuff[a]=nil Okie = 1 break end end if Okie then SaveRel() ReloadRel() return (what.." is removed from the releases") else return (what.." wasn't found in the releases") end end ReloadRel() function SendPMMsg(hub, user, txt) DC():SendHubMessage( hub:getId(), "$To: "..user:getNick().." From: "..hub:getOwnNick().." $<"..hub:getOwnNick().."> "..txt.."|" ) end dcpp:setListener( "pm", "releases", function( hub, user, text ) local s = string.lower( text ) d,e,cmd,typ,tune = string.find(s, "^(%S+)%s*(%S*)%s*(.*)") if cmd == cmd2 then if typ == "" then SendPMMsg( hub, user, MsgAll ) --user:sendPrivMsgFmtNoWin( MsgAll ) return 1 elseif typ == "new" then SendPMMsg( hub, user, MsgNew ) --user:sendPrivMsgFmtNoWin( MsgNew ) return 1 elseif Types[typ] then SendPMMsg( hub, user, ShowRelType(typ) ) --user:sendPrivMsgFmtNoWin( MsgType ) return 1 end elseif cmd == cmd4 then SendPMMsg( hub, user, MsgNew ) --user:sendPrivMsgFmtNoWin( MsgNew ) return 1 elseif user:isOp() then if cmd == cmd3 then if typ ~= "" then SendPMMsg( hub, user, DelRel(user, typ) ) --user:sendPrivMsgFmtNoWin( DelRel(user, typ) ) else SendPMMsg( hub, user, "yea right, like i know what i got 2 delete when you don't tell me!" ) --user:sendPrivMsgFmtNoWin( "yea right, like i know what i got 2 delete when you don't tell me!" ) end return 1 elseif cmd == cmd1 then if tune ~= "" and Types[typ] then SendPMMsg( hub, user, AddRel(user, tune, typ) ) --user:sendPrivMsgFmtNoWin( AddRel(user, tune, typ) ) elseif Types[typ] == nil then SendPMMsg( hub, user, "I need to know the catagory to add it to!" ) --user:sendPrivMsgFmtNoWin( "I need to know the catagory to add it to!" ) else SendPMMsg( hub, user, "yea right, like i know what you got 2 add when you don't tell me!" ) --user:sendPrivMsgFmtNoWin( "yea right, like i know what you got 2 add when you don't tell me!" ) end return 1 elseif cmd == cmd5 then ReloadRel() SendPMMsg( hub, user, "Albums reloaded!" ) --user:sendPrivMsgFmtNoWin( "Albums reloaded!" ) return 1 end return 1 -- make bcdc++ forget the original message end end ) dcpp:setListener( "chat", "releases", function( hub, user, text ) local s = string.lower( text ) d,e,cmd,typ,tune = string.find(s, "^(%S+)%s*(%S*)%s*(.*)") if cmd == cmd2 then if typ == "" then SendPMMsg( hub, user, MsgAll ) --user:sendPrivMsgFmtNoWin( MsgAll ) return 1 elseif typ == "new" then SendPMMsg( hub, user, MsgNew ) --user:sendPrivMsgFmtNoWin( MsgNew ) return 1 elseif Types[typ] then SendPMMsg( hub, user, ShowRelType(typ) ) --user:sendPrivMsgFmtNoWin( ShowRelType(typ) ) return 1 end end end ) DC():PrintDebug( " ** Loaded freshstuff.lua **" )