Conversion of Change Nick 1.0 LUA 5.0/5.1
 

Conversion of Change Nick 1.0 LUA 5.0/5.1

Started by rEALx, 12 May, 2008, 19:41:21

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

rEALx

Hi Mutor,

I would like to get this script converted to new API.
I tried it with the LUA API Converter.. but no luck, still gets errors.
thx

rEALx

--[[
 
	Change Nick 1.0 LUA 5.0/5.1
 
	By Mutor	10/12/06
 
	Requested by JueLz
 
	Allows users to change their own registered nick
	-Removes existing hub account , then adds new account
	-Maintains existing user password and profile
	-Provides context menu commands [right click]
 
 
 
	Change Nick Help
 
	Command		Description
	????????????????????????????????????????
	+nickhelp	Change Nick Help
	+changenick	Change Nick <new nick>
 
	????????????????????????????????????????
 
]]
 
NickCfg = {
-- Botname pulled from the hub or use "CustomName"
Bot = frmHub:GetHubBotName(),
-- Should bot have a key?
BotIsOp = 1,
--Bot description
BotDesc = "Nick Changer",
--Bot Email address
BotMail = "user@domain.com",
--Context Menu Title
Menu = frmHub:GetHubName(),
--Context Submenu Title
SubMenu = "Change Your Nick",
}
 
NickCmds = {
	changenick = function(user,data)
		if user then
			if user.iProfile ~= -1 and GetUserProfile(user.sName) then
				local s,e,newnick = string.find( data, "%b<>%s%p%w+%s(%S+)|$")
				local nick,pswd,prof = user.sName,frmHub:GetUserPassword(user.sName),user.iProfile
				if newnick then
					if nick and pswd and prof then
						DelRegUser(nick)
						AddRegUser(newnick,pswd,prof)
						if GetUserProfile(newnick) then
							return "New nick successfully set to: "..newnick..
							". Reconnect as "..newnick.." to effect the change."
						end
					end
				else
					return "Error!, Usage: "..frmHub:GetPrefixes()[1]..
					"changenick <newnick>"
				end
			end
		else
			return "Change Nick <new nick>"," %[line:New Nick Name]"," %[line:New Nick Name]"
		end
	end,
	nickhelp = function(user,data)
		if user then
			local reply = "Change Nick Help\n\n\tCommand\t\tDescription\r\n"..
			"\t"..string.rep("?",40).."\r\n"
			for i,v in pairs(NickCmds) do
				local desc,args = NickCmds[i]()
				reply = reply.."\t+"..string.format("%-15s",i).."\t"..desc.."\r\n"
			end
			return reply.."\n\t"..string.rep("?",40).."\r\n\r\n"
		else
			return "Change Nick Help","",""
		end
	end,
}
 
Main = function()
	if NickCfg.Bot ~= frmHub:GetHubBotName() or
		NickCfg.Bot == frmHub:GetHubBotName() and not frmHub:GetHubBot() then
		frmHub:NickBot(NickCfg.Bot, NickCfg.BotIsOp, NickCfg.BotDesc, NickCfg.BotMail)
	end
end
 
function NewUserConnected(user, data)
	if user.iProfile ~= -1 then --and CheckProfile(user.iProfile) then
		SendNickCmds(user)
		user:SendData(NickCfg.Bot, GetProfileName(user.iProfile).."'s change nick commands "..
		"enabled. Right click hub tab or user list for command menu.")
	end
end
OpConnected = NewUserConnected
 
ChatArrival = function(user, data)
	if user.iProfile ~= -1 then
		local s,e,to = string.find(data,"^$To:%s(%S+)%sFrom:")
		local s,e,cmd = string.find( data, "%b<>%s%p(%w+)")
		if cmd and NickCmds[cmd] then
			if to and to == NickCfg.Bot then
				user:SendPM(NickCfg.Bot,NickCmds[cmd](user,data))
			else
				user:SendData(NickCfg.Bot,NickCmds[cmd](user,data))
			end
			return 1
		end
	end
end
ToArrival = ChatArrival
 
SendNickCmds = function(user)
	for i,v in pairs(NickCmds) do
		local desc,arg1,arg2 = NickCmds[i]()
		user:SendData("$UserCommand 1 1 "..NickCfg.Menu.."\\"..NickCfg.SubMenu.."\\"..
		desc.."$<%[mynick]> +"..i..arg1.."&#38;#124;")
		user:SendData("$UserCommand 1 2 "..NickCfg.Menu.."\\"..NickCfg.SubMenu.."\\"..
		desc.."$$To: %[nick] From: %[mynick] $<%[mynick]> +"..i..arg2.."&#38;#124;")
		collectgarbage(gc)
	end
end


rEALx

Thx Mutor.. that was fast :D

Working well....

rEALx

SMF spam blocked by CleanTalk