Author Topic: Reg Online Check  (Read 2321 times)

0 Members and 1 Guest are viewing this topic.

Offline Highlander Back

  • Junior Member
  • **
  • Posts: 16
  • Karma: +0/-1
Reg Online Check
« on: 29 December, 2008, 00:13:45 »
Code: [Select]
--- Reg Online Check
-- Made by Madman
-- Requested by T?M??r?V?ll?R
-- Lua 5.1 version by C??o?y??

-- OBS! Script must be placed above script with the reg command

RegCmd = "regreg" -- Cmd you use to reg with
RegCmd2 = "regop"
DelCmd = "delonline" -- Delete user from online check
RegFile = "RegOnline.txt" -- Where to store the Onlinechecks
Bot = frmHub:GetHubBotName() -- Botname
SetTo = { [0] = 1, [1] = 1, [2] =1, [3] =1, [4] = 1, [5] = 1, [6] = 1,}

function Main()
local file = io.open(RegFile) -- There is a file?
if file then -- Yes
file:close() -- Good, close it
else -- Nope
local file = io.open(RegFile, "w+") -- Create it
file:write("tRegged = {\n}") -- Write Table in it
file:close() -- close it
end
frmHub:RegBot(Bot) -- Reg bot
LoadFromFile(RegFile) -- Load table from file
end

SendTo = function(msg)
local tProfiles = { [0] = 1, [1] = 1, [4] = 1, [5] = 1, [6] =1 }
for i, v in ipairs(frmHub:GetOnlineUsers()) do
if tProfiles[v.iProfile] and tProfiles[v.iProfile] == 1 then
v:SendPM(Bot, msg)
end
end
end

function ChatArrival(curUser, data)
local data = string.sub(data, 1, -2)
local s,e,cmd = string.find(data, "%b<>%s+[%!%+%?%#](%S+)")
if cmd then
local tCmds = {
[RegCmd] = function(curUser, data)
if SetTo[curUser.iProfile] == 1 then
local s,e,Nick = string.find(data, "%b<>%s+%S+%s+(%S+)") -- Get Nick
if Nick and not frmHub:isNickRegged(Nick) then -- We got Nick and Nick is not regged
Nick = string.upper(Nick)
if tRegged[Nick] == nil then -- If Nick not in table
tRegged[Nick] = {} -- Create
tRegged[Nick] = curUser.sName -- Add op who regs
SaveToFile(RegFile, tRegged, "tRegged") -- Save
else
tRegged[Nick] = curUser.sName
SaveToFile(RegFile, tRegged, "tRegged")
end
end
end
end,
[RegCmd2] = function(curUser, data)
if SetTo[curUser.iProfile] == 1 then
local s,e,Nick = string.find(data, "%b<>%s+%S+%s+(%S+)") -- Get Nick
if Nick and not frmHub:isNickRegged(Nick) then -- We got Nick and Nick is not regged
Nick = string.upper(Nick)
if tRegged[Nick] == nil then -- If Nick not in table
tRegged[Nick] = {} -- Create
tRegged[Nick] = curUser.sName -- Add op who regs
SaveToFile(RegFile, tRegged, "tRegged") -- Save
else
tRegged[Nick] = curUser.sName
SaveToFile(RegFile, tRegged, "tRegged")
end
end
end
end,
[DelCmd] = function(curUser, data)
if curUser.bOperator then
local s,e,Nick = string.find(data, "%b<>%s+%S+%s+(%S+)") -- Get Nick
if not Nick then -- No Nick
curUser:SendData(Bot, "I need a nick to delete from online check") return 1 --- Tell us
end
tNick = string.upper(Nick)
if not tRegged[tNick] then -- Got Nick but Nick was not in table
curUser:SendData(Bot, Nick.. " was not in online check") return 1
end
if tRegged[tNick] then -- Got Nick and was in table
tRegged[tNick] = nil -- But no more... ;)
SaveToFile(RegFile, tRegged, "tRegged") -- Save file
curUser:SendData(Bot, Nick.. " was deleted") return 1 -- Tell us that it was deleted
end
end
end,
}
if tCmds[cmd] then
return tCmds[cmd](curUser, data)
end
end
end

function NewUserConnected(curUser)
Nick = string.upper(curUser.sName)
if tRegged[Nick] then -- User is in table
SendTo(curUser.sName.. " Regged By " ..tRegged[Nick].. " Just Went Online For The First Time, Please Check His Share...!!!!!!") -- Pm Ops
SendPmToNick(Nick,Bot,"\r\n\tWelcome "..curUser.sName.." !!\r\n\tSeams this is your first login to "..frmHub:GetHubName().."\r\n\tWe hope you like your stay here   Remember to add this hub to youre fav hubs !!")
tRegged[Nick] = nil -- Delte user from table
SaveToFile(RegFile, tRegged, "tRegged") -- Save to file
end
end


-- Serialize by nErBoS
function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..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
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end

function LoadFromFile(filename)
local f = io.open(filename)
if f then
local r = f:read("*a")
f:flush()
f:close()
local func,err = loadstring(r)
if func then x,err = pcall(func) end
end
end



could this be converted to  new px  please

PtokaX forum

Reg Online Check
« on: 29 December, 2008, 00:13:45 »

Offline Madman

  • Scripter
  • Emperor
  • ******
  • Posts: 1 316
  • Karma: +75/-1
