PtokaX forum

Archive => Archived 5.1 boards => Help with scripts => Topic started by: antd on 14 October, 2006, 17:02:13

Title: Command Spy
Post by: antd on 14 October, 2006, 17:02:13
Hello, I have to log everything in my hub as I use the hub in an organisation. Logs are required to be kept for 12months.

I have use the script commandspy1.0 but I don't know how to use it. I would be grateful if someone could tell me how to use the command.

Thank you.

The script I use:


--[[

Command Spy 1.0 by jiten (3/18/2006)

]]--

Settings = {
sBot = frmHub:GetHubBotName(),
fSpy = "Notify.tbl",
tSpy = {}
}

Main = function()
if loadfile(Settings.fSpy) then dofile(Settings.fSpy) end
end

ChatArrival = function(user,data)
local s,e,msg = string.find(data,"^%b<>%s+(%p.*)|$")
-- Command Spy related
if msg then return ParseCommands(user,msg) end
end

ToArrival = function(user,data)
local s,e,to,msg = string.find(data, "^%$To:%s+(%S+)%s+From:%s+%S+%s-%$%b<>%s+(%p.*)|$")
if to == Settings.sBot and msg then return ParseCommands(user, msg) end
end

ParseCommands = function(user, data)
for i,v in pairs(Settings.tSpy) do
local nick = GetItemByName(i)
if nick then
nick:SendPM(Settings.sBot,os.date("%x %X").." - "..GetProfileName(GetUserProfile(user.sName) or "User").." "..user.sName.." used command: "..data)
end
end
local s,e,cmd = string.find(data,"^%p(%S+)")
tCmds = {
-- Start: Command Spy Command
["cmdspy"] = {
tFunc = function(user,data)
local s,e,flag = string.find(data,"%S+%s+(%S+)")
if flag then
flag = string.lower(flag)
local tTable = {
["on"] = function()
if Settings.tSpy[user.sName] then
user:SendData(Settings.sBot,"*** Command Spy is already enabled for you!")
else
Settings.tSpy[user.sName] = 1
user:SendData(Settings.sBot,"*** Command Spy is now enabled for you.")
end
end,
["off"] = function()
if Settings.tSpy[user.sName] then
Settings.tSpy[user.sName] = nil
user:SendData(Settings.sBot,"*** Command Spy is now disabled for you!")
else
user:SendData(Settings.sBot,"*** Command Spy is already disabled for you!.")
end
end
}
if tTable[flag] then
tTable[flag]()
else
user:SendData(Settings.sBot,"*** Usage: !cmdspy <on/off>")
end
end
end,
tLevels = {
[0] = 1,
[5] = 1,
},
},
}
if cmd and tCmds[string.lower(cmd)] then
cmd = string.lower(cmd)
if tCmds[cmd].tLevels[user.iProfile] then
return tCmds[cmd].tFunc(user,data), 1
else
return user:SendData(Settings.sBot,"*** Error: You are not allowed to use this command."), 1
end
end
end

OnExit = function()
local hFile = io.open(Settings.fSpy,"w+") Serialize(Settings.tSpy,"Settings.tSpy",hFile); hFile:close()
end

