All pastes #525569 Raw Edit

Mine

public text v1 · immutable
#525569 ·published 2007-05-31 12:35 UTC
rendered paste body
-----------------------------------------
-----CrossfireBot by Hexxeh-----
-----------------------------------------

--Load socket library
require("socket")

--A few needed vars
hostname = "irc.gamesurge.net"
port = 6667
nick = "Crossfired"
user = "Crossfired . . :Crossfired"
lineendings = "\r\n"
version = 0.1
partmsg = "CrossfireBot "..version.." by Hexxeh"

--Create connection object
irc = socket.tcp()

function Connect()
	local sock, err = irc:connect(hostname,port)
	irc:send("USER "..user..lineendings)
	irc:send("NICK "..nick..lineendings)
	Main()
end

function Say(to,msg)
	irc:send("PRIVMSG "..to.." :"..msg..lineendings)
end

function Join(channel)
	irc:send("JOIN "..channel..lineendings)
end

function Part(channel)
	irc:send("PART "..channel.." :"..partmsg..lineendings)
	print("PART "..channel.." :"..partmsg..lineendings)
end

function Kick(kicknick, channel)
	irc:send("KICK "..channel.." "..nick.." :"..kicknick..lineendings)
end

function Explode(str,div)
  if (div=='') then return false end
  local pos,arr = 0,{}
  for st,sp in function() return string.find(str,div,pos,true) end do
	table.insert(arr,string.sub(str,pos,st-1))
	pos = sp + 1
  end
  table.insert(arr,string.sub(str,pos))
  return arr
end



function Parse(response)
	if string.sub(response,1,6) == "PING :" then
		print(response)
		local pong = string.gsub(response,"PING","PONG")
		print(pong)
		irc:send(pong..lineendings)
	elseif string.sub(response,1,17) == "NOTICE AUTH :*** " then
		local notice = string.gsub(response,"NOTICE AUTH :*** ","")
		print(notice)
	elseif string.find(response, "PRIVMSG "..nick.." :") ~= nil then
		local s,e = string.find(response, "PRIVMSG "..nick.." :")
		local msg = string.sub(response, e+1, string.len(response))
		_,start = string.find(response, ':')
		final,_ = string.find(response, '!', start)
		msgfrom = string.sub(response, start+1, final-1)
		print(msgfrom..": "..msg)
		if string.sub(msg,1,1) == "!" then
			ParseCommand(msgfrom,string.sub(msg,2,string.len(msg)))
		end
	elseif string.find(response, " PRIVMSG ") ~= nil then
		split1 = Explode(response,"@")
		split2 = Explode(split1[2], " ")
		channelfrom = split2[3]
		command = string.sub(split2[4],3,string.len(split2[4]))
		if string.sub(split2[4],2,2) == "!" then
			ParseCommand(channelfrom, command)
		end
	else
		print(response)
	end
end

function ParseCommand(from,command)
	if string.sub(command, 1, 7) == "version" then
		Say(from, "CrossfireBot version "..version)
	elseif string.sub(command, 1, 4) == "join" then
		local args = {}
		args = Explode(string.sub(command, 6, string.len(command))," ")
		for key, value in pairs(args) do
			Join(value)
		end
	elseif string.sub(command, 1, 4) == "part" then
		print(command)
		local args = {}
		args = Explode(string.sub(command, 6, string.len(command))," ")
		for key, value in pairs(args) do
			Part(value)
			print(value)
		end
	elseif string.sub(command, 1, 4) == "kick" then
		local args = {}
		args = Explode(string.sub(command, 6, string.len(command))," ")
		Kick(args[1],args[2])
		if args[3] then
			print("Too many args to !kick command.")
		end
	end
end

function Main()
	while true do
		local response = irc:receive("*l")
		Parse(response)
	end
end

Connect()