Re: Reg Online Check
« Reply #1 on: 29 December, 2008, 09:30:43 »
Code: [Select]
-- Reg Online Check 2.0
-- Made by Madman
-- Requested by T?M?†r?V?ll?R
-- Lua 5.1 version by C??o?y†?
-- API 2 Version 2.0 by Madman

-- OBS! Script must be placed above script with the reg command

-- Version 2.0
-- Changed: Supports multiple reg cmds
-- Changed: Settings now in tConfig table
-- Changed: SetTo is now UseCmds, and are useing true/false
-- Changed: SendTo function, updated and improved for api 2
-- Removed: RegCmd2 code
-- Removed: Unneeded code in regcmds code
-- Removed: Unnedded code in delcmd code

tConfig = {
RegFile = "RegOnline.txt", -- Where to store the Onlinechecks
RegCmds = {"regreg","regop","regmaster","addreguser"},
DelCmd = "delonline", -- Remove user from online check
Bot = SetMan.GetString(21), -- Bot name
UseCmds = { -- The users who are allowed to use the reg cmds
-- Also used for what profiles should recieve pm about newly connected user
[0] = true, -- Master
[1] = true, -- Operator
[2] = false, -- VIP
},
}

Path = Core.GetPtokaXPath().."scripts/" -- Standard path to files

function OnStartup()
local file = io.open(Path..tConfig.RegFile) -- There is a file?
if file then -- Yes
file:close() -- Good, close it
else -- Nope
local file = io.open(Path..tConfig.RegFile, "w+") -- Create it
file:write("tRegged = {\n}") -- Write Table in it
file:close() -- close it
end
Core.RegBot(tConfig.Bot,"Reg Online check","Dont@Have.Email",true)
LoadFromFile(Path..tConfig.RegFile) -- Load table from file
end

SendTo = function(msg)
for i,v in pairs(tConfig.UseCmds) do
if tConfig.UseCmds[i] then
Core.SendPmToProfile(i,Bot,msg)
end
end
end

function ChatArrival(user, data)
local data = data:sub(1, -2)
local s,e,cmd = data:find("%b<>%s+[%!%+%?%#](%S+)")
if cmd then
local tCmds = {
["fakedregcmd"] = function(user,data)
if tConfig.UseCmds[user.iProfile] then
local s,e,Nick = data:find("%b<>%s+%S+%s+(%S+)") -- Get nick
Nick = Nick:upper() -- Set nick to upper case
if tRegged[Nick] == nil then -- If Nick is not in table
tRegged[Nick] = user.sNick -- Add it and, add op who regged nick
SaveToFile(Path..tConfig.RegFile,tRegged,"tRegged")
end
end
end,
[DelCmd] = function(user, data)
if user.bOperator then
local s,e,Nick = data:find("%b<>%s+%S+%s+(%S+)") -- Get Nick
if Nick then
tNick = Nick:upper()
if tRegged[tNick] then -- and was in table
tRegged[tNick] = nil -- But no more... ;)
SaveToFile(RegFile, tRegged, "tRegged") -- Save file
Core.SendToUser(user, "<" ..Bot.. "> " ..Nick.. " was deleted") return true -- Tell us that it was deleted
else
Core.SendToUser(user, "<" ..Bot.. "> " ..Nick.. " was not in online check") return true
end
else -- No Nick
Core.SendToUser(user, "<" ..Bot.. "> I need a nick to delete from online check") return true --- Tell us
end
end
end,
}
-- Support multiple reg cmds
for i=1,table.maxn(tConfig.RegCmds) do
if tConfig.RegCmds[i] == cmd then cmd = "fakedregcmd" end
end
if tCmds[cmd] then
return tCmds[cmd](user, data)
end
end
end

function UserConnected(user)
Nick = string.upper(user.sNick)
if tRegged[Nick] then -- User is in table
SendTo(user.sNick.. " Regged By " ..tRegged[Nick].. " Just Went Online For The First Time, Please Check His Share...!!!!!!") -- Pm Ops
Core.SendPmToNick(user.sNick,Bot,"\r\n\tWelcome "..user.sNick.." !!\r\n\tSeams this is your first login to "..SetMan.GetString(0).."\r\n\tWe hope you like your stay here   Remember to add this hub to youre fav hubs !!")
tRegged[Nick] = nil -- Delte user from table
SaveToFile(RegFile, tRegged, "tRegged") -- Save to file
end
end

-- Serialize by nErBoS
function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..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
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end

function LoadFromFile(filename)
local f = io.open(filename)
if f then
local r = f:read("*a")
f:flush()
f:close()
local func,err = loadstring(r)
if func then x,err = pcall(func) end
end
end

Not tested but should work
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

Offline Highlander Back

  • Junior Member
  • **
  • Posts: 16
  • Karma: +0/-1
Re: Reg Online Check
« Reply #2 on: 29 December, 2008, 10:31:35 »
Thank you :)

Offline Highlander Back

  • Junior Member
  • **
  • Posts: 16
  • Karma: +0/-1
Re: Reg Online Check
« Reply #3 on: 02 January, 2009, 12:36:56 »
got a error here with restarting scripts

[12:32] Syntax E:\Private HuB\scripts\Reg Online Check.lua:85: table index is nil

Offline Madman

  • Scripter
  • Emperor
  • ******
  • Posts: 1 316
  • Karma: +75/-1
Re: Reg Online Check
« Reply #4 on: 03 January, 2009, 21:07:18 »
You are missing code... line 85 is
Code: [Select]
end, and that can't just return that
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

PtokaX forum

Re: Reg Online Check
« Reply #4 on: 03 January, 2009, 21:07:18 »