Serialize = function(tTable,sTableName,hFile,sTab)
sTab = sTab or "";
hFile:write(sTab..sTableName.." = {\n");
for key,value in pairs(tTable) do
if (type(value) ~= "function") then
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
Serialize(value,sKey,hFile,sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
hFile:write(sTab.."\t"..sKey.." = "..sValue);
end
hFile:write(",\n");
end
end
hFile:write(sTab.."}");
end
Title: Re: Command Spy
Post by: Rincewind on 14 October, 2006, 19:13:29
The script you posted is in Lua4. To use it with a modern PtokaX it will need converting to Lua 5.03 or Lua 5.1.1.

Not sure you'll have much luck getting someone here to convert it
Title: Re: Command Spy
Post by: antd on 14 October, 2006, 19:22:00
Thank you very much (again). Some kind person couldn't help me out with this?
Title: Re: Command Spy
Post by: 6Marilyn6Manson6 on 14 October, 2006, 19:42:56
Quote from: Rincewind on 14 October, 2006, 19:13:29
The script you posted is in Lua4. To use it with a modern PtokaX it will need converting to Lua 5.03 or Lua 5.1.1.

Not sure you'll have much luck getting someone here to convert it

This is false, because jiten not have made this script in Lua4, you can see:

ChatArrival = function(user,data)

or

for i,v in pairs(Settings.tSpy) do

these parts of script exist only on LUA5,so that's impossible this script can be on lua4, and you can see also this:

Command Spy 1.0 by jiten (3/18/2006)
Title: Re: Command Spy
Post by: antd on 14 October, 2006, 19:51:46
Quote from: 6Marilyn6Manson6 on 14 October, 2006, 19:42:56
This is false, because jiten not have made this script in Lua4, you can see:

ChatArrival = function(user,data)

or

for i,v in pairs(Settings.tSpy) do

these parts of script exist only on LUA5,so that's impossible this script can be on lua4, and you can see also this:

Command Spy 1.0 by jiten (3/18/2006)

It is because I posted a similar thread at another forum. He probably just copied and pasted his response assuming I posted the same topic.
Title: Re: Command Spy
Post by: 6Marilyn6Manson6 on 14 October, 2006, 20:01:41
Quote from: antd on 14 October, 2006, 19:51:46
It is because I posted a similar thread at another forum. He probably just copied and pasted his response assuming I posted the same topic.

I don't understand, ....can you tell me better your problem about this script?
Title: Re: Command Spy
Post by: Psycho_Chihuahua on 14 October, 2006, 20:17:12
Quote from: antd on 14 October, 2006, 17:02:13
Hello, I have to log everything in my hub as I use the hub in an organisation. Logs are required to be kept for 12months.

I have use the script commandspy1.0 but I don't know how to use it. I would be grateful if someone could tell me how to use the command.

Thank you.



Actually the script is simple to use

While the hub is running and the script is active do the following:

type  !cmdspy <on/off> to turn its function <on/off> for you iE. !cmdspy on  for activating


after you have done this you will get PM Messages for all Commands used by the Users in that hub in this type of fashion:
[20:11:41] <-SanitariuM-> 10/14/06 20:11:41 - Master Psycho_Chihuahua used command: !goinfo
Title: Re: Command Spy
Post by: antd on 14 October, 2006, 20:20:37
Quote from: 6Marilyn6Manson6 on 14 October, 2006, 20:01:41
I don't understand, ....can you tell me better your problem about this script?
I made a topic at another forum. Rincewind posted about the script being version 4 because on my -other- post the script was version 4. He just copied and pasted his response.

My problem is that I don't know how to use the script. It seems the above poster has solved my problem. Thank you all for posting.
Title: Re: Command Spy
Post by: 6Marilyn6Manson6 on 14 October, 2006, 21:44:03
Quote from: antd on 14 October, 2006, 20:20:37
I made a topic at another forum. Rincewind posted about the script being version 4 because on my -other- post the script was version 4. He just copied and pasted his response.

My problem is that I don't know how to use the script. It seems the above poster has solved my problem. Thank you all for posting.

This script have two command :  !cmdspy on   and   !cmdspy off  , or you can see Psycho_Chihuahua  ;D
Title: Re: Command Spy
Post by: Rincewind on 15 October, 2006, 00:05:15
Quite correct in what you assumed I did. I only took a cursory glance here and it seemed to be the same post as on the other board. I apologise for that and will take the time to fully read posts before replying again  :-X
Title: Re: Command Spy
Post by: 6Marilyn6Manson6 on 15 October, 2006, 00:25:42
Quote from: Rincewind on 15 October, 2006, 00:05:15
Quite correct in what you assumed I did. I only took a cursory glance here and it seemed to be the same post as on the other board. I apologise for that and will take the time to fully read posts before replying again  :-X

No Problem Guy  ;D
Title: Re: Command Spy
Post by: Mozzilla? on 23 October, 2006, 01:14:22
Here it is converted to Lua 5.1

Hope it helps


--[[

Command Spy 1.1 LUA 5.1

by jiten (3/18/2006)

Changelog:

- Changed: Script will only search for ! and +
- Fixed: Missing () in GetProfileName
- Added full profile table rather than just master and netfounder - Toobster?? - 16TH September 2006

]]--

Settings = {
sBot = frmHub:GetHubBotName(),
fSpy = "Notify.tbl",
tSpy = {}
}

Main = function()
if loadfile(Settings.fSpy) then dofile(Settings.fSpy) end
end

ChatArrival = function(user,data)
local s,e,msg = string.find(data,"^%b<>%s+([%!%+].*)|$")
-- Command Spy related
if msg then return ParseCommands(user,msg) end
end

ToArrival = function(user,data)
local s,e,to,msg = string.find(data, "^%$To:%s+(%S+)%s+From:%s+%S+%s-%$%b<>%s+([%!%+].*)|$")
if to == Settings.sBot and msg then return ParseCommands(user, msg) end
end

ParseCommands = function(user, data)
for i,v in pairs(Settings.tSpy) do
local nick = GetItemByName(i)
if nick then
nick:SendPM(Settings.sBot,os.date("%x %X").." - "..(GetProfileName(GetUserProfile(user.sName)) or "User").." "..user.sName.." used command: "..data)
end
end
local s,e,cmd = string.find(data,"^%p(%S+)")
tCmds = { 
-- Start: Command Spy Command
["cmdspy"] = {
tFunc = function(user,data)
local s,e,flag = string.find(data,"%S+%s+(%S+)")
if flag then
flag = string.lower(flag)
local tTable = {
["on"] = function()
if Settings.tSpy[user.sName] then
user:SendData(Settings.sBot,"*** Command Spy is already enabled for you!")
else
Settings.tSpy[user.sName] = 1
user:SendData(Settings.sBot,"*** Command Spy is now enabled for you.")
end
end,
["off"] = function()
if Settings.tSpy[user.sName] then
Settings.tSpy[user.sName] = nil
user:SendData(Settings.sBot,"*** Command Spy is now disabled for you!")
else
user:SendData(Settings.sBot,"*** Command Spy is already disabled for you!.")
end
end
}
if tTable[flag] then
tTable[flag]()
else
user:SendData(Settings.sBot,"*** Usage: !cmdspy <on/off>")
end
end
end,
tLevels = {
[0] = 1, -- Masters 
[1] = 1, -- Operators 
[2] = 0, -- Vips 
[3] = 0, -- Regs 
[4] = 1, -- Moderator 
[5] = 1, -- NetFounder 
[6] = 1, --Owner
[-1] = 0, -- Users 
},
},
}
if cmd and tCmds[string.lower(cmd)] then
cmd = string.lower(cmd)
if tCmds[cmd].tLevels[user.iProfile] then
return tCmds[cmd].tFunc(user,data), 1
else
return user:SendData(Settings.sBot,"*** Error: You are not allowed to use this command."), 1
end
end
end

OnExit = function()
local hFile = io.open(Settings.fSpy,"w+") Serialize(Settings.tSpy,"Settings.tSpy",hFile); hFile:close()
end

Serialize = function(tTable,sTableName,hFile,sTab)
sTab = sTab or "";
hFile:write(sTab..sTableName.." = {\n");
for key,value in pairs(tTable) do
if (type(value) ~= "function") then
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
Serialize(value,sKey,hFile,sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
hFile:write(sTab.."\t"..sKey.." = "..sValue);
end
hFile:write(",\n");
end
end
hFile:write(sTab.."}");
end
Title: Re: Command Spy
Post by: antd on 24 October, 2006, 01:16:52
Thanks a lot!!   8)