PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: Optimus on 30 March, 2005, 19:12:56

Title: Mass message unregged users
Post by: Optimus on 30 March, 2005, 19:12:56
-- Message Unregged Users
-- Made by Optimus
-- 03/30/05

sBot = "BotName"

Main = function()
frmHub:RegBot(sBot)
end

ChatArrival = function(user, data)
data=string.sub(data,1,string.len(data)-1)
s,e,cmd=string.find(data, "%b<>%s+(%S+)")
if (cmd == "!messunreg") then
if user.bOperator then
local s,e,cmd,message = string.find(data,"%b<>%s+(%S+)%s+(.*)")
if message then
local border = ""
if (string.len ( message)*2/3+2) < 76 then
border = string.rep ("-", string.len (message)*2/3+2)
else
border = string.rep ("-", 75)
end message = "\r\n\r\n"..border.."\r\n"..message.."\r\n"..border.."\r\n"
for id,who in frmHub:GetOnlineUsers() do
if who.iProfile == -1 then
who:SendPM(sBot, message)
end
end
else
user:SendData(sBot, "*** Usage: !messunreg ")
end
end
return 1
end
end


Mass message unregged users updated version.

- Optimus
Title:
Post by: Herodes on 30 March, 2005, 21:41:46
nice trick for the border,.. its about 2/3rds ;)
I couldn't resist touching this one,... no offense..

-- Message Unregged Users
-- Made by Optimus
-- 03/30/05
---
-- I couldn't resist touching .. Herodes..

sBot = "BotName"

ChatArrival = function(user, data)
if user.bOperator then
data=string.sub(data,1,-2)
s,e,cmd=string.find(data, "%b<>%s+(%S+)")
if (cmd == "!messunreg") then
local s,e,cmd,message = string.find(data,"%b<>%s+(%S+)%s+(.*)")
if message then
local border = string.rep ("-", 75)
if (string.len (message)*2/3+2) < 76 then
border = string.rep ("-", string.len (message)*2/3+2)
end
message = "\r\n\r\n"..border.."\r\n"..message.."\r\n"..border.."\r\n"
for id,who in frmHub:GetOnlineUsers() do
if who.iProfile == -1 then
who:SendData( "$To: "..who.sName.." From: "..who.sName.." $<"..sBot.."> "..message )
end
end
else
user:SendData(sBot, "*** Usage: !messunreg ")
end
end
return 1
end
end
Title:
Post by: bastya_elvtars on 30 March, 2005, 22:08:07
If i use this:

SendPmToAll(user.sName,"message came")
will the away messages be rebounded to me?

Or better use this:

for h=1,table.getn(userstbl) do; userstbl[h]:SendData("$To: "..userstbl[h].sName.." From: "..Bot.." $<"..user.sName.."> "..message ); end
, where user is me.

So?
Title:
Post by: Optimus on 30 March, 2005, 23:28:48
-- Message Unregged Users
-- Made by Optimus
-- 03/30/05
--
-- I couldn't resist touching .. Herodes..
-- Touched it some more by Optimus cause it feels so good hehe

sBot = "BotName"

