Profile Update 1.0 [LUA 5.1] [API2]
 

Profile Update 1.0 [LUA 5.1] [API2]

Started by Ravage, 20 September, 2009, 21:20:08

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ravage

Hey dudes and dudettes   ;D

Here is my very first script that i made for Ptoka. Dunno, if this was allready made or sth.,
i needed some simple tool that allows me to handle with my regged users profiles,
so i made this one.

According to that, sometime ago i`ve started to learn how to script, so this was also an
opportunity to learn from it. At this point big thx to CrazyGuy for helping me find some
serious bugs in the earlier version of this Script and special thx to Mutor for helping
me out with some cool solutions when i got stuck sometimes.

Have fun with it, comments are welcome!

--[Edit]--[Script Updated 29-09-2009]--
--[[
		____________________________________
		????????????????????????????????????
			  LUA 5.1 [API2]
			
		    --- Profile Update 1.1 --- 
			  
		       By Ravage   20-09-2009 
		____________________________________	
		????????????????????????????????????
	-This script provides commands to change profile of regged users.
	
	-'Get Prof Names in table function' by Mutor (Thx a bunch, for help!)
		
	====[ Description Ver. 1.0 ]============================
	[->] Changes Profile of a regged user per command
	[->] Gets profile from regged user
	[->] Shows all Profiles that are set in Hubsoft
	[->] RightClick command Option enabled
	[->] Optional, notifies online user about Profile Update
	[->] Optional, notifies about Profile Update in OpChat
	--------------------------------------------------------
	
	====[ Description Ver. 1.1 ]============================
	[+] Added: Improved Perm. Control for changeprof Command
	[+] Added: Extended Function to Profile Permission table
	--------------------------------------------------------
	
	====[ Available Commands Ver. 1.0 ]==============================
	[->] !changeprof <username> <profile>  --// change user`s profile
	[->] !getprof <username>                  --// get user`s profile
	[->] !getprofall              --// Show available Profiles in hub
	-----------------------------------------------------------------	
]]

