determinate determinate

Author Topic: SpareChat 1.0b LUA 5.11 [Strict][API 2]  (Read 851 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
SpareChat 1.0b LUA 5.11 [Strict][API 2]
« on: October 21, 2007, 03:12:06 pm »
Code: [Select]
--[[
SpareChat 1.0b LUA 5.11 [Strict][API 2]

By Mutor 07/11/07

Requested by M_S o s a

Yet another chat app, this one is light
in function but small, per request. (~35k Mem)

+Changes from 1.0 10/21/07
~Converted for the new PtokaX API
-Removed RoboCop profiles
]]

local ChatName = "[ChatRoom]"
--[[
Set your profiles here. [yours may be different]
[#] = 0 = disabled/1=enabled for chat,
]]
local ChatProfiles = {
[-1] = 0, -- Unregistered User [Technically, a non profile]
[0] = 1, -- Master
[1] = 1, -- Operator
[2] = 0, -- Vip
[3] = 1, -- Reg
}
--Set a few local variables for the script [edit only the timer interval 'Int']
local Mem,Time,Int,Timer = 0,os.time(),5

function OnStartup()
local x = true
for i,v in ipairs(Core.GetBots()) do
if ChatName == v.sNick then
x = false
break
end
end
if x then
local prt = SetMan.GetString(3) or "411"
Core.RegBot(ChatName,SetMan.GetString(0).." Chat Room",
SetMan.GetString(2)..":"..prt:gsub("%;.+$",""),true)
end
Timer = TmrMan.AddTimer(Int*60000)
end

OnTimer = function(Id)
if Timer == Id then
if collectgarbage("count") > (Mem * 1.05) then
collectgarbage("collect")
end
if ((os.time() - Time) / 60) > Int then
TmrMan.RemoveTimer(Timer)
Timer = nil
end
end
end

ToArrival = function(user,data)
local _,_,to = data:find("^$To: (%S+) From:")
if to and to:lower() == ChatName:lower() then
if ChatProfiles[user.iProfile] and ChatProfiles[user.iProfile] == 1 then
Time = os.time()
local _,_,msg = data:find("%b<> (.+)|$")
if msg then
SendToChat(user,msg)
end
if not Timer then
Timer = TmrMan.AddTimer(Int*60000)
end
OnTimer(Timer)
else
return Core.SendPmToNick(user.sNick,ChatName,"Sorry "..user.sNick..", this chat is for "..
"select profiles only. Your message has not been sent. :("),1
end
end
end

function SendToChat(user,msg)
local Tab = Core.GetOnlineUsers()
for i,usr in ipairs(Tab) do
if ChatProfiles[usr.iProfile] and ChatProfiles[usr.iProfile] == 1 then
if usr.sNick:lower() ~= user.sNick:lower() then
Core.SendToNick(usr.sNick,"$To: "..usr.sNick.." From: "..ChatName..
" $<"..user.sNick.."> " ..msg.."|")
end
end
end
collectgarbage("collect")
end

collectgarbage("collect")
Mem = collectgarbage("count")
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

 

determinate determinate
guestbook