Kick-Bot by: NightLitch
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Kick-Bot by: NightLitch

Started by NightLitch, 02 November, 2003, 00:05:52

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

NightLitch

Here's my Kick-Bot I have made with the Help from Tezlo... ThX m8

Bug fixed... :-)

*UPDATED AGAIN*

--=============================================--
--=  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
--= !show     -    Show many times user been kicked
--= fixed some minor bugs...
--= !show command can view offline users Count as well...
--= 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

/NightLitch
//NL

kepp

He he, Nice one!! :)
User was kicked by user for no reason :D

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

I may be wrong, but will that disconnect the user?

vUser:TembBan()
vUser:Disconnect()

SHould it not be like that?
Guarding    

BlazeXxX

vUser:TembBan()
vUser:Disconnect()

Wen u tempban a user, it actually disconnects from the min they get banned :) But yes, tht works.. I tested it and it works fine :)

NightLitch

Comment my Bot....

/NightLitch
//NL

tezlo

your bot blocks all other !commands.. why ?
and when a command is succesfull it shows in mainchat.. why ?

NightLitch

Take a look at it now...

Fixed The bug, but heh, but did not notice the bug so rewrote the Data Arrival so it became easier for me...

Maybe Tezlo you could tell me what was wrong... :-) plz...

function DataArrival(user, data)
if (strsub(data, 1, 1) == "<" ) then
return MAINCOMMAND(user, data)
end
end

function MAINCOMMAND(user, data)
	data=strsub(data,1,strlen(data)-1)

	_,_,cmd=strfind(data, "%b<>%s+(%S+)")
	if not cmd then cmd = "0" end
	if (strsub(cmd, 1, 1) ~= tSettings.PREFIXA and strsub(cmd, 1, 1) ~= tSettings.PREFIXB) then
		return 0
	else
		cmd = strlower(cmd)
		if strlen(cmd) > 1 then
			cmd=strsub(cmd,2,strlen(cmd))
			local COMMANDS = (userfunctions(user, data, cmd))
			if not COMMANDS then
				return 1
			else
				return COMMANDS
			end
		end
	end
end

/NightLitch
//NL

NightLitch

The Thing is, this code works great in my other scripts...

for Ex. my MasterBot...


/NightLitch
//NL

SMF spam blocked by CleanTalk