ChatArrival = function(user, data)
if user.bOperator then
data=string.sub(data,1,-2)
local s,e,cmd=string.find(data, "%b<>%s+(%S+)")
if (cmd == "!massunreg") then
local s,e,cmd,message = string.find(data,"%b<>%s+(%S+)%s+(.*)")
if message then
local border = string.rep ("-", 75)
if (string.len (message)*2/3+2) < 76 then
border = string.rep ("-", string.len (message)*2/3+2)
end message = "*** Hub: "..(frmHub:GetHubName() or frmHub:GetHubAddress()).." - From: "..user.sName.."\r\n\r\n"..border.."\r\n"..message.."\r\n"..border.."\r\n"
for id,who in frmHub:GetOnlineUsers() do
if who.iProfile == -1 then
who:SendData( "$To: "..who.sName.." From: "..who.sName.." $<"..sBot.."> "..message)
end
end SendToOps(sBot, user.sName.." sended a mass message to all none regged users!")
else
user:SendData(sBot, "*** Usage: !massunreg ")
end
return 1
end
end
end
Yummy yummy
Title:
Post by: Requiem on 30 March, 2005, 23:36:19
The script above eats too much resources (memory compared to the one I'll give below) I think.. Maybe you can try this one:
-- Made by Optimus
-- 08/12/03
-- converted to LUA 5 by jiten

sBot = "BotName"

unRegUsers = {}
unRegUserFile = "unRegUsers.txt"

function Main()
frmHub:RegBot(sBot)
doloadTable(unRegUserFile)
if frmHub:GetUsersCount() == 0 then unRegUsers = {}
dosaveTable(user,data)
end
end

function NewUserConnected(user)
if user.iProfile == -1 then
doLog_unRegUsers(user, data)
end
end
function UserDisconnected(user)
if unRegUsers[user.sName] then
unRegUsers[user.sName] = nil
dosaveTable(user,data)
end
end

function ChatArrival(user, data)
data=string.sub(data,1,string.len(data)-1)
_,_,cmd=string.find(data, "%b<>%s+(%S+)")
if user.bOperator then
if (cmd == "!unregpm") then
s,e,cmd,message = string.find(data,"%b<>%s+(%S+)%s+(.+)")
if message then
tosend = ""
if (string.len ( message)*2/3+2) < 76 then
border = string.rep ("-", string.len (message)*2/3+2)
else
border = string.rep ("-", 75)
end
tosend = "\r\n\r\n"..border.."\r\n"..message.."\r\n"..border.."\r\n"
if unRegUsers then
for name,_ in unRegUsers do
SendPmToNick(name,sBot, tosend)
end
end
else
user:SendData(sBot, "*** Please Enter a Message!")
end
return 1
end
end
end

function doLog_unRegUsers(user, data)
if unRegUsers[user.sName] == nil then
unRegUsers[user.sName] = 1
dosaveTable(user,data)
end
end


function doloadTable(unRegUserFile)
local handle = io.open(unRegUserFile,"r")
if (handle ~= nil) then
                dofile(unRegUserFile)
handle:flush()
handle:close()
        end
end

function dosaveTable(user,data)
local f = io.open(unRegUserFile, "w+")
assert(unRegUserFile)
f:write("unRegUsers = {")
         for a,b in unRegUsers do
                  if b == 1 then
         f:write(string.format("[%q]=",a)..b..",")
         end
        end
        f:write("}")
        f:flush()
        f:close()
end


Am I wrong ?
Title:
Post by: [UK]Madman on 31 March, 2005, 00:41:31
If using lua new releases of ptokax (e.g. lua 5) wouldnt something like this be easier ?

local tUsers = {}
tUsers = frmHub:GetOnlineUsers()
for key,value in tUsers do
if not value.bRegistered then
tUnreg[value.sName] = 1
  end
end

Would save the need to save to a text file, tho use more resources when called in a hub with a lot of users.....
Title:
Post by: Herodes on 31 March, 2005, 00:46:48
Requiem,.. I dont think that it eats up resources.. check it out ... the script done by Opti is taking advantage of what [UK]Madman pointed out .. ;)
Title: Re: Mass message unregged users
Post by: philoum on 29 May, 2006, 05:25:22
Hello, i'm french
I put this last unreg mess but on connected unreg there no mess auto in pm for the unreg user ?
can you help me?

thank
respectfull
Title: Re: Mass message unregged users
Post by: Rincewind on 29 May, 2006, 09:11:02
This script only sends a message when an operator types !massunreg in main followed by the message to send.
Title: Re: Mass message unregged users
Post by: Madman on 29 May, 2006, 20:51:08
I noticed.. All codes posted in this is thread is lua 5... so maybe this topic fits better in the lua 5 section?