PtokaX forum

Archive => Archived 5.0 boards => Finished Scripts => Topic started by: jiten on 24 March, 2005, 15:43:58

Title: Leech Bot
Post by: jiten on 24 March, 2005, 15:43:58
-- Lua 5 version by jiten (completely rewritten)
-- Removed: Unnecessary code;
-- Added: Profile x can (not) download from profile y table
-- Changed: Commands' structure to tables
-- Added: Immune users that can download from blocked nicks (requested by felix444) (1/1/2006)
-- Fixed: tImmune if
-- Changed: tIdxBlocked to allow connections between every profile by default (1/2/2006)

-- 100% Blocker by chill
-- Table Load and Save (added by nErBoS)

sBot = "LeechBot"

tBlocked = {}

-- File where the blocked nicks are stored
fBlock = "tBlock.tbl"

tImmune = {
-- [Blocked Uploader's Nick] = {
-- [Nick allowed to download from him]
-- },
["uploader"] = {
["downloader1"] = 1,
["downloader2"] = 1,
},
}

tIdxBlocked = {
-- [Downloader Profile Number] = {
-- [Uploader Profile Number] = 1 - Connection Blocked; 0 - Unblocked Connection
-- },

[0] = { [-1] = 0, [0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, },
[1] = { [-1] = 0, [0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, },
[2] = { [-1] = 0, [0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, },
[3] = { [-1] = 0, [0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, },
[4] = { [-1] = 0, [0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, },
[5] = { [-1] = 0, [0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, },
[-1] = { [-1] = 0, [0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, },
}

Main = function()
if loadfile(fBlock) then dofile(fBlock) end
end

ChatArrival = function(user,data)
local data = string.sub(data,1,-2)
if user.bOperator then
local s,e,cmd = string.find (data,"^%b<>%s+(%!%S+)")
if cmd and tCmds[cmd] then return tCmds[cmd](user,data),1 end
end
end

CTMArrival = function(user,data)
local sFind
if string.sub(data,1,4) == "$Rev" then sFind = "(%S+)|$" elseif string.sub(data,1,4) == "$Con" then sFind = "%S+%s+(%S+)" end
local s,e,nick = string.find(data,sFind)
-- (user is blocked and can't download? OR user's profile can download from nick's? OR nick is blocked and can't upload?) AND (can immune user download from blocked nick?)
if (tBlocked[string.lower(user.sName)] or tIdxBlocked[user.iProfile][GetItemByName(nick).iProfile] == 1 or tBlocked[string.lower(nick)]) then
if not (tImmune[string.lower(GetItemByName(nick).sName)] and tImmune[string.lower(GetItemByName(nick).sName)][string.lower(user.sName)]) then
user:SendData(sBot,"*** Error: You are not authorized to download from "..nick..".")
return 1
end
end
end

ConnectToMeArrival = CTMArrival
RevConnectToMeArrival = CTMArrival

tCmds = {
["!block"] =
function(user,data)
local s,e,nick = string.find(data,"%b<>%s+%S+%s+(%S+)")
if nick then
if tBlocked[string.lower(nick)] == 1 then
user:SendData(sBot,"*** Error: "..nick.." is already blocked.")
else
tBlocked[string.lower(nick)] = string.lower(user.sName) SaveToFile(fBlock,tBlocked,"tBlocked")
user:SendData(sBot,"*** "..nick.." is now blocked.")
end
else
user:SendData(sBot,"*** Syntax Error: Type !block <nick>")
end
end,
["!unblock"] =
function(user,data)
local s,e,nick = string.find(data,"%b<>%s+%S+%s+(%S+)")
if nick then
if tBlocked[string.lower(nick)] then
tBlocked[string.lower(nick)] = nil SaveToFile(fBlock,tBlocked,"tBlocked")
user:SendData(sBot,"*** "..nick.." is now unblocked.")
else
user:SendData(sBot,"*** Error: "..nick.." isn't blocked.")
end
else
user:SendData(sBot,"*** Syntax Error: Type !unblock <nick>")
end
end,
["!showblock"] =
function(user)
local msg = "\r\n\r\n".."\t"..string.rep("- -",20).."\r\n"
msg = msg.."\t\tCurrent Blocked Users:\r\n"
msg = msg.."\t"..string.rep("- -",20).."\r\n"
for v, i in tBlocked do msg = msg.."\t ? "..v.."\t blocked by "..i.."\r\n" end
user:SendData(sBot,msg)
end,
}

Serialize = function(tTable,sTableName,hFile,sTab)
sTab = sTab or "";
hFile:write(sTab..sTableName.." = {\n");
for key,value in tTable do
if (type(value) ~= "function") then
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
Serialize(value,sKey,hFile,sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
hFile:write(sTab.."\t"..sKey.." = "..sValue);
end
hFile:write(",\n");
end
end
hFile:write(sTab.."}");
end

SaveToFile = function(file,table,tablename)
local hFile = io.open(file,"w+") Serialize(table,tablename,hFile); hFile:close()
end
Title:
Post by: James on 30 June, 2005, 13:05:46
Hi
is possible to change this script in Dl @ Up Blocker ? for active @ passive User.

Thx in Advance
James
Title:
Post by: Dessamator on 30 June, 2005, 13:21:09
whaaat?, i didnt understand the request ! could u explain it?
Title:
Post by: Krysalis on 30 June, 2005, 15:52:10
I think he means blocking download and upload separately.

Now there is
!block
!unblock

he wants

!blockup
!blockdown

!unblockup
!unblockdown

i think

Greets
Title:
Post by: James on 30 June, 2005, 17:23:00
Sorry !!! my bad english..speak only german ,french or romanian ...

i thought that this is only a download blocker but it's an upload blocker too. Now its all right.
but i thank you all for your help!-)))

James
Title:
Post by: chettedeboeuf on 15 August, 2005, 13:53:15
Hi !
Is it possible to have reason with '!block' command ??
And with the list the reasan should appear

Thank you
Title:
Post by: yoonohoo on 19 August, 2005, 14:03:52
What about adding a rightclick command with a line for the reason?
Thanx
Title:
Post by: Dessamator on 19 August, 2005, 16:32:32
Do it yourself, check the howto section !
Title:
Post by: yoonohoo on 20 August, 2005, 05:06:30
Hey Dessamator
I'm very grateful 4 all your help in the past, present and maybe future but no need 2b so harsh...
If the
QuoteDo it yourself, check the howto section !
was 4 me see my sig!
Been there, tried, even managed to create the raw cmd (i think thats what you call it)"$UserCommand 1 3 Block User$<%[mynick]> !block %[line:nick] %[line:reason]|" that was easy anyway just copied from another script and changed the command word and add or take the lines, so I could have this also $UserCommand 1 2 Block User$<%[mynick]> !block %[line:reason]|" But the shite hits the fan when it gets to the functions and the variables? and everything else but the raws.
So thats why I come and seek 4 help in this forum. If I could I would have done it and not seek for help (can only talk, write, 4 myself)...It would give me much more pleasure!
Title:
Post by: Dessamator on 20 August, 2005, 20:31:33
Well, uve done most of it, and i wasnt being harsh, its isnt really hard to create right click, u just need to copy and paste one of the right click scripts, and change what u need.

either way all u need now is a function, in this case :

function OpConnected(user)
user:SendData("$UserCommand 1 3 Block User$<%[mynick]> !block %[line:nick] %[line:reason]|")

end


You can add the other commands using the same syntax , good luck.
Title: Re: Leech Bot
Post by: jiten on 01 March, 2006, 17:31:24
First post updated with the most recent Leech Bot code.