Author Topic: Membercount  (Read 2584 times)

0 Members and 1 Guest are viewing this topic.

Offline Yahoo

  • Triple Ace
  • **
  • Posts: 225
  • Karma: +32/-14
  • People Say "I Dont Know English"
    • Yahoo
Membercount
« on: 19 July, 2010, 19:33:18 »
Is it possible for someone to convert this script to latest API. It will be great

Code: [Select]
-- Member Count
-- Made by Madman
-- Requested by SwapY
-- Small bugfix, report by Markitos
-- Small changes by NL

Members = {}

function Main()
-- Make file
local file = io.open("Members.dat")
if file then
file:close()
else
local file = io.open("Members.dat", "w+")
file:write("Members = {\n}")
file:close()
end
-- Load file
LoadFromFile("Members.dat")
end

function ChatArrival(curUser, data)
local data = string.sub(data, 1, -2)
local s,e,cmd = string.find(data, "%b<>%s+[%!%+%?%#](%S+)")
if cmd == "membercount" then -- find cmd
SendToAll(data)
local RegC, OnlineC, ActiveC, vCount = 0,0,0,0
for count,_ in pairs(frmHub:GetRegisteredUsers()) do -- Get regged users
RegC = count -- RegC is count
end
for count,oUser in pairs(frmHub:GetOnlineRegUsers()) do -- Get online reg users
OnlineC = count
if oUser.bActive then -- If user is Active
-- Add to table
if Members[oUser.sName] == nil then
Members[oUser.sName] = {Active = 1}
SaveToFile("Members.dat", Members, "Members")
else
if not Members[oUser.sName].Active then
Members[oUser.sName].Active = 1
SaveToFile("Members.dat", Members, "Members")
end
end
end
end
for name,_ in pairs(Members) do -- Get names from tables
if Members[name].Active then -- Get the Active
ActiveC = ActiveC+1 -- Count them
end
if Members[name].LastSeen then -- Get thoose who are offline
if Members[name].LastSeen == os.date("%Y-%m-%d") then -- Check if they has todays date
vCount = vCount+1 -- if they do, count
else -- if not
Members[name].LastSeen = nil -- Remove from table
SaveToFile("Members.dat", Members, "Members") -- Save
end
end
end
SendToAll(frmHub:GetHubBotName(), "" ..RegC.. " registered users, " ..ActiveC.. " active, " ..vCount.. " visited the hub in last 24 hrs, " ..OnlineC.. " currently online")
return 1
end
end

function NewUserConnected(curUser)
if frmHub:isNickRegged(curUser.sName) then -- Is user reg?
if Members[curUser.sName] and  Members[curUser.sName].LastSeen then -- Is user in table with LastSeen
Members[curUser.sName].LastSeen = nil -- Delte it
end
if curUser.bActive then -- Is user active?
-- Add to table
if Members[curUser.sName] == nil then
Members[curUser.sName] = {Active = 1}
else
Members[curUser.sName].Active = 1
end
end
SaveToFile("Members.dat", Members, "Members") -- Save it
end
end

OpConnected = NewUserConnected

function UserDisconnected(curUser)
if frmHub:isNickRegged(curUser.sName) then -- Is user reg?
-- Add to table
if Members[curUser.sName] == nil then
Members[curUser.sName].LastSeen = {os.date("%Y-%m-%d")}
else
Members[curUser.sName].LastSeen = os.date("%Y-%m-%d")
end
SaveToFile("Members.dat", Members, "Members") -- Save it
end
end

OpDisconnected = UserDisconnected

-- 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


Thanks In Advance :D
"BoRN FIGhTEr"

PtokaX forum

Membercount
« on: 19 July, 2010, 19:33:18 »

Offline TZB

  • Double Ace
  • *
  • Posts: 119
  • Karma: +13/-1
  • ||-T-z-B-||
    • FastFix Support
Re: Membercount
« Reply #1 on: 24 July, 2010, 12:26:43 »
Code: [Select]
-- This script is converted with PtokaX LUA API Converter v0.9b at 07/24/10 15:46:18
-- Member Count
-- Made by Madman
-- Requested by SwapY
-- Small bugfix, report by Markitos
-- Small changes by NL

Members = {}

function OnStartup()
-- Make file
local file = io.open("Members.dat")
if file then
file:close()
else
local file = io.open("Members.dat", "w+")
file:write("Members = {\n}")
file:close()
end
-- Load file
LoadFromFile("Members.dat")
end

function ChatArrival(curUser,data)
local data = string.sub(data, 1, -2)
local s,e,cmd = string.find(data, "%b<>%s+[%!%+%?%#](%S+)")
if cmd == "membercount" then -- find cmd
Core.SendToAll(data)
local RegC, OnlineC, ActiveC, vCount = 0,0,0,0
for count,_ in pairs(RegMan.GetRegs()) do -- Get regged users
RegC = count -- RegC is count
end
for count,oUser in pairs(Core.GetOnlineRegs(true)) do -- Get online reg users
OnlineC = count
if Core.GetUserValue(oUser,10) then -- If user is Active
-- Add to table
if Members[oUser.sNick] == nil then
Members[oUser.sNick] = {Active = 1}
SaveToFile("Members.dat", Members, "Members")
else
if not Members[oUser.sNick].Active then
Members[oUser.sNick].Active = 1
SaveToFile("Members.dat", Members, "Members")
end
end
end
end
for name,_ in pairs(Members) do -- Get names from tables
if Members[name].Active then -- Get the Active
ActiveC = ActiveC+1 -- Count them
end
if Members[name].LastSeen then -- Get thoose who are offline
if Members[name].LastSeen == os.date("%Y-%m-%d") then -- Check if they has todays date
vCount = vCount+1 -- if they do, count
else -- if not
Members[name].LastSeen = nil -- Remove from table
SaveToFile("Members.dat", Members, "Members") -- Save
end
end
end
Core.SendToAll("<"..SetMan.GetString(21).."> " ..RegC.. " registered users, " ..ActiveC.. " active, " ..vCount.. " visited the hub in last 24 hrs, " ..OnlineC.. " currently online")
return true
end
end

function UserConnected(curUser)
if RegMan.GetReg(curUser.sNick) then -- Is user reg?
if Members[curUser.sNick] and  Members[curUser.sNick].LastSeen then -- Is user in table with LastSeen
Members[curUser.sNick].LastSeen = nil -- Delte it
end
if Core.GetUserValue(curUser,10) then -- Is user active?
-- Add to table
if Members[curUser.sNick] == nil then
Members[curUser.sNick] = {Active = 1}
else
Members[curUser.sNick].Active = 1
end
end
SaveToFile("Members.dat", Members, "Members") -- Save it
end
end

OpConnected = UserConnected

function UserDisconnected(curUser)
if RegMan.GetReg(curUser.sNick) then -- Is user reg?
-- Add to table
if Members[curUser.sNick] == nil then
Members[curUser.sNick].LastSeen = {os.date("%Y-%m-%d")}
else
Members[curUser.sNick].LastSeen = os.date("%Y-%m-%d")
end
SaveToFile("Members.dat", Members, "Members") -- Save it
end
end

OpDisconnected = UserDisconnected

-- 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
RegConnected = UserConnected
RegDisconnected = UserDisconnected
Simple converter did the trick.

PtokaX forum

Re: Membercount
« Reply #1 on: 24 July, 2010, 12:26:43 »