PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: BlazeXxX on 31 October, 2003, 03:01:33

Title: Notify to OPs
Post by: BlazeXxX on 31 October, 2003, 03:01:33
Useful Script for you  all - Written by klownietklowniet



-- Start Copying From this line
-- Date: 02-09-2003
--
-- code from klownietklowniet
-- network: [ > DC - UniteD < ]
--
-- Request by Discs
--
-- Send notice to OPs when certaion ip or username logs into the hub
--

BotName = "ReportCertain"

CommandNotifyIP="!notifyip"
CommandNotifyUSR="!notifyusr"

usernames={}
ips={}

function Main()
--frmHub:RegBot(BotName)
LoadUsernames()
LoadIPs()
end


function NewUserConnected(curUser)

if usernames[curUser.sName] then
SendPmToOps(BotName, curUser.sName.." with ip "..curUser.sIP.."just logged in and wanted to notify you!")
end

if ips[curUser.sIP] then
SendPmToOps(BotName, curUser.sIP.." belonging to "..curUser.sName.."just logged in and wanted to notify you!")
end

end


function DataArrival(curUser,data)

local MessageRecognized = 0
if isPM(data)==1 then
whoto,from,message=ParsePM(data)
MessageRecognized=1
elseif isMCM(data)==1 then
message=ParseMCM(data)
MessageRecognized=1
end


if MessageRecognized==1 and curUser.iProfile>=0 and curUser.iProfile<=1 then
if (strfind(strlower(message), strlower(CommandNotifyIP))) then
AddIPs(message, curUser)
elseif (strfind(strlower(message), strlower(CommandNotifyUSR))) then
AddUsernames(message, curUser)
end
end

end



function isMCM(data)
if( strsub(data, 1, 1) == "<" ) then
return 1
else
return 0
end
end

function isPM(data)
if( strsub(data, 1, 3) == "$To" ) then
return 1
else
return 0
end
end

function ParsePM(data)
s,e,whoTo,from,message = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.*)")
message = strsub(message,1,strlen(message)-1)
return whoTo,from,message
end

function ParseMCM(data)
s,e,message = strfind(data, "%b<> (.*)")
message = strsub(message,1,strlen(message)-1)
return message
end

function GetOneParam(message)
s,e,param1=strfind(message,"%S+%s(.+)")
return param1
end

function LoadUsernames()
readfrom("usernames.txt")
while 1 do
local line = read()
if (line == nil) then
break
else
s,e, n, i = strfind(line,"(%S+) (%S+)")
usernames[n]=i
end
end
readfrom()
end

function SaveUsernames()
writeto("usernames.txt")
for n, i in usernames do
write(n.." "..i.."\r\n")
end
writeto()
end

function LoadIPs()
readfrom("ips.txt")
while 1 do
local line = read()
if (line == nil) then
break
else
s,e, n, i = strfind(line,"(%S+) (%S+)")
ips[n]=i
end
end
readfrom()
end

function SaveIPs()
writeto("ips.txt")
for n, i in ips do
write(n.." "..i.."\r\n")
end
writeto()
end

function AddUsernames(message, curUser)
local n = GetOneParam(message)
if (n~=nil) then
usernames[n]="1"
SaveUsernames()
curUser:SendPM(BotName,"Added username "..n.." for notification!")
else
curUser:SendPM(BotName,"Usage: "..CommandNotifyUSR.." username")
end
end

function AddIPs(message, curUser)
local n = GetOneParam(message)

if (n~=nil) then
ips[n]="1"
SaveIPs()
curUser:SendPM(BotName,"Added ip "..n.." for notification!")
else
curUser:SendPM(BotName,"Usage: "..CommandNotifyIP.." ip")
end
end

-- Finsh Copying
Title:
Post by: Twix on 30 November, 2003, 23:29:34
At the momment this alerts ops everytime a user or IP connects.
Is there anyway changing it so I can remove a username or IP from the list manually.
Or possible have the name/IP removed auto after a preset number of connects?

TIA

Twix
Title:
Post by: BlazeXxX on 08 December, 2003, 16:44:36
Sorry for the  late reply!

The usernames that will be notified shud be recorded in usernames.txt and ips wud be stored in ips.txt