PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: Guibs on 06 December, 2003, 04:18:45

Title: Immune script
Post by: Guibs on 06 December, 2003, 04:18:45
Hi there,,

A script to make users immuned by their nick,,

-------
-- Immune script
-- !immune < to add a user immuned
-- !delimmune < to delete a user immuned
-- ?immune < show the current users immuned


function Main()
Bot = "YourBot"
ImmunesTotal = 0
ImmunesList = {}
ReadImmunes()
end

function ReadImmunes()
readfrom("Immune.lst")
while 1 do
local line = read()
if line == nil then
break
else
ImmunesTotal = ImmunesTotal + 1
rawset(ImmunesList,ImmunesTotal,line)
end
end
readfrom()
end

function WriteImmunes()
writeto("Immune.lst")
for i=1,ImmunesTotal,1 do
write(rawget(ImmunesList,i).."\n")
end
writeto()
end

function DeleteImmunes(opNick)
errlvl = 1
for i=1,ImmunesTotal,1 do
if rawget(ImmunesList,i) == opNick then
if i ~= ImmunesTotal then
rawset(ImmunesList,i,rawget(ImmunesList,ImmunesTotal))
end
ImmunesTotal = ImmunesTotal - 1
SortImmunes()
WriteImmunes()
errlvl = 0
break
end
end
-- returns 1 if Immune could not be found
return errlvl
end

function AddImmunes(opNick)
errlvl = CheckUserNickImmune(opNick)
if errlvl == 0 then
ImmunesTotal = ImmunesTotal + 1
rawset(ImmunesList,ImmunesTotal,opNick)
SortImmunes()
WriteImmunes()
end
-- returns 1 if Immune already exists
return errlvl
end

function SortImmunes()
for passNum=1,ImmunesTotal-1,1 do
for i=1,ImmunesTotal-passNum,1 do
if rawget(ImmunesList,i) > rawget(ImmunesList,i+1) then
tempNick = rawget(ImmunesList,i)
rawset(ImmunesList,i,rawget(ImmunesList,i+1))
rawset(ImmunesList,i+1,tempNick)
end
end
end
end

function ShowImmunes(user)
nickimmune = 0
nickimmunelist = ""
for i=1,ImmunesTotal,1 do
nickimmunelist = nickimmunelist..rawget(ImmunesList,i).."\r\n"
nickimmune = nickimmune+1
end
if nickimmune > 0 then
nickfound = "***Current users Immuned by their Nick are listed as:\r\n"..nickimmunelist
else
nickfound = "***None users immuned by their Nick found."
end

user:SendData(Bot,"\r\n"..nickfound)
end


function DoAddImmunes(user, data)
arg = GetArgML(data)
if arg ~= nil then
if AddImmunes(arg) == 1 then
user:SendData(Bot,"User "..arg.." is already Immune!")
else
SendToOps(Bot, user.sName.." just made "..arg.." a Immune!")
user:SendData(Bot,"You just made "..arg.." a Immune!")
SendToNick(arg, "<"..Bot.."> "..user.sName.." just made you a Immune!")
end
else
user:SendData(Bot, "You provided insufficient information for me to run the specified command.")
end
end

function DoDeleteImmunes(user, data)
arg = GetArgML(data)
if arg ~= nil then
if DeleteImmunes(arg) == 1 then
user:SendData(Bot,"User "..arg.." was not found in the current Immune list!")
else
SendToOps(Bot, user.sName.." just revoked Immune status from: "..arg)
user:SendData(Bot,"You just revoked Immune status from: "..arg)
SendToNick(arg, "<"..Bot.."> "..user.sName.." just revoked your Immune status.")
end
else
user:SendData(Bot, "You provided insufficient information for me to run the specified command.")
end
end

function CheckNickImmune(user)
found = 0
for i=1,ImmunesTotal,1 do
if rawget(ImmunesList,i) == user.sName then
found = 1
break
end
end
-- returns 1 if user specified is Immuned
return found
end

