determinate determinate

Author Topic: NickPrefix 1.0 LUA 5.1x [Strict] [API 2]  (Read 1305 times)

0 Members and 1 Guest are viewing this topic.

Offline Mutor

  • Global Moderator
  • Forum God
  • *****
  • Posts: 3 854
  • Karma: +395/-18
  • To err is human, to arr is pirate...
    • PxDev
NickPrefix 1.0 LUA 5.1x [Strict] [API 2]
« on: March 20, 2008, 04:48:07 am »
Code: [Select]
--[[

NickPrefix 1.0 LUA 5.1x [Strict][API 2]

By Mutor 03/07/08

Set a prefix to your nick in main chat [alpha-mumeric values only]
plop had done this yet I don't think he ever released it. Here's my
take on it. Perhaps you'll find it as uselesly fun as I do

- Automatically moves this script to end of list [to avoid conflicts]
- Provides context menu [right click]
- Saves to file for hub/script restarts
- Option for minimum maximum prefix character limit


]]

--//--
-- Botname pulled from the hub or use "CustomName"
local Bot = SetMan.GetHubBot().sNick
-- Admins nick for status / error messages
local OpNick = "Mutor"
-- Script command, no prefix [Listens for any valid hub command prefix]
local pfxcmd = "prefix"
--Set your profiles / permissions here.
-- [#] = true/flase, (true = Command Enabled / false = Command Disabled)
local Profiles = {
[-1] = false, --Unregistered User
[0] = true, --Master
[1] = true, --Operator
[2] = true, --Vip
[3] = true, --Registered User
}
local File = "prefixes.dat"
-- Nick prefix ["UserName"] = "prefix"
Prefixes = {
["Mutor"] = "Scripter",
}
-- Minimum number of characters required for prefix [1 - 5]
local MinChar = 3
-- Maximum number of characters allowed for prefix [5 - 35]
local MaxChar = 35
--//--

local Scp = "NickPrefix 1.0 L5.1.lua"
OnStartup = function()
if loadfile(File) then
dofile(File)
else
SaveFile(File,Prefixes,"Prefixes")
end
local t = ScriptMan.GetScripts()
if next(t) and t[#t].sName:lower() ~= Scp:lower() then
while ScriptMan.MoveDown(Scp) do ScriptMan.MoveDown(Scp) end
SetMan.Save()
end
MinChar = math.max(math.min(MinChar,5),1)
MaxChar = math.min(math.max(MaxChar,5),35)
end

UserConnected = function(user)
if Profiles[user.iProfile] then
local p,s = Prefixes[user.sNick],""
if p then s = " ("..p..")" end
local Pfx = SetMan.GetString(29):sub(1,1)
local uc = "$UserCommand 1 1 "..SetMan.GetString(0).."\\"..Scp:gsub(" .+","").."\\Set Prefix"..s..
"$<%[mynick]> "..Pfx..pfxcmd.." %[line:Nick Prefix (Leave Blank To Clear Prefix)]&#124;|"
Core.SendToUser(user,uc)
end
end
OpConnected, RegConnected = UserConnected,UserConnected

ChatArrival = function(user,data)
if Profiles[user.iProfile] then
local _,_,cmd = data:lower():find("^%b<> ["..SetMan.GetString(29).."](%a+)")
local spc = string.char(160)
if cmd then
if cmd:lower() == pfxcmd then
local _,_,pfx = data:find("^%b<> %p%a+ ([ %w]+)|$")
local _,_,input = data:find("^%b<> %p%a+ ([^|]+)|$")
if pfx then
if pfx:len() > MinChar then
if pfx:len() < MaxChar then
Prefixes[user.sNick] = pfx:gsub(" ",spc)
SaveFile("prefixes.dat",Prefixes,"Prefixes")
Core.SendToUser(user,"<"..Bot.."> Your prefix is "..
"now set to "..Prefixes[user.sNick].."|")
else
Core.SendToUser(user,"<"..Bot.."> Error. "..pfx.." is too long a prefix.|")
end
else
Core.SendToUser(user,"<"..Bot.."> Error. "..pfx.." is too short a prefix.|")
end
else
if input then
return Core.SendToUser(user,"<"..Bot.."> "..input..
" contains invalid characters..|"),true
end
Prefixes[user.sNick] = nil
SaveFile("prefixes.dat",Prefixes,"Prefixes")
Core.SendToUser(user,"<"..Bot.."> Your prefix has been cleared.|")
end
return true
end
else
local p = Prefixes[user.sNick]
if p then
local d,c = data:gsub("^%<","<"..p..spc)
if c then return Core.SendToAll(d),true end
end
end
end
end

OnError = function(msg)
local user = Core.GetUser(OpNick)
if user then
Core.SendToUser(user,"<"..Bot.."> "..msg.."|")
end
end
SaveFile = function(file,table, tablename )
local hFile = io.open (file , "wb")
Serialize(table, tablename, hFile)
hFile:close()
end

Serialize = function(tTable, sTableName, hFile, sTab)
sTab = sTab or "";
hFile:write(sTab..sTableName.." = {\n" )
for key, value in pairs(tTable) do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key)
if(type(value) == "table") then
Serialize(value, sKey, hFile, sTab.."\t")
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value)
hFile:write( sTab.."\t"..sKey.." = "..sValue)
end
hFile:write( ",\n")
end
hFile:write( sTab.."}")
end
« Last Edit: July 10, 2010, 04:05:04 am by Mutor »
Respectfully,