tCfg = {
----[Bot Configuration]--------------------------------

-- Enter Bot`s name here, leave "", for default Hub Bot
sBotname = "-[ProfileUpdate]-",

-- Bot Description
Desc = "Ver 1.1", 

-- Bot Email
Email = "",

-- Reg Bot as OP. Bot is OP = true, / is not OP = false,
Key = true,

----[Notification Confgr.]-----------------------------

-- Notify about Prof. Updates in OPchat
OpNtf = false,

-- Notify the user about Profile update, if online
UsrNtf = false,

----[Command Config.]----------------------------------

-- change user`s profile
CmdProf = "changeprof", 

-- get user`s profile
CmdGtPr ="getprof",

-- Show available Profiles in hub
CmdShwPrf = "getprofall",

----[Rightclick Config.]-------------------------------

-- UserCommands available in Context Menu? (Rightclick)
RgClk = true,

-- Main Menu Name
menu = "Profile Update",

----[Profile Command Permission]-----------------------

-- '2' can update any profile (Use this ONLY for Admin)
-- '1' can update lower profile, only
-- '0' No command permission / Disabled
-- Set your permission profiles here:

Profiles = {
	[0] = 2,	-- Admin / Master
	[1] = 1,	-- OP
	[2] = 0,	-- VIP
	[3] = 0,	-- Reg
	},
}

--===================================================--
           --[End of Configuration Line]--
          --[Do not change anything below]--
--===================================================--
OnStartup = function()
	if tCfg.sBotname == "" then
		local Bta = SetMan.GetString(21)
		if Bta then botname = Bta
		end
	else
		local Btb = tCfg.sBotname
		if Btb then botname = Btb
		end
	end
		Core.RegBot(botname, tCfg.Desc, tCfg.Email, tCfg.Key)
		fncStart()
		tProfs = {}
		prx = SetMan.GetString(29)
		prxtab = string.sub(prx, 1, 1)
		profiles = "" 
	for i,v in ipairs(ProfMan.GetProfiles()) do 
		profiles = profiles..v.sProfileName.." / " end
	for i,v in ipairs(ProfMan.GetProfiles()) do
		tProfs[v.sProfileName] = v.iProfileNumber
	end
end

fncStart = function()
Core.SendToAll("<"..botname.."> Profile Update Ver. 1.1 by Ravage has been started|")
end

UserConnected = function(user)
UserCmds(user)
end

RegConnected,OpConnected = UserConnected,UserConnected

ChatArrival = function(user,data)
local _,_,pfx  = string.find(data,"^%b<>%s+(["..prx.."])")
local _,_,cmd  = string.find(data,"^%b<>%s+["..prx.."](%w+)")
local _,_,sUsr = string.find(data,"^%b<>%s+["..prx.."]%w+%s+(%S+)")
local _,_,sPrf = string.find(data,"^%b<>%s+["..prx.."]%w+%s+%S+%s+(%S+)|")
local iPerm = tCfg.Profiles[user.iProfile]
	if pfx then		
		if cmd == tCfg.CmdProf then
			if not sUsr or not sPrf then
				Core.SendToUser(user,"<"..botname.."> Wrong command usage. "..
				"Syntax is: !changeprof <nickname> <profilename>|")
				return true
			else
				if iPerm == 1 or iPerm == 2 then
					GetUserInfo(user, sUsr, sPrf, iPerm)
					return true
				else
					Core.SendToUser(user,"<"..botname.."> You have no permission to use this command|")
					return true
				end
			end
		end
		if cmd == tCfg.CmdGtPr then
			if iPerm == 1 or iPerm == 2 then
				GetProf(user, sUsr, prof)
				return true
			else
				Core.SendToUser(user,"<"..botname.."> You have no permission to use this command|")
				return true
			end
		end
		if cmd == tCfg.CmdShwPrf then
			if iPerm == 1 or iPerm == 2 then
				Core.SendToUser(user,"<"..botname.."> Hub`s available Profiles are: "..profiles.."|")
				return true
			else
				Core.SendToUser(user,"<"..botname.."> You have no permission to use this command|")
				return true
			end
		end
	end
end

GetUserInfo = function(user, sUsr, sPrf, iPerm)
	if RegMan.GetReg(sUsr) then
		if sUsr then 
			if sPrf then				
				local Profs = tProfs						
				if Profs[sPrf] then
					ProfNmbr = Profs[sPrf]
					local tab = RegMan.GetReg(sUsr)
					local prof = ProfMan.GetProfile(tab.iProfile).sProfileName
					PermChk(user, sUsr, ProfNmbr, prof, sPrf, iPerm)
				else
					Core.SendToUser(user,"<"..botname.."> No such profile name "..
					"as: '"..sPrf.."' available, "..
					"please make sure, you have typed the correct profile name.|")
				end 
			end			
		end
	else
		Core.SendToUser(user,"<"..botname.."> The user: "..
		""..sUsr.." couldn`t be found in the registry|")
		return true
	end
end

PermChk = function(user, sUsr, ProfNmbr, prof, sPrf, iPerm)
	if iPerm == 2 then
		ProfUpd(user, sUsr, ProfNmbr, prof, sPrf)
	end
	if iPerm == 1 then
	local tab = RegMan.GetReg(sUsr)
	local iProf = tab.iProfile
		if user.iProfile > iProf then
			Core.SendToUser(user,"<"..botname.."> ***Error, "..
			"Command restricted. User "..sUsr.." has a higher "..
			"profile than you. |")
		else
			if user.iProfile == iProf then
				Core.SendToUser(user,"<"..botname.."> Do you "..
				"really wanna change your own profile by "..
				"yourself? Please ask the Admin first. |")
			else
				if user.iProfile >= ProfNmbr then 
					Core.SendToUser(user,"<"..botname.."> ***Error, ".. 
					"Command restricted. You cannot use profiles "..
					"that are equal or higher than your profile |")
				else
					ProfUpd(user, sUsr, ProfNmbr, prof, sPrf)
				end
			end
		end
	end		
end

ProfUpd = function(user, sUsr, ProfNmbr, prof, sPrf)
	if sUsr then
		local pwd = RegMan.GetReg(sUsr).sPassword
		RegMan.ChangeReg(sUsr, pwd, ProfNmbr)
		Core.SendToUser(user,"<"..botname.."> *** User`s profile "..
		"has been updated to: "..sPrf.." |")
		if tCfg.OpNtf == true then NotfOp(user ,prof ,sUsr) end
		if tCfg.UsrNtf == true then	NotfUsr(user, sUsr, prof) 
			if Core.GetUser(sUsr) then
				Core.SendToUser(user,"<"..botname.."> *** User "..
				"has been informed about Profile Change|")
			else
				Core.SendToUser(user,"<"..botname.."> User is not online!|")
			end
		end
	else
	Core.SendToUser(user,"<"..botname.."> Error, missing Argument!|")
	return true
	end
end

GetProf = function(user, sUsr, prof)
local sUsr = string.sub(sUsr, 1, -2)
local sTabUsr = RegMan.GetReg(sUsr)
	if sTabUsr then
		local tab = RegMan.GetReg(sUsr)
		local prof = ProfMan.GetProfile(tab.iProfile).sProfileName
			Core.SendToUser(user,"<"..botname.."> "..sUsr.."`s profile is: '"..prof.."'|")
	else
		Core.SendToUser(user,"<"..botname.."> "..sUsr.." is not a registered user.|")
	end
end

NotfUsr =function(user, sUsr, prof)
local tab = RegMan.GetReg(sUsr)
local newprf = ProfMan.GetProfile(tab.iProfile).sProfileName
local nick = Core.GetUser(sUsr)
	if nick then
		local PmMsg = " "..sUsr..", Your old profile: "..
		"'"..prof.."' has been changed to profile: "..
		"'"..newprf.."' by "..user.sNick.."."
		Core.SendPmToUser(nick, botname, PmMsg)
	end
end

NotfOp = function(user ,prof ,sUsr)
local tab = RegMan.GetReg(sUsr)
local newprf = ProfMan.GetProfile(tab.iProfile).sProfileName
local opchat = SetMan.GetString(24)
		Core.SendPmToOps(opchat, "<"..botname.."> The profile of"..
		" user: "..sUsr.." has been updated from '"..prof.."'"..
		" to the new profile: '"..newprf.."' by "..user.sNick.."|")
end

function UserCmds(user, sUsr)
local iUsrCmd = tCfg.Profiles[user.iProfile]
	if iUsrCmd == 1 or iUsrCmd == 2 then
		if tCfg.RgClk == true then
			Core.SendToUser(user,"$UserCommand 1 3 |")
			Core.SendToUser(user,"$UserCommand 1 3 "..tCfg.menu.."\\ Get User`s Profile$<%[mynick]> "..prxtab..""..tCfg.CmdGtPr.." %[nick]&#124;|")
			Core.SendToUser(user,"$UserCommand 1 3 "..tCfg.menu.."\\ Change Profile$<%[mynick]> "..prxtab..""..tCfg.CmdProf.." %[nick] %[line:Enter Profile: "..profiles.."]&#124;|")
			Core.SendToUser(user,"$UserCommand 1 3 "..tCfg.menu.."\\ Show all Profiles$<%[mynick]> "..prxtab..""..tCfg.CmdShwPrf.."&#124;|")
		end
	end
end
Classic Rock to Modern Metal
metal-unity.no-ip.org:980
Join Us!

DeAn

Nice approach Ravage.. I think if there was a limit of share for particular profiles, so after exceeding that share limit the user automatically switches to the next profile.. For example if the minimum share limit for VIP profile is 100 GB and when a user of reg profile exceeds above 100 GB share, he automatically switches to VIP profile.

A message could be sent to that user "Congrats buddy, you are now switched to VIP Profile as you have crossed the minimum share limit for VIP profile.

I would be thankful if such an addon would be added to this script..



Thanks in advance,
DeAn
Thanks,

DeAn

TZB

This scripts good but why such a update.
OK if its updated then the scriptor will have to add the reverser also if the profile lowers share less than 100GB then back to Reg.
Don't you think the script will make the hub Master's a bit lazy? The Master has to just on the script and sit and all the work done by script. :P
Not against the update but its best to have VIP's and OP's on Hub whom you know.Rather than classify them on share basis but even if its done it should be done manually or else there are clients by which user can increase their share by using fake share clients and get themselves a  updated profile.
Its all my own views.Nothing personal.

Yahoo

"BoRN FIGhTEr"

Ravage


Hey ppl. I was working on the script again and made some changes to it, due some security reasons.
I have noticed that in the Version 1.0 , any user, that the 'changeprof' command is given to, was
able to change the profile from any user to any profile, even his own.

So in case one of your Ops has updated himself to an Admin 'accidently',
do not panic and blame me instead.  ;D

Script Version 1.0 is no longer available, and has been replaced to Version 1.1.
The new version has a better permission handling now, see the description below.
----[Profile Command Permission]-----------------------

-- '2' can update any profile (Use this ONLY for Admin)
-- '1' can update lower profile, only
-- '0' No command permission / Disabled
-- Set your permission profiles here:

Profiles = {
	[0] = 2,	-- Admin / Master
	[1] = 1,	-- OP
	[2] = 0,	-- VIP
	[3] = 0,	-- Reg
	},
}