function CheckUserNickImmune(opNick)
errlvl = 0
for i=1,ImmunesTotal,1 do
if rawget(ImmunesList,i) == opNick then
errlvl = 1
break
end
end
-- returns 1 if user specified is Immuned
return errlvl
end

function GetArgML(data)
s,e,cmd,arg = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
return arg
end

function DataArrival(user,data)
if (strsub(data,1,1)=="<") or (strsub(data,1,4)=="$To:") then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")

if (cmd=="!addimmune" or cmd == "!immune") then
if user.bOperator then
DoAddImmunes(user,data)
return 1
end

elseif (cmd=="!deleteimmune" or cmd == "!delimmune") then
if user.bOperator then
DoDeleteImmunes(user,data)
return 1
end
elseif (cmd=="!showimmune" or cmd == "?immune") then
if user.bOperator then
ShowImmunes(user)
return 1
end
end
end
end

function OpConnected(user)
immune=CheckNickImmune(user)
if immune == 1 then
user:SendData(Bot, "Welcom there, lucky guy,... ;o)")
else
-- Do Your Code There
end
end

function NewUserConnected(user)
immune=CheckNickImmune(user)
if immune == 1 then
user:SendData(Bot, "Welcom there, lucky guy,... ;o)")
else
-- Do Your Code There
end
end
-------

l8tr, ;)
Title:
Post by: Guibs on 06 December, 2003, 04:36:45
Hi?,,

Updated, about some immune functions on Ips,, :)

That one is not tested,,... so,, to test... :))

Hub owner can enter >manually< some Ips in the file 'IpImmune.lst',... then, those Ips should be immuned on a '!banip',...

-----
-- Immune-example script v1.1, By Guibs
-- Added Ip immune list (IpImmune.lst) to show an other example about immune functions on Ip
-- !immune < to add a user immuned
-- !delimmune < to delete a user immuned
-- ?immune < show the current users immuned
-- This is just an example about the way to make some users immuned


function Main()
Bot = "YourBot"
ImmunesTotal = 0
ImmunesList = {}
IpImmunesTotal = 0
IpImmunesList = {}
ReadImmunes()
ReadIpImmunes()
end

function ReadImmunes()
readfrom("Immune.lst")
while 1 do
local line = read()
if line == nil then
break
else
ImmunesTotal = ImmunesTotal + 1
rawset(ImmunesList,ImmunesTotal,line)
end
end
readfrom()
end

function ReadIpImmunes()
readfrom("IpImmune.lst")
while 1 do
local line = read()
if line == nil then
break
else
IpImmunesTotal = IpImmunesTotal + 1
rawset(IpImmunesList,IpImmunesTotal,line)
end
end
readfrom()
end

function WriteImmunes()
writeto("Immune.lst")
for i=1,ImmunesTotal,1 do
write(rawget(ImmunesList,i).."\n")
end
writeto()
end

function DeleteImmunes(opNick)
errlvl = 1
for i=1,ImmunesTotal,1 do
if rawget(ImmunesList,i) == opNick then
if i ~= ImmunesTotal then
rawset(ImmunesList,i,rawget(ImmunesList,ImmunesTotal))
end
ImmunesTotal = ImmunesTotal - 1
SortImmunes()
WriteImmunes()
errlvl = 0
break
end
end
-- returns 1 if Immune could not be found
return errlvl
end

function AddImmunes(opNick)
errlvl = CheckUserNickImmune(opNick)
if errlvl == 0 then
ImmunesTotal = ImmunesTotal + 1
rawset(ImmunesList,ImmunesTotal,opNick)
SortImmunes()
WriteImmunes()
end
-- returns 1 if Immune already exists
return errlvl
end

