PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: NightLitch on 03 November, 2003, 18:58:43

Title: -Kick-Bot- ( If you want it... )
Post by: NightLitch on 03 November, 2003, 18:58:43
This is my -Kick-Bot- with Counter on how many times a user have been kicked & banned....

Hope you guys like my creation....

Features:
----------------------------------------------------------------------
Commands:

!kick [reason]        -        Kick a User, reason optional
!ban [reason]        -        Ban a User, reason optional
!info        -        Show Info on User

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

!info:

show's

Nick
Ip
Level
Client & Version
Slots
Hubs
Speed
Mode
Share
Kicked
Banned


--=============================================--
--=  Kick-Bot 1.0
--=  By: NightLitch 2003
--= Grettings To: Tezlo for all the help
--= AND Guidence and learning me a
--= one or two to make me understand..
--= !kick [reason]    -   Kick user with reason
--= fixed some minor bugs...
--= Fixed The Kick command, Reason was needed to kick
--= but not now...
--= Added: !ban [reason], !showbans
--= Added: Set Prefix
--= Added: !info   -    Show Info On User
--= Removed Showbans & Showkicks
--= Fixed bug, send commands from another bot works now...
--= Changed The Data Arrival Code...
--=============================================--
kb = 1024
mb = kb*kb
gb = kb*kb*kb

Bot = "-Kick-Bot-"
Prefix = "!"

KICKCOUNT = {}

function Main()
frmHub:EnableSearchData(1)
frmHub:RegBot(Bot)
end

function DataArrival(user,data)
if( strsub(data, 1, 1) == "<" ) then
data=strsub(data,1,strlen(data)-1)
local _,_,cmd = strfind( data, "%b<>%s+(%S+)" )
if user.bOperator then
if (cmd == Prefix.."kick" ) then
doKick(user, data,cmd)
return 1
elseif (cmd == Prefix.."ban" ) then
doBan(user, data, cmd)
return 1
elseif (cmd == Prefix.."info" ) then
douserinfo(user,data)
return 1
end
end
end
end

function douserinfo(user,data)
local _,_,cmd,nick = strfind( data, "%b<>%s+(%S+)%s+(.+)" )
if not nick then
user:SendData(Bot,"Syntax: !info ")
return 1
end

local tUser = GetItemByName(nick)
if not tUser then
user:SendData(Bot,nick.." is not online or wrong name...")
return 1
end
user:SendData(Bot,"?????????????????????????????????????")
user:SendData(Bot,"User Info:")
user:SendData(Bot,"")
user:SendData(Bot,"Nick: "..nick)
user:SendData(Bot,"Ip: "..tUser.sIP)
local level = GetProfileName(tUser.iProfile)
if level == nil then level = "Unreg"
else
end
user:SendData(Bot,"Level: "..level)
local sClient, iShare, sSpeed, tFlags = doParseMyInfo(tUser.sMyInfoString)
if sClient == "d" then -- dcpp
user:SendData(Bot,"Client & Version: DC++ "..tFlags["V"])
elseif sClient == "o" then -- odc
user:SendData(Bot,"Client & Version: oDC "..tFlags["V"])
elseif sClient == "n" then --nmdcv2
user:SendData(Bot,"Client & Version: DC2 "..tFlags["V"])
elseif sClient == "f" then --Probably fakers
user:SendData(Bot,"Client & Version: Fake Client "..tFlags["V"])
elseif sClient == "g" then --dcgui
user:SendData(Bot,"Client & Version: DC Gui "..tFlags["V"])
elseif sClient == "u" then --Klients without tags
user:SendData(Bot,"Client & Version: DC1 or Client without TAG "..tFlags["V"])
end
user:SendData(Bot,"Slots: "..tFlags["S"])
user:SendData(Bot,"Hubs: "..tFlags["H"])
user:SendData(Bot,"Speed: "..sSpeed)
if tFlags["M"] == "A" then
user:SendData(Bot,"Mode: Active")
else
user:SendData(Bot,"Mode: Passive")
end
local i,j,temp = strfind(tUser.sMyInfoString, "$(%d+)%$")
Share = format("%0.2f", tonumber(temp)/gb)
user:SendData(Bot,"Share: "..Share.." Gb")
local KICKCOUNT, total = readkicks("kicks.dat")
if KICKCOUNT[nick] == nil then
user:SendData(Bot,"Kicked: 0")
else
user:SendData(Bot,"Kicked: "..KICKCOUNT[nick])
end
local KICKCOUNT, total = readkicks("bans.dat")
if KICKCOUNT[nick] == nil then
user:SendData(Bot,"Banned: 0")
else
user:SendData(Bot,"Banned: "..KICKCOUNT[nick])
end
user:SendData(Bot,"_____________________________________")
return 1
end

function doKick(user, data,cmd)
local _,_,cmd,nick,reason = strfind( data, "%b<>%s+(%S+)%s+(.+)" )
if not nick then
user:SendData(Bot,"Syntax: !kick [reason]")
return 1
end

local vUser = GetItemByName(nick)
if not vUser then
user:SendData(Bot,nick.." is not online or wrong name...")
return 1
end
if reason == nil then reason = "for no reason"
else reason = "because "..reason
end

local f = openfile("kicks.dat", "a")
if f then
write(f, nick.." "..vUser.sIP.." "..reason.."\r\n")
closefile(f)
end

vUser:SendData(Bot,"You are being KICKED by "..user.sName.." "..reason)
vUser:TempBan()

SendToAll(Bot,"User "..nick.." has been KICKED by "..user.sName.." "..reason)
return 1
end

