Luadch Example 0.03

Post finished Hubside Scripts here, known supporting hubsofts for LUA scripting.

ADCH++ | DCWatch | LUADCH
Locked
Toast

Luadch Example 0.03

Post by Toast » 24 Mar 2008, 21:15

Code: Select all

--[[

		example.lua v0.03 by blastbeat

]]--

local check_failed = function( user, rank )
	if not user:isRegged( ) or user:getRank( ) < rank then		
		return true			
	end
	return false
end

hub:setListener( "onLogin", { }, 								
	function( p )
		local user = p.user
		if user:supports( "UCMD" ) or user:supports( "UCM0" ) then
			if hub:getCfg( "nick_change" ) then
				user:send( "ICMD Nick\\sChange TTBMSG\\s%[mySID]\\s+nick\\\\s%[line:Nick]\\n CT1\n" )	--// send usercommand
			end
			if not check_failed( user, hub:getCfg "admin_rank" ) then 
				user:send( "ICMD Reg\\suser TTBMSG\\s%[mySID]\\s+reg\\\\s%[userCID]\\\\s%[line:Password]\\\\s%[line:Level]\\n CT2\n" )				
			end
		end
		return nil
	end

)

hub:setListener( "onBroadcast", { }, 								--// chatarrival..
	function( p )
		local user, cmd = p.user, p.cmd	
		local adc_msg = cmd:param( 3 )							--// text, adc formated
		local msg = hub:escapeFrom( adc_msg )						--// text, normal formated
		--hub:debug( "Escaped ADC msg: ", msg )						--// debugs to hub cl..
		--hub:debug( "Normal string: ", hub:escapeFrom( msg ) )	
		return nil	
	end
)

hub:setListener( "onBroadcast", { }, 									
	function( p )
		local user, cmd = p.user, p.cmd		
		local msg = hub:escapeFrom( cmd:param( 3 ) ) or ""				
		local command, parameters = utf.match( msg, "^[+!#](%a+) ?(.*)" )
		if command == "test" then
			user:reply{ msg = "Test ok.", from = hub:getBot( ) }
			return PROCESSED
		elseif command == "regcid" then
			if check_failed( user, hub:getCfg "op_rank" ) then user:reply{ msg = "You are not allowed to use this command.", from = hub:getBot( ) } return PROCESSED end				
			local cid, password, rank = utf.match( parameters, "^(%S+) (%S+) (%d+)" )
			rank = tonumber( rank )
			if not ( cid and password and rank ) then
				user:reply{ msg = "Usage: +regcid <cid> <password> <rank>", from = hub:getBot( ) }
				return PROCESSED
			end
			if user:getRank( ) < rank then
				user:reply{ msg = "Rank must be lower than " .. rank .. ".", from = hub:getBot( ) }
				return PROCESSED
			end		
			user:reply{ msg = hub:regUser{ cid = cid, hash = "TIGR", password = password, rank = rank }, from = hub:getBot( ) } 		
			return PROCESSED
		end
		return nil			
	end
)

hub:debug( "** Loaded example.lua **" )

Locked