function SortImmunes()
for passNum=1,ImmunesTotal-1,1 do
for i=1,ImmunesTotal-passNum,1 do
if rawget(ImmunesList,i) > rawget(ImmunesList,i+1) then
tempNick = rawget(ImmunesList,i)
rawset(ImmunesList,i,rawget(ImmunesList,i+1))
rawset(ImmunesList,i+1,tempNick)
end
end
end
end

function ShowImmunes(user)
nickimmune = 0
nickimmunelist = ""
for i=1,ImmunesTotal,1 do
nickimmunelist = nickimmunelist..rawget(ImmunesList,i).."\r\n"
nickimmune = nickimmune+1
end
if nickimmune > 0 then
nickfound = "***Current users Immuned by their Nick are listed as:\r\n"..nickimmunelist
else
nickfound = "***None users immuned by their Nick found."
end

user:SendData(Bot,"\r\n"..nickfound)
end


function DoAddImmunes(user, data)
arg = GetArgML(data)
if arg ~= nil then
if AddImmunes(arg) == 1 then
user:SendData(Bot,"User "..arg.." is already Immune!")
else
SendToOps(Bot, user.sName.." just made "..arg.." a Immune!")
user:SendData(Bot,"You just made "..arg.." a Immune!")
SendToNick(arg, "<"..Bot.."> "..user.sName.." just made you a Immune!")
end
else
user:SendData(Bot, "You provided insufficient information for me to run the specified command.")
end
end

function DoDeleteImmunes(user, data)
arg = GetArgML(data)
if arg ~= nil then
if DeleteImmunes(arg) == 1 then
user:SendData(Bot,"User "..arg.." was not found in the current Immune list!")
else
SendToOps(Bot, user.sName.." just revoked Immune status from: "..arg)
user:SendData(Bot,"You just revoked Immune status from: "..arg)
SendToNick(arg, "<"..Bot.."> "..user.sName.." just revoked your Immune status.")
end
else
user:SendData(Bot, "You provided insufficient information for me to run the specified command.")
end
end

function CheckNickImmune(user)
found = 0
for i=1,ImmunesTotal,1 do
if rawget(ImmunesList,i) == user.sName then
found = 1
break
end
end
-- returns 1 if user specified is Immuned
return found
end

function CheckUserNickImmune(opNick)
errlvl = 0
for i=1,ImmunesTotal,1 do
if rawget(ImmunesList,i) == opNick then
errlvl = 1
break
end
end
-- returns 1 if user specified is Immuned
return errlvl
end

function GetArgML(data)
s,e,cmd,arg = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
return arg
end

function GetLongArgML(data)
s,e,cmd,arg = strfind(data, "%b<>%s+(%S+)%s+(.+)*")
return arg
end

function DataArrival(user,data)
if (strsub(data,1,1)=="<") or (strsub(data,1,4)=="$To:") then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")

if (cmd=="!addimmune" or cmd == "!immune") then
if user.bOperator then
DoAddImmunes(user,data)
return 1
end

elseif (cmd=="!deleteimmune" or cmd == "!delimmune") then
if user.bOperator then
DoDeleteImmunes(user,data)
return 1
end
elseif (cmd=="!showimmune" or cmd == "?immune") then
if user.bOperator then
ShowImmunes(user)
return 1
end

elseif (cmd=="!banip") then
if user.bOperator then
BanIp(user,data)
end
end
end
end

function OpConnected(user)
immune=CheckNickImmune(user)
if immune == 1 then
user:SendData(Bot, "Welcom there, lucky guy,... ;o)")
else
-- Do Your Code There
end
end

function NewUserConnected(user)
immune=CheckNickImmune(user)
if immune == 1 then
user:SendData(Bot, "Welcom there, lucky guy,... ;o)")
else
-- Do Your Code There
end
end

