Some info on what i want to do ..
I have a table thats looking like this
SKCONF = {
["Safe_Adv"] = {},
}
the idea is that i should be able to add tables to it using this:
function SafeAdv(user,data)
Get1Arg(data)
SKCONF["SaveAdv"] = {arg}
end
end
Result:
SKCONF = {
["SaveAdv"] = {
[1] = "what ever",
},
}
So far so good ... But now i want to add a 2nd line and this is where i need help.
What i wanna end up with is:
SKCONF = {
["SaveAdv"] = {
[1] = "what ever",
[2] = "what ever2",
[3] = "what ever3",
[4] = "what ever4",
},
}
So i need a hint on checking 'if SKCONF.SaveAdv ~= nill then
well.. then it should ad the next line while keeping the lines thats already added..
Any help would be great !!
**Snooze
- Arhh, tables are killing my brain
this is what you need (from ref man) (http://www.lua.org/manual/4.0/manual.html#6.1):
tinsert (table [, pos] , value)
Inserts element value at table position pos, shifting other elements to open space, if necessary. The default value for pos is n+1, where n is the result of getn(table) (see Section 6.1), so that a call tinsert(t,x) inserts x at the end of table t. This function also sets or increments the field n of the table to n+1. This function is equivalent to the following Lua function, except that the table accesses are all raw (that is, without tag methods):
function tinsert (t, ...)
local pos, value
local n = getn(t)
if arg.n == 1 then
pos, value = n+1, arg[1]
else
pos, value = arg[1], arg[2]
end
t.n = n+1;
for i=n,pos,-1 do
t[i+1] = t
end
t[pos] = value
end
tremove (table [, pos])
Removes from table the element at position pos, shifting other elements to close the space, if necessary. Returns the value of the removed element. The default value for pos is n, where n is the result of getn(table) (see Section 6.1), so that a call tremove(t) removes the last element of table t. This function also sets or decrements the field n of the table to n-1.
This function is equivalent to the following Lua function, except that the table accesses are all raw (that is, without tag methods):
function tremove (t, pos)
local n = getn(t)
if n<=0 then return end
pos = pos or n
local value = t[pos]
for i=pos,n-1 do
t = t[i+1]
end
t[n] = nil
t.n = n-1
return value
end
local arg = "whatever"
if SKCONF["SaveAdv"] then
tinsert(SKCONF["SaveAdv"], arg)
else
SKCONF["SaveAdv"] = {arg}
end
or if you are using a non number index:
rawset (table, index, value)
Sets the real value of table[index] to value, without invoking any tag method. table must be a table, index is any value different from nil, and value is any Lua value.
local arg = "whatever"
local index = "whatever2"
if SKCONF["SaveAdv"] then
rawset (SKCONF["SaveAdv"], index, arg)
else
SKCONF["SaveAdv"] = {[index] = arg}
end
Thanks Skrollster,
That were just the hint i needed :D - table are being created just nicely now :))
Next step is learning howto use it
Thanks again ..
**Snooze
- still learning..
OK this is really doing my head in !!
Please please help me out here..
What i wanna do is an anti adv section to my DataArrival function...
This is what i have (Org. From Brain-Master by nErBoS i think)
if (SKCONF.AntiAdv == "ON") then
if not (user.bOperator) then
if (( strsub(data, 1, 1) == "<" ) or ( strsub(data, 1, 4) == "$To:" )) then
for i=1,getn(trigs) do
if (strfind(strlower(data), trigs[i])) then
local word = strlower(data), trigs[i]
local userToBeWarned = user
if SKCONF.MaxWarns == "ON" and tWarnCounter[userToBeWarned.sName] == tonumber(SKCONF.MaxWarnCounts) then
KickUser(user, data)
return
end
if (tWarnCounter[userToBeWarned.sName] == nil) then
tWarnCounter[userToBeWarned.sName] = 1
else
tWarnCounter[userToBeWarned.sName] = tWarnCounter[userToBeWarned.sName] + 1
end
SendToAll(Bot, user.sName.." has been warned "..tWarnCounter[userToBeWarned.sName].." time(s) - because: Sending advertizing in the hub.")
userToBeWarned:SendPM(Bot, "You have been Warned "..tWarnCounter[userToBeWarned.sName].." time(s) - because: Sending advertizing in the hub.")
appendto(sKicklog)
write("\r\n", "? "..GetTime()..": "..user.sName.." was warned "..tWarnCounter[userToBeWarned.sName].." time(s) - because: Sending "..word.." advertizing in the hub: ")
writeto()
userToBeWarned:Disconnect()
end
end
end
end
end
This is now checking from a list of BAD URLS and working great...
But now that i also have a list of "SAFE URLS" it would be nice to have it check against that too ... And this is here i need your help again ... i cant seem to work that in there..
this is how the safe urls are listed.
SKCONF = {
["SafeAdv"] = {
[1] = "Url1",
[2] = "Url2",
[3] = "Url3",
[4] = "Url4",
[5] = "Url5",
["n"] = 5,
},
}
---------------------------
2nd problem is:
It would be nice if a user were not to be kicked when sending an urls to an Op..
Any help apriciated ..
**Snooze
- Grrrrr
data holds the name of the recieving user, if you extract that you can check his level.
if it's a user you continue.
the good urls have 2 be before the bad, if good you break.
maby take a look @ sneaky anti adver, that can detect good and bad urls.
plop
Thanks plop, im gonna give it a try :)
**Snooze
hmm.. i need a hint before spending any more 'hours' on this.. am i even getting close
if (( strsub(data, 1, 1) == "<" ) or ( strsub(data, 1, 4) == "$To:" )) then
s,e,name = strfind(data,"$Who:([^$]+)")
if (not user.bOperator) or (GetItemByName(name).iProfile > 2) then
Please advice ..
**Snooze
Hi,
s,e,name = strfind(data,"$Who:([^$]+)")
Humm were are you getting this string "$Who"???
Best regards, nErBoS
Well.. this part is all new to me so im kinda doing it by 'trial and error'
function DataArrival(user,data)
if (SKCONF.AntiAdv == "ON") then
if (( strsub(data, 1, 1) == "<" ) or ( strsub(data, 1, 4) == "$To:" )) then
s,e,name = strfind(data,"$Who:([^$]+)")
if (not user.bOperator) or (GetItemByName(name).iProfile <= 3) then
for i=1,getn(trigs) do
if (strfind(strlower(data), trigs[i])) then
local word = strlower(data), trigs[i]
local userToBeWarned = user
if SKCONF.MaxWarns == "ON" and tWarnCounter[userToBeWarned.sName] == tonumber(SKCONF.MaxWarnCounts) then
KickUser(user, data)
return
end
I got the idea from this little script - just not fully understanding it ..
function DataArrival(curUser, sData)
if ( strsub(sData, 1, 12) == "$OpForceMove" ) then
s,e,name = strfind(sData,"$Who:([^$]+)")
s,e,where = strfind(sData,"$Where:([^$]+)")
appendto(file)
write(Time, "\t" ..curUser.sName.." with IP; "..curUser.sIP.." has redirect "..name.." to: "..where.." \r\n")
writeto()
end
end
Hi,
Well i would recommend you to see the DC documation to see and compreend every string and his job an info send it :)
Best regards, nErboS
Problem solved .. took a bit of reading though ;)
Thanks for your help and advice ..
**Snooze