function doBan(user, data,cmd)
local _,_,cmd,nick,reason = strfind( data, "%b<>%s+(%S+)%s+(.+)" )
if not nick then
user:SendData(Bot,"Syntax: !ban [reason]")
return 1
end

local vUser = GetItemByName(nick)
if not vUser then
user:SendData(Bot,nick.." is not online or wrong name...")
return 1
end
if reason == nil then reason = "for no reason"
else reason = "because "..reason
end

local f = openfile("bans.dat", "a")
if f then
write(f, nick.." "..vUser.sIP.." "..reason.."\r\n")
closefile(f)
end

vUser:SendData(Bot,"You are being BANNED by "..user.sName.." "..reason)
vUser:Ban()

SendToAll(Bot,"User "..nick.." has been BANNED by "..user.sName.." "..reason)
return 1
end
function readkicks(filename)
-- feed it a filename
-- returns an associative table with a kick-count for each user and a total kick-count

local file = openfile(filename, "r")
assert(file, "cant open "..filename)

local total, KICKCOUNT = 0, {} -- setup counter variables
local line = read(file, "*l") -- read first line
while line do
total = total+1 -- update total kick-count
local s, e, nick, ip, reason = strfind(line, "(%S-)%s(%S-)%s(.*)")
assert(s, "bad format on line "..total) -- shouldnt happen

KICKCOUNT[nick] = (KICKCOUNT[nick] or 0)+1 -- create/update users kick-count
line = read(file, "*l") -- read next line
end closefile(file)
return KICKCOUNT, total
end

function doParseMyInfo( sMyInfo )
local sClient = "u" -- undefined
local sIsDcPlusplus,c,sDTagInfo = strfind( sMyInfo, "^%$MyINFO %$ALL [^ ]+ [^$]*<%+%+ ([^$<>]+)>%$" )
local sIsDCGUI,c,sGTagInfo = strfind( sMyInfo, "^%$MyINFO %$ALL [^ ]+ [^$]*]+)>%$" )
local sIsNMDC2,c,sNTagInfo = strfind( sMyInfo, "^%$MyINFO %$ALL [^ ]+ [^$]*]+)>%$" )
local sIsOther,c,sSpeed,sShare = strfind( sMyInfo, "^%$MyINFO %$ALL [^ ]+ [^$]*%$ $([^$]+)[^$]%$[^$]*%$%s*(%d+)%$" )
local sTagInfo
local iShare = tonumber( sShare )
if sIsNMDC2 then
sTagInfo = sNTagInfo
sClient = "n" -- NMDC v2
elseif sIsDCGUI then
sTagInfo = sGTagInfo
sClient = "g" -- dcgui
elseif sIsDcPlusplus then
sTagInfo = sDTagInfo
local sIsOdc,c,sOdcTag = strfind( sMyInfo, "^%$MyINFO %$ALL [^ ]+ [^$]*")
local sFakeInfo = strfind( sMyInfo,"<%+%+ V:.*><%+%+ V:.*>")
if sFakeInfo then
sClient = "f" --Faking dc++ tag
elseif sIsOdc then
sClient = "o" -- oDC
else
sClient = "d" -- DC++
end
elseif sIsOther then
local sIsMLDC = strfind( sMyInfo, "mld" )
if sIsMLDC then
sClient = "m"
end
if sSpeed and iShare then
return sClient, iShare, sSpeed, nil
else
return sClient, nil, nil, nil
end
else
sClient = "f"-- fake
return sClient, nil, nil, nil
end
local tFlags = {}
sTagInfo = sTagInfo..","
gsub( sTagInfo, "(.):([^,]+),", function( letter, value ) %tFlags[letter] = value ; end )
if not tFlags["H"] or not tFlags["S"] or not tFlags["V"] or not tFlags["M"]then
sClient = "f" -- fake
return sClient, nil, nil, nil
end
if sClient == "n" then
tFlags["H"] = doGetHubNumber(tFlags["H"], 3)
elseif sClient == "d" then
tFlags["V"] = tonumber(tFlags["V"])
if tFlags["V"] and tFlags["V"] < 0.24 then
tFlags["H"] = doGetHubNumber(tFlags["H"], 1)
else
tFlags["H"] = doGetHubNumber(tFlags["H"], 3)
end
if tFlags["H"] < 0 then
sClient = "f"
end
elseif sClient == "g" then
tFlags["H"] = doGetHubNumber(tFlags["H"], 1)
elseif sClient == "o" then
iVersion = tonumber(tFlags["V"])
if iVersion < 0.24 then
tFlags["H"] = doGetHubNumber(tFlags["H"], 1)
else
tFlags["H"] = doGetHubNumber(tFlags["H"], 3)
end
local sIsOdc,c,sOdcTag = strfind(sMyInfo , "^%$MyINFO %$ALL [^ ]+ [^$]*")
tFlags["V"]=sOdcTag
if tFlags["H"] < 0 then
sClient = "f"
end
end
return sClient, iShare, sSpeed, tFlags
end

function doGetHubNumber(sHubTag, iHubCheckMethod)
local tHubs = {0}
local _,c = gsub( sHubTag, "(%d+)", function( x ) %tHubs[1] = %tHubs[1] + tonumber( x ) end, 3 )
if not (c == iHubCheckMethod) then tHubs[1] = 0 - tHubs[1] end
return tHubs[1]
end


Comments are welcome

Have a good one / NightLitch
Title: kickban
Post by: gizmo on 02 December, 2003, 11:49:52
can you put in

!kickban
!showpass
!reg for users

?
=))