function BanIp(user,data)
arg = GetLongArgML(data)
if arg ~= nil then
ipimmune = CheckIpImmunes(arg)
if ipimmune == 1 then
SendToOps(Bot, user.sName.." has tried to ban "..arg.." as it was an Ip immuned,... Bo0h!!")
user:SendData(Bot,"You can't do a BanIp on such Ip!")
return 1
else
end
else
user:SendData(Bot, "You provided insufficient information for me to run the specified command.")
end
end

function CheckIpImmunes(arg)
ipimmune = 0
for a,b, in IpImmunesList do
if arg == b then
ipimmune == 1
end
end
return ipimmune
end
-----
Hoping it works,,

Good test & script with this example,, :)

l8tr,, ;o)
Title:
Post by: pHaTTy on 06 December, 2003, 15:00:26
excellent when i lost all my scripts in hdd failure, i never did find that one :))

ty guibs nearly re-done my collection wooo loool :))
Title:
Post by: [NL]trucker on 06 December, 2003, 23:00:18
guibs

thanks alot was waiting fo this one. ';))


now one request left

can you make it so that it also logs the one who trys to kick the users in immunelist?

and as far as i understand if i want to make a command not  to work i need to put [--] infront of that line? right?


will test this script as soon as i got my comp back online
had a crash last thursday and i couldnt fix the prob so i had to bring it to the shop (:- but hopefully it will be back on monday.

then i will test it.
Title: Syntax error
Post by: Snoris on 07 December, 2003, 23:40:24
syntax error `in* expected;
 last token read `; at line 261 in string "--immune-example script v1.1 By Guibs


-what does it mean??
Title:
Post by: Guibs on 08 December, 2003, 03:30:37
Hi there,,

Phatty,
pleasure to help, m8,, ;o)
Catch u soon on checkers,,... when you learn a few more about,... ^^

[NL]trucker,,
yw too,, ;)
> can you make it so that it also logs the one who trys to kick the users in immunelist?  < if i get it & if you want,, a message could be send to the ops on a 'bad kick', yep, .. tell me if i get your request,... :)

Snooris,
Be sure to take & use the code after the line:
----
 > code: <
----
I get none syntax error on a simple restart script there,...

l8tr,, ;)
Title:
Post by: pHaTTy on 08 December, 2003, 05:58:43
hmm sorry guibs you just aint good enuff :P beat ya in that one ;)
Title:
Post by: Guibs on 08 December, 2003, 06:03:43
erf,... easy,.... you give up on the revenge,... ;)
Title:
Post by: pHaTTy on 08 December, 2003, 06:08:38
loooooooool whatevr :P
Title:
Post by: [NL]trucker on 08 December, 2003, 19:53:41
Guibs

> can you make it so that it also logs the one who trys to kick the users in immunelist?

< if i get it & if you want,, a message could be send to the ops on a 'bad kick', yep, .. tell me if i get your request,... :)


almost m8 i just want it to LOG the one who tried to kick a immune user.
No need for messages send to the OPs

btw

do i need to make the log-files or are they made automatticly?
and if so where are they placed?
Title:
Post by: [NL]trucker on 08 December, 2003, 22:48:34
sorry m8  ;(


i have a problem/bug

in this section function CheckIpImmunes(arg)
   ipimmune = 0
   for a,b, in IpImmunesList do
      if arg == b then
         ipimmune == 1
      end
   end
   return ipimmune

Syntax error: `in' expected;
  last token read: `,' at line 243 in file `E:\==DC==\ptotaxbuild15.16\scripts\immune.lua'

dont know what is wrong (:-
Title:
Post by: plop on 09 December, 2003, 02:18:14
for a,b, in IpImmunesList do
after a,b  is an , 2 much.

plop
Title:
Post by: Snoris on 09 December, 2003, 07:08:15
QuoteOriginally posted by plop
for a,b, in IpImmunesList do
after a,b  is an , 2 much.

plop

noticed that to after a while :]
Title:
Post by: [NL]trucker on 09 December, 2003, 15:21:32
another one

i have removed the second , now i get this:

Syntax error: `=' expected;
  last token read: `==' at line 245 in file `E:\==DC==\ptotaxbuild15.16\scripts\immune.lua'



in this section function CheckIpImmunes(arg)
ipimmune = 0
for a,b  in IpImmunesList do
if arg == b then
ipimmune == 1     <--line 245
end
end
return ipimmune
Title:
Post by: plop on 09 December, 2003, 15:57:35
QuoteOriginally posted by [NL]trucker
another one

i have removed the second , now i get this:

Syntax error: `=' expected;
  last token read: `==' at line 245 in file `E:\==DC==\ptotaxbuild15.16\scripts\immune.lua'



in this section function CheckIpImmunes(arg)
ipimmune = 0
for a,b  in IpImmunesList do
if arg == b then
ipimmune == 1     <--line 245
end
end
return ipimmune
it expects 1 = not 2.

plop
Title:
Post by: [NL]trucker on 09 December, 2003, 18:52:10
Thnx m8

that did it :-))