If the value '2' is set to the command permission table, then, as the description above describes,
any profile from any user can be changed

if value '1' is set, then profiles can only be changed from users with lower profile. If this
hierarchy structure is affected then it will be mentioned by messages as follow...
<-[ProfileUpdate]-> ***Error, Command restricted. You cannot use profiles that are equal or higher than your profile.

<-[ProfileUpdate]-> ***Error, Command restricted. User [OP]TestOp has a higher profile than you. 

<-[ProfileUpdate]-> Do you really wanna change your own profile by yourself? Please ask the Admin first.


I hope this let you slumber calmly.
Enjoy, reports are welcome!

greets,
Ravage
Classic Rock to Modern Metal
metal-unity.no-ip.org:980
Join Us!

atonal

well the scripts is good, for me is bether one hub working with only scripts
is becase to many OP, master are lazy,

my request is more security scripts and less OP and master in to Hub?s

ejempl:  if one user broke the rules bunnnn out kick from  security script,  lol

Most the time  OP or master are sleeping, lol

Recewinds  is good i block stuped Many Old dc
and fani nicks

well brother thanks for all scripts beutifull i habe in to Recewinds, habe good day

DeAn

I think you are right TZB, but that addon can be only put till VIP profile. Not more than that.. As atonal said,
QuoteMost the time  OP or master are sleeping, lol
;D
I think still it would be better if that addon could be added till profile VIP.


Thanks In Advance
DeAn
Thanks,

DeAn

Ravage

Quote
I think still it would be better if that addon could be added till profile VIP.

Hi DeAn,

Regarding your earlier request, i think as a matter of principle, it is
a bad idea to benefit somebody just because of the amount of share.
Besides, as some people mentioned, it is neither guaranteed if a specific user
can hold his share after his update, nor if the users share is gonna meet
your expecrtations at all.

I have started to work on something similiar to your request, some days ago.
The auto profile update itself will be based on something different than
the amount of share.

In consideration of that I?m still a learning script noob, it will take some
time until some functions will work, but i promise to come up  with
something soon, or Leastwise, i am trying.

greets,
Ravage
Classic Rock to Modern Metal
metal-unity.no-ip.org:980
Join Us!

DeAn

Thank you very much Ravage.. I'll be looking forward for that.



Thanks In Advance
DeAn
Thanks,

DeAn

SMF spam blocked by CleanTalk