Mutor

=-=-=-=-=-=-=-==-=-=-=
[ Ptokax Admins Hub ] Ptokax Help Hub
[ Mutor's Ptokax Archive Website ] Scripting Forum
[ Dynamic Downloads ] API 2
[ Microsoft IIS serving PxWeb 1.0d ] API 2
[ WebReg 1.1.2.0 ] Web Based Hub Reg

Offline uffetjur

  • Lord
  • ***
  • Posts: 299
  • Karma: +4/-0
Re: NickPrefix 1.0 LUA 5.1x [Strict] [API 2]
« Reply #1 on: March 20, 2008, 01:48:39 pm »
- Automatically moves this script to end of list [to avoid conflicts]
 

if you use this function in 2 scripts, wouldnt that lead to a conflict?
Somewhere in Cyberspace

Offline Mutor

  • Global Moderator
  • Forum God
  • *****
  • Posts: 3 854
  • Karma: +395/-18
  • To err is human, to arr is pirate...
    • PxDev
Re: NickPrefix 1.0 LUA 5.1x [Strict] [API 2]
« Reply #2 on: March 20, 2008, 09:59:29 pm »
Well I suppose if you did use this function in two separate scripts
and then set the file names accordingly they could do battle.
I'm more about making things work than making them fail.

If you're really interested in crashing your hub I can give you
just one line of code to do so. Hey don't run with scissors either.
« Last Edit: March 21, 2008, 11:02:44 am by Mutor »
Respectfully,

Mutor

=-=-=-=-=-=-=-==-=-=-=
[ Ptokax Admins Hub ] Ptokax Help Hub
[ Mutor's Ptokax Archive Website ] Scripting Forum
[ Dynamic Downloads ] API 2
[ Microsoft IIS serving PxWeb 1.0d ] API 2
[ WebReg 1.1.2.0 ] Web Based Hub Reg

Offline uffetjur

  • Lord
  • ***
  • Posts: 299
  • Karma: +4/-0
Re: NickPrefix 1.0 LUA 5.1x [Strict] [API 2]
« Reply #3 on: March 21, 2008, 09:15:28 am »
rofl welll we all know how to crash a hub dont we
Somewhere in Cyberspace

Offline Mutor

  • Global Moderator
  • Forum God
  • *****
  • Posts: 3 854
  • Karma: +395/-18
  • To err is human, to arr is pirate...
    • PxDev
Re: NickPrefix 1.0 LUA 5.1x [Strict] [API 2]
« Reply #4 on: March 21, 2008, 11:03:50 am »
Added bad prefix char reply and a bug fix, script updated
Respectfully,

Mutor

=-=-=-=-=-=-=-==-=-=-=
[ Ptokax Admins Hub ] Ptokax Help Hub
[ Mutor's Ptokax Archive Website ] Scripting Forum
[ Dynamic Downloads ] API 2
[ Microsoft IIS serving PxWeb 1.0d ] API 2
[ WebReg 1.1.2.0 ] Web Based Hub Reg

Offline Jaxx89

  • Member
  • ***
  • Posts: 40
  • Karma: +0/-0
Re: NickPrefix 1.0 LUA 5.1x [Strict] [API 2]
« Reply #5 on: July 10, 2010, 02:13:53 am »
somehow the context menu is not working
and it works only if the users add it themselves

adding the nicks to the prefixes.dat file dint work

cant the HUB admin set it as per profile??????

Offline Mutor

  • Global Moderator
  • Forum God
  • *****
  • Posts: 3 854
  • Karma: +395/-18
  • To err is human, to arr is pirate...
    • PxDev
Re: NickPrefix 1.0 LUA 5.1x [Strict] [API 2]
« Reply #6 on: July 10, 2010, 04:12:27 am »
That's not what this is, it's Nick Prefix, not Profile Prefix.
There is nothing wrong with the context menus, you're
probably looking for it on the user list, it's on the hub tab.
Respectfully,

Mutor

=-=-=-=-=-=-=-==-=-=-=
[ Ptokax Admins Hub ] Ptokax Help Hub
[ Mutor's Ptokax Archive Website ] Scripting Forum
[ Dynamic Downloads ] API 2
[ Microsoft IIS serving PxWeb 1.0d ] API 2
[ WebReg 1.1.2.0 ] Web Based Hub Reg

Offline Mutor

  • Global Moderator
  • Forum God
  • *****
  • Posts: 3 854
  • Karma: +395/-18
  • To err is human, to arr is pirate...
    • PxDev
Re: NickPrefix 1.0 LUA 5.1x [Strict] [API 2]
« Reply #7 on: July 25, 2010, 10:05:31 pm »
Respectfully,

Mutor

=-=-=-=-=-=-=-==-=-=-=
[ Ptokax Admins Hub ] Ptokax Help Hub
[ Mutor's Ptokax Archive Website ] Scripting Forum
[ Dynamic Downloads ] API 2
[ Microsoft IIS serving PxWeb 1.0d ] API 2
[ WebReg 1.1.2.0 ] Web Based Hub Reg

Offline vaibhavg88

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Re: NickPrefix 1.0 LUA 5.1x [Strict] [API 2]
« Reply #8 on: December 02, 2011, 04:37:54 pm »
thanx

 

determinate determinate