working fine now Guibs thanks alot to all off you .
Title:
Post by: Ricky12 on 05 January, 2004, 21:12:45
I installed the script and I get this....
Syntax Error: `in' expected;
  last token read: `,' at line 244 in string "
..."

the script looks like this at the moment...
function CheckIpImmunes(arg)
   ipimmune = 0
   for a,b, in IpImmunesList do
      if arg == b then
         ipimmune == 1
      end
   end
   return ipimmune
end

I read the other replies and I dont under stand what to do. I tried to fix it and it still gave the the same problem. PLease any help would be nice. :rolleyes:
Title:
Post by: plop on 06 January, 2004, 02:07:07
QuoteOriginally posted by Ricky12
I installed the script and I get this....
Syntax Error: `in' expected;
  last token read: `,' at line 244 in string "
..."

the script looks like this at the moment...
function CheckIpImmunes(arg)
   ipimmune = 0
   for a,b, in IpImmunesList do
      if arg == b then
         ipimmune == 1
      end
   end
   return ipimmune
end

I read the other replies and I dont under stand what to do. I tried to fix it and it still gave the the same problem. PLease any help would be nice. :rolleyes:
check back and change the next marked lines.

function CheckIpImmunes(arg)
   ipimmune = 0
   for a,b, in IpImmunesList do   <-------------- remove the , after the b
      if arg == b then
         ipimmune == 1  <----------------- remove 1 =
      end
   end
   return ipimmune
end

thats all.

plop
Title:
Post by: Ricky12 on 06 January, 2004, 06:12:01
Thanks it works now!!! Keep up the good work!!  :] And I look foward to downloading more scripts. ;)
Title:
Post by: Devastator on 29 January, 2004, 17:00:02
Syntax Error: `then' expected;
  last token read: `=' at line 230

thats an error i get and sadly i dnt understand it.....i think ma new years resolution is 2 learn LUA *-) :-p

plz sum1 help me with that cos i've stared at it 4 ages but still i'm useless.

Thanx

Devastator
Title:
Post by: [NL]trucker on 29 January, 2004, 19:47:13
devastator

 look in the posts above and then post your question like we all did maybey then we can help ya.

so post the piece where it is all about.

QuoteSyntax error: `=' expected;
last token read: `==' at line 245 in file `E:\==DC==\ptotaxbuild15.16\scripts\immune.lua'



in this section function CheckIpImmunes(arg)
ipimmune = 0
for a,b in IpImmunesList do
if arg == b then
ipimmune == 1 <--line 245
end
end
return ipimmune

something like this.
Title: Nice one!!!
Post by: enema on 04 November, 2004, 15:07:42
Only thing - I still can kick immune users.. Can someone fix this little bug in this script??
Title:
Post by: enema on 10 November, 2004, 20:38:20
Please, someone help me! My problem is, that I want to make some users immune from kicks, but I dont want them give any special profile! If you cant edit this one, then please give me something better! Please!