PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: tamilzone on 22 December, 2003, 20:27:11

Title: Need Help With This Script
Post by: tamilzone on 22 December, 2003, 20:27:11
BotName="[TZH Hub]"
allowConnSpeed={}
allowConnSpeed["28.8Kbps"]=1
allowConnSpeed["33.6Kbps"]=1
allowConnSpeed["56Kbps"]=1
allowConnSpeed["ISDN"]=1
allowConnSpeed["DSL"]=1
allowConnSpeed["Cable"]=1
allowConnSpeed["LAN(T1)"]=1
allowConnSpeed["LAN(T3)"]=1
allowConnSpeed["Satellite"]=1
SlotspPerConnSpeed={}
SlotspPerConnSpeed["28.8Kbps"]=15
SlotspPerConnSpeed["33.6Kbps"]=15
SlotspPerConnSpeed["56Kbps"]=15
SlotspPerConnSpeed["ISDN"]=15
SlotspPerConnSpeed["DSL"]=15
SlotspPerConnSpeed["Cable"]=15
SlotspPerConnSpeed["LAN(T1)"]=15
SlotspPerConnSpeed["LAN(T3)"]=15
SlotspPerConnSpeed["Satellite"]=15
AllowNeoModus=1
AllowDCPP=1
AllowMLDonkey=1
AllowReplika=1
AllowPePeK=1
trigs={["owner"]="[Admin]?Vinoth",["hubaddress"]="tamilzone.no-ip.com",["hubpage"]="htt?://www.tamilzone.ch.vu",["welcome"]="Welcome to Tamil Zone Hub",["ownerplace"]="Zurich,Switerland"}
awayArray={}
antiadvertisingtrigs={["dns2go"]=1,["ip.com"]=1,["serveftp"]=1,["kickass.net"]=1,["dyndns"]=1,["mine.nu"]=1}
seenArray={}
CommandFlood="flood"
CommandMassMessage="mm"
CommandMassMessageOps="mmops"
ComandAway="away"
ComandBack="back"
CommandAddGBEntry="#addGBEntry"
CommandReadGB="#readGB"
CommandMyIP="myip"
CommandOpenBotDialog="opbot"
CommandHelp="help"
--intern constants
cKB=1024
cMB=1024*cKB
cGB=1024*cMB
--helper functions
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+(.*)")
   --remove pipe
   message = strsub(message,1,strlen(message)-1)
   return whoTo,from,message
end
function ParseMCM(data)
   s,e,message = strfind(data, "%b<> (.*)")
   --remove pipe
   message = strsub(message,1,strlen(message)-1)
   return message
end

function ParseMyInfoString(data)
s,e,description,speed,email,share = strfind(data, "$MyINFO $ALL ([^$]+)$ $([^$]*)$([^$]*)$([^$]+)")
--remove speed identifier
speed = strsub(speed,1,strlen(speed)-1)
return description,speed,email,share
end

function ParseDCPPDescription(description)
_,b, slots = strfind(description,"S:(%d+)")
_,b, dcver = strfind(description,"V:(%x.%x+)")
_,b, slots = strfind(description,"S:(%d+)")
_,b, hubs = strfind(description,"H:(%d+)")
_,b, bs = strfind(description,"B:(%x+)")
slots=tonumber(slots)
hubs=tonumber(hubs)


return dcver, slots, hubs, bs
end

function GetCommand(message)
s,e,command=strfind(message,"(%S+)")
return command
end

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

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


function tokenize (inString,token)
_WORDS = {}
local matcher = "([^?"..token.."]+)"
gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
return _WORDS
end
--checker functions
function MaxSlotsCheck(slots, connectiontype)
if (SlotspPerConnSpeed[connectiontype]>=slots)then
return 1
else
return 0
end
end

function IsDCPPCLient(description)
if strfind(description,"<++") then
return 1
else
return 0
end
end

function IsConnAllowed(speed)
if (allowConnSpeed[speed]==1)then
return 1
else
return 0
end
end

function CheckClientType(description)
local result=1

if (AllowDCPP==0) then
   if (IsDCPPCLient(description)) then
      result=0
   end
end
if (AllowMLDonkey==0) then
   if (strfind(description,"mldonkey")) then
      result=0
   end
end

if (AllowReplika==0) then
   if (strfind(description,"REPLIKA")) then
      result=0
   end
end
if (AllowPePeK==0) then
   if (strfind(description,"Pepek")) then
      result=0
   end
end


return result
end
function DoFlood(victim)
user=GetItemByName(victim)
for a=1,600 do
   user:SendPM(BotName..a,"you are flooded ....")
end
end
function ShowHelp(target)
target:SendPM(BotName,"Hi, I'm the incharge of this hub.I am providing you these commands for you.I will only follow these exact commands.")
if (target.bOperator) then
target:SendPM(BotName,"...........OP-COMMANDS.............")
target:SendPM(BotName,CommandFlood.." username: floods a user with 600 pms")
target:SendPM(BotName,CommandMassMessage.." text: sends a message to all users")
target:SendPM(BotName,CommandMassMessageOps.." text: sends a message to all ops")
target:SendPM(BotName,CommandOpenBotDialog..": Opens a window for the mainbot")
target:SendPM(BotName,"hideme: Hidden mode for you")
target:SendPM(BotName,"unhideme: Visible mode for you")
target:SendPM(BotName,"drop user: Drops a user")
target:SendPM(BotName,"ban user: Bans a user")
target:SendPM(BotName,"unban user: Unbans a user")
target:SendPM(BotName,"addvip name password: Adds a vip")
target:SendPM(BotName,"removevip name: Removes a vip")
end
target:SendPM(BotName,"...........USER-COMMANDS...............")
target:SendPM(BotName,CommandMyIP..": -=[Shows your own ip]=-")
target:SendPM(BotName,CommandHelp..": -=[Shows the current help window]=-")
target:SendPM(BotName,"time : [=-Shows the current date/time]=-")
target:SendPM(BotName,"seen user: -=[When was the user online?]=-")

target:SendPM(BotName,"...........AWAY-BOT..............")
target:SendPM(BotName,"awayreason: -=[announces that you are away]=-")
target:SendPM(BotName,"back : -=[announces that you are back]=-")

target:SendPM(BotName,"...........GUESTBOOK............")
target:SendPM(BotName,"#addGBEntry text: [=-adds a new entry to the guestbook]=-")
target:SendPM(BotName,"#readGB: -=[shows you the entire Guestbook]=-")
end
function HandleComand(curUser,message)
command=GetCommand(message)
if (curUser.bOperator) then
if (command==CommandFlood) then
   victim=GetOneParam(message)
   if (victim~=nil) then
      DoFlood(victim)
   else
      curUser:SendPM(BotName,"Wrong syntax - use that one: "..CommandFlood.." username")
   end
end
if (command==CommandMassMessage) then
   masstext=GetOneParam(message)
   if (masstext~=nil) then
      SendPmToAll(BotName,masstext)
   else
      curUser:SendPM(BotName,"Wrong syntax - use that one: "..CommandMassMessage.." text")
   end
end
if (command==CommandMassMessageOps) then
   masstext=GetOneParam(message)
   if (masstext~=nil) then
      SendPmToOps(BotName,masstext)
   else
      curUser:SendPM(BotName,"Wrong syntax - use that one: "..CommandMassMessageOps.." text")
   end
end
if (command==CommandOpenBotDialog) then
   curUser:SendPM(BotName,"How may i help?")
end
if (command=="hideme") then
   frmHub:UnregBot(curUser.sName)
end
if (command=="unhideme") then
   frmHub:RegBot(curUser.sName)
end
if (command=="drop") then
   victim=GetOneParam(message)
   if (victim~=nil) then
      tempuser=GetItemByName(victim)
      tempuser:Disconnect()
   else
      curUser:SendPM(BotName,"Wrong syntax - use that one: drop username")
   end
end
if (command=="ban") then
   victim=GetOneParam(message)
   if (victim~=nil) then
      tempuser=GetItemByName(victim)
      tempuser:NickBan()
      tempuser:Ban()
   else
      curUser:SendPM(BotName,"Wrong syntax - use that one: ban username")
   end
end
if (command=="unban") then
   victim=GetOneParam(message)
   if (victim~=nil) then
      Unban(victim)
   else
      curUser:SendPM(BotName,"Wrong syntax - use that one: unban username")
   end
end
if (command=="addvip") then
   vipname,vippass=GetTwoParam(message)
   if (vippass~=nil) then
      frmHub:AddRegUser(vipname,vippass,0)
   else
      curUser:SendPM(BotName,"Wrong syntax - use that one: addvip username password")
   end
end
if (command=="removevip") then
   vipname=GetOneParam(message)
   if (vipname~=nil) then
      frmHub:DelRegUser(vipname)
   else
      curUser:SendPM(BotName,"Wrong syntax - use that one: removevip username")
   end
end
end
if (command==CommandMyIP) then
   curUser:SendPM(BotName, "Your IP is "..curUser.sIP)
end
if (command==CommandHelp) then
   ShowHelp(curUser)
end
if (command==ComandAway) then
   arg=GetOneParam(message)
SendToAll(BotName,date("User "..curUser.sName.." told us at %T that he is away, because :")..arg.." ")
awayArray[curUser.sName]=arg
end
if (command==ComandBack) then
if (awayArray[curUser.sName]~=nil) then
awayArray[curUser.sName]=nil
SendToAll(BotName,date("User "..curUser.sName.." told us at %T that he is back"))
end
end
if (command=="seen") then
   target=GetOneParam(message)
   if (seenArray[target]~=nil) then
      curUser:SendPM(BotName,seenArray[target])
   else
      curUser:SendPM(BotName,"The user "..target.." wasnt seen here .... ")
   end
end
if (command==CommandAddGBEntry) then
arg= GetOneParam(message)
local handle=openfile("guestbook.dat","a")
write(handle,"("..curUser.sName..") wrote :"..arg.."?")
curUser:SendPM(BotName,"Guestbook entry saved ....")
SendToAll(BotName, "New entry in the guestbook!")
closefile(handle)
end
if (command==CommandReadGB) then
handle2=openfile("guestbook.dat","r")
if (handle2~=nil) then
line = read(handle2,"*a")
line=strsub(line,1,strlen(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
curUser:SendPM(BotName,linearray)
end
closefile(handle2)
end
end
if (command=="time") then
   SendToAll(BotName, date("Today is %A the %D. Time is %T"))
end
--triggers
for key, value in trigs do
if( strfind( strlower(message), key) ) then
   SendToAll( BotName, value )
   break
   end
end
--antiadvertising
for key, value in antiadvertisingtrigs do
if( strfind( strlower(), key) ) then
   SendToAll( BotName, curUser.sName.." has been kicked for advertising. His IP was: "..curUser.sIP )
   curUser:Disconnect()
   break
   end
end
end


function Main()
frmHub:RegBot(BotName)
end
function OpConnected(curUser)
   SendToAll(BotName,"The OP "..curUser.sName.." has entered the Tamil Zone Hub")
   ShowHelp(curUser)
end
function OpDisconnected(curUser)
   SendToAll(BotName,"Our OP "..curUser.sName.." has left the Tamil Zone hub.")
seenArray[curUser.sName]=date(curUser.sName.." last seen at %d/%m/%Y %T .")
end
function NewUserConnected(curUser)
description,speed,email,share=ParseMyInfoString(curUser.sMyInfoString)
if (IsConnAllowed(speed)~=1) then
   curUser:SendPM(BotName,"Your connection-speed is not allowed in here -> disconnected"..IsConnAllowed(speed))
   curUser:Disconnect()
end
CheckClientType(description)
if (IsDCPPCLient(description)==1)then
dcver, slots, hubs, bs=ParseDCPPDescription(description)
if (MaxSlotsCheck(slots, speed)~=1) then
   curUser:SendPM(BotName,"You just have too much slots per connection. You could have max: "..SlotspPerConnSpeed[speed])
   curUser:Disconnect()
end
if (bs~=nil) then
if (tonumber(bs)<99) then
   curUser:SendPM(BotName,"You have a too less upload limit ....")
   curUser:Disconnect()
end
end
end
end
function UserDisconnected(curUser)
seenArray[curUser.sName]=date(curUser.sName.." last seen at %d/%m/%Y %T .")
end


function DataArrival(curUser,data)
local MessageRecognized = 0
if (isPM(data)==1) then
   whoto,from,message=ParsePM(data)
   MessageRecognized=1
if (awayArray[whoto]~= nil) then
curUser:SendPM(whoto,"I am currently away, because of: "..awayArray[whoTo])
end
end
if (isMCM(data)==1) then
   message=ParseMCM(data)
   from=curUser.sName
   whoto=BotName
   MessageRecognized=1
end
if ((MessageRecognized==1)and(whoto==BotName)) then
   HandleComand(curUser,message)
end
end







whats wrong with this file?




tamilzone.
Title:
Post by: Snoris on 22 December, 2003, 20:33:17
Quotewhats wrong with this file?

Erhm....Nothing??
Don't get any syntax..

But I can tell you this...Next time you post a script do it the right way :]

Use the ['code'] and ['/code']  (Witout the ')
Before and after the script ;)
Title:
Post by: ((UKSN))shad_dow on 28 January, 2004, 13:10:35
hello all

yea theres no syntex error when u check but as soon as u run the sripct this syntex error appers

Syntax Error: bad argument #1 to `strlower' (string expected, got no value)

thinks thats what he was on about , but i still learning and i cant find out how to correct maybe phatty,chilla,plop etc can take a look for him

c ya l8z
Title:
Post by: c h i l l a on 28 January, 2004, 14:11:32
sure, would help you, do you know when the error occurs, then I don't have to search for myself.
Title:
Post by: ((UKSN))shad_dow on 28 January, 2004, 15:09:56
yo chilla , any time u put a command in main it does the command and then reports that error
Title:
Post by: Event_Horizon on 28 January, 2004, 22:20:41
just an idea.. but registred Bots shouldn't have spaces in the name.... or am I wrong ???
Title:
Post by: plop on 28 January, 2004, 23:22:12
QuoteOriginally posted by Event_Horizon
just an idea.. but registred Bots shouldn't have spaces in the name.... or am I wrong ???
indeed, thats not allowed but the error comes from the anti advertising part.
strlower() <----- that should have something 2 do.
for example strlower(data)

plop
Title:
Post by: c h i l l a on 28 January, 2004, 23:50:09
defently plop, thats a big mistake

I think it should be strlower(message)

and the PM error also will diasspear when you use one word as botname.
Title:
Post by: plop on 29 January, 2004, 00:32:50
QuoteOriginally posted by c h i l l a
defently plop, thats a big mistake

I think it should be strlower(message)

and the PM error also will diasspear when you use one word as botname.
didn't check that far.
just did a search for strlower and found it empty.

plop
Title:
Post by: ((UKSN))shad_dow on 29 January, 2004, 01:05:42
Quotedefently plop, thats a big mistake

I think it should be strlower(message)

and the PM error also will diasspear when you use one word as botname

well done chilla u were right all than need was to change strlower() to strlower(message) :)

right now going to studdy this script and disect it in to my brain for a few hrs to see how these commands work as a diffent script code-ed a different way

thx to all

l8z

(Need More scripts for more input :) :) :) :)  )
Title:
Post by: kepp on 29 January, 2004, 07:51:40
QuoteOriginally posted by ((UKSN))shad_dow
Quotedefently plop, thats a big mistake

I think it should be strlower(message)

and the PM error also will diasspear when you use one word as botname

well done chilla u were right all than need was to change strlower() to strlower(message) :)

right now going to studdy this script and disect it in to my brain for a few hrs to see how these commands work as a diffent script code-ed a different way

thx to all

l8z

(Need More scripts for more input :) :) :) :)  )

That's the spirit :D

When you feel ready, You can try to make a small script that sends Different Welcome messages for each profile :)
Title:
Post by: ((UKSN))shad_dow on 29 January, 2004, 13:11:50
-- created by ((UKSN))shad_dow
--  welcome script for master,op,vip,guest,reg and admin
--  idea for testing my lua so far ,by kepp





sBot = "-=Welcome-Home=-"


function OpConnected(user)

if user.iProfile == 0 then
     WelcomeMaster(user)
return 1
end
if user.iProfile == 1 then
     WelcomeOP(user)
return 1
end
end




function NewUserConnected(user)

     if user.iProfile == 2 then
     WelcomeVIP(user)
return 1
end
 if user.iProfile == 3 then
      WelcomeReg(user)
return 1
end
if user.iProfile == 4 then
      WelcomeGuest(user)
return 1
end
if user.iProfile == 5 then
      WelcomeAdmin(user)
return 1
end
  end


function WelcomeVIP(user)
SendToAll(sBot, "VIP "..user.sName.." has entered the Hub, Welcome Home.")
end

function WelcomeReg(user)
SendToAll(sBot, "REG "..user.sName.." has entered the Hub, Welcome Home.")
end

function WelcomeOP(user)
SendToAll(sBot, "OP "..user.sName.." has entered the Hub, Welcome Home.")
end

function WelcomeMaster(user)
SendToAll(sBot, "Hub owner "..user.sName.." has entered the Hub, Welcome Home.")
end

function WelcomeVIP(user)
SendToAll(sBot, "VIP "..user.sName.." has entered the Hub, Welcome Home.")
end

function WelcomeGuest(user)
SendToAll(sBot, "Guest "..user.sName.." has entered the Hub, Welcome Home.")
end

function WelcomeAdmin(user)
SendToAll(sBot, "Admin "..user.sName.." has entered the Hub, Welcome Home.")
end




function OPDisconnected(user)
if user.iProfile == 0 then
SendToAll(sBot, "Master "..user.sName.." has left the Hub, See you soon")
return 1
end
if user.iProfile == 1 then
SendToAll(sBot, "OP "..user.sName.." has left the Hub, See you soon")
return 1
end
end



function UserDisconnected(user)
if user.iProfile == 0 then
SendToAll(sBot, "Master "..user.sName.." has left the Hub, See you soon")
return 1
end
if user.iProfile == 1 then
SendToAll(sBot, "OP "..user.sName.." has left the Hub, See you soon")
return 1
end
if user.iProfile == 2 then
SendToAll(sBot, "VIP "..user.sName.." has left the Hub, See you soon")
return 1
end
if user.iProfile == 3 then
SendToAll(sBot, "REG "..user.sName.." has left the Hub, See you soon")
return 1
end
if user.iProfile == 4 then
SendToAll(sBot, "Guest "..user.sName.." has left the Hub, See you soon")
return 1
end
if user.iProfile == 5 then
SendToAll(sBot, "Admin "..user.sName.." has left the Hub, See you soon")
return 1
end
end


hello again Kepp

right i think idid right , well its works and no syntex errors :D

even added meassges for when profile dissconecst (bad spelling) , oh i used a function for each meassage for 2 reasons 1) easy to find errors , 2) easy to say change welcome messgae for say VIP :)

think i might go and try to use the Elseif command ,might make it look better ???

oh marks out of 10 plz :D :D

cya in bit
Title:
Post by: kepp on 29 January, 2004, 13:37:02
Very well :)

Yep, 'elseif' is good too use when possible

Yet another test ;)
To get the share amount from a user, using His InfoString.
Have fun

-- created by ((UKSN))shad_dow
--  welcome script for master,op,vip,guest,reg and admin
--  idea for testing my lua so far ,by kepp





sBot = "-=Welcome-Home=-"


function OpConnected(user)

if user.iProfile == 0 then
WelcomeMaster(user)
return 1

elseif user.iProfile == 1 then
WelcomeOP(user)
return 1
end
end



function NewUserConnected(user)

if user.iProfile == 2 then
WelcomeVIP(user)
return 1

elseif user.iProfile == 3 then
WelcomeReg(user)
return 1

elseif user.iProfile == 4 then
WelcomeGuest(user)
return 1

elseif user.iProfile == 5 then
      WelcomeAdmin(user)
return 1
end
end


function WelcomeVIP(user)
SendToAll(sBot, "VIP "..user.sName.." has entered the Hub, Welcome Home.")
end

function WelcomeReg(user)
SendToAll(sBot, "REG "..user.sName.." has entered the Hub, Welcome Home.")
end

function WelcomeOP(user)
SendToAll(sBot, "OP "..user.sName.." has entered the Hub, Welcome Home.")
end

function WelcomeMaster(user)
SendToAll(sBot, "Hub owner "..user.sName.." has entered the Hub, Welcome Home.")
end

function WelcomeVIP(user)
SendToAll(sBot, "VIP "..user.sName.." has entered the Hub, Welcome Home.")
end

function WelcomeGuest(user)
SendToAll(sBot, "Guest "..user.sName.." has entered the Hub, Welcome Home.")
end

function WelcomeAdmin(user)
SendToAll(sBot, "Admin "..user.sName.." has entered the Hub, Welcome Home.")
end




function OPDisconnected(user)
if user.iProfile == 0 then
SendToAll(sBot, "Master "..user.sName.." has left the Hub, See you soon")
return 1

elseif user.iProfile == 1 then
SendToAll(sBot, "OP "..user.sName.." has left the Hub, See you soon")
return 1
end
end



function UserDisconnected(user)
if user.iProfile == 0 then
SendToAll(sBot, "Master "..user.sName.." has left the Hub, See you soon")
return 1

elseif user.iProfile == 1 then
SendToAll(sBot, "OP "..user.sName.." has left the Hub, See you soon")
return 1

elseif user.iProfile == 2 then
SendToAll(sBot, "VIP "..user.sName.." has left the Hub, See you soon")
return 1

elseif user.iProfile == 3 then
SendToAll(sBot, "REG "..user.sName.." has left the Hub, See you soon")
return 1

elseif user.iProfile == 4 then
SendToAll(sBot, "Guest "..user.sName.." has left the Hub, See you soon")
return 1

elseif user.iProfile == 5 then
SendToAll(sBot, "Admin "..user.sName.." has left the Hub, See you soon")
return 1
end
end

Title:
Post by: plop on 29 January, 2004, 13:58:33
QuoteOriginally posted by ((UKSN))shad_dow
hello again Kepp

right i think idid right , well its works and no syntex errors :D

even added meassges for when profile dissconecst (bad spelling) , oh i used a function for each meassage for 2 reasons 1) easy to find errors , 2) easy to say change welcome messgae for say VIP :)

think i might go and try to use the Elseif command ,might make it look better ???

oh marks out of 10 plz :D :D

cya in bit
take a look here (http://board.univ-angers.fr/thread.php?threadid=1064&boardid=6&styleid=1) for a next step.
but kepp's idea is really good 2.

btw nice 2 see you teaching kepp.

plop
Title:
Post by: ((UKSN))shad_dow on 29 January, 2004, 15:54:31
-- users share size by ((uksn))shad_dow
-- this test  from Kepp , tst = optaing share size from myinfo string
-- command !sharesize name

botname = "shareinfo"

function MyInfoString(data)
s,e,share = strfind(data, "$MyINFO $ALL ([^$]+)$ $([^$]*)$([^$]*)$([^$]+)")

return share
end

function DataArrival(user, data)

if( strsub(data, 1, 1) == "<" ) then
      data=strsub(data,1,strlen(data))
      s,e,cmd,Name = strfind( data, "%b<>%s+(%S+)%s+(%S+)" )
      if (user.bOperator) then
         if (cmd=="!sharesize") then
            name = GetItemByName(Name)
            share=MyInfoString(user.sMyInfoString)
            share1 = share / (1024*1024*1024)
            user:SendPM(botname, "user "..Name.." is sharing "..share1.."Gb")
            return 1
         end
      end
   end
end
 





Syntax Error: attempt to perform arithmetic on global `share' (a string value) ????????????????

so tryed this way        
botname = "shareinfo"
             
function DataArrival(user, data)

if( strsub(data, 1, 1) == "<" ) then
      data=strsub(data,1,strlen(data))
      s,e,cmd,Name,share = strfind(data, "$MyINFO $ALL ([^$]+)$ $([^$]*)$([^$]*)$([^$]+)")
      return share
       end
        if (user.bOperator) then
         if (cmd=="!checkshare") then
            Name2 = GetItemByName(Name)
            share1 = share / (1024*1024*1024)
            user:SendPM(botname, "user "..Name2.." is sharing "..share1.."Gb")
            return 1
         end
      end
   end

got no syntex errors , and no pm from bot ???????

totaly confused now lol / brb need coffee lol

PS . plop thankx for the link , and Kepp thankx so far for putting up with a newbee scripter :D
Title:
Post by: plop on 29 January, 2004, 16:15:33
QuoteOriginally posted by ((UKSN))shad_dow
Syntax Error: attempt to perform arithmetic on global `share' (a string value) ????????????????

got no syntex errors , and no pm from bot ???????

totaly confused now lol / brb need coffee lol

PS . plop thankx for the link , and Kepp thankx so far for putting up with a newbee scripter :D
strfind the name says the answer, it returns a string.
share = tonumber(share) solves your problem.

btw beside the thread i gave you there are some handy lessons from phatty and simple howto's from me.

plop
Title:
Post by: ((UKSN))shad_dow on 29 January, 2004, 16:30:44
cheerrs plop

yea been using phatty how to make a bot and some others too :) .. only thing that gets is how many ways u can make a simple script, as i keep find when exsameing other scripts :)

ok gone to try that bit of help , il post script here with or with out errors :) (then Kepp can give me a nother test to try :) ).. and thx for helping , u , phatyy , nightlinch and Kepp are good to me for putting up with a newbee :D
Title:
Post by: ((UKSN))shad_dow on 29 January, 2004, 20:48:49
ello plop and Kepp

right when i put   share = tonumber(share)  any where in the script i get

Syntax Error: attempt to perform arithmetic on global `share' (a nil value)

so i reckon its got to be some thing to do with

s,e,share = strfind(data, "$MyINFO $ALL ([^$]+)$ $([^$]*)$([^$]*)$([^$]+)")  (i hope)

all the code below



-- users share size by ((uksn))shad_dow
-- this test  from Kepp , tst = optaing share size from myinfo string
-- command !sharesize name
-- with help from plop and Kepp

botname = "shareinfo"



             
function MyInfoString(data)
s,e,share = strfind(data, "$MyINFO $ALL ([^$]+)$ $([^$]*)$([^$]*)$([^$]+)")
share = tonumber(share)
return share
end

function DataArrival(user, data)

if( strsub(data, 1, 1) == "<" ) then
      data=strsub(data,1,strlen(data))
      s,e,cmd,Name = strfind( data, "%b<>%s+(%S+)%s+(%S+)" )
      if (user.bOperator) then
         if (cmd=="!sharesize") then
            name = GetItemByName(Name)
            share=MyInfoString(user.sMyInfoString)
            share1 = share / (1024*1024*1024)
            user:SendPM(botname, "user "..name.." is sharing "..share1.."Gb")
            return 1
         end
      end
   end
end

waiting quitely with out clue as to what i need to to make this work  ?(
Title:
Post by: VidFamne on 29 January, 2004, 22:04:38
try this line;s,e,description,speed,email,share = strfind(data, "$MyINFO $ALL ([^$]+)$ $([^$]*)$([^$]*)$([^$]+)")  instaed of this;s,e,share = strfind(data, "$MyINFO $ALL ([^$]+)$ $([^$]*)$([^$]*)$([^$]+)")
Title:
Post by: plop on 29 January, 2004, 22:52:29
((UKSN))shad_dow if you look @ what VidFamne posted you see he added a bunch of things between s,e, and share = strfind.
the reason is simple
([^$]+)   <--- the ( ) here means the strfind has 2 extract something from the given string and add that 2 for example share, so if you call share (a local or global vallue)  later in your script you get the vallue you found on this.
the way this works isn't 2 hard.
s,e,1,2,3,4 = strfind(string, "(1)(2)(3)(4)")

now the error you made was like this
s,e,4= strfind(string, "(1)(2)(3)(4)")
which means 4 actualy gets the 1st thing strfind has 2 find on your pattern, which is 1.
if you only want 2 find the share you can do like the next example.
s,e,4= strfind(string, "123(4)")

i hope you get the idea, if not don't fear 2 ask.
i rather explain something then fix a script for some1, even if explaining takes more time.

plop
Title:
Post by: kepp on 29 January, 2004, 23:12:40
Yep, Or go straight to the (4)

DATA = user.sMyInfoString

local s,e,version = strfind(DATA,"V:(%d.%d+) ")
^^   you see that one

that will take the version Nr after V:
in the InfoString

i can do this too i suppose :D

local s,e,version,mode = strfind(DATA,"V:(%d.%d+)M:(%a)")

So, in your case, you are only suppose to look for digits...

print a user.sMyInfoString and study what's in it, Then you might find a way :)
Title:
Post by: ((UKSN))shad_dow on 30 January, 2004, 02:09:36
cheers plop , thats was easy for me to start to digest as it was plain english :) .. (il read it agin tommorw )

right only 1 prob which i just relised is this :-

s,e,cmd,Name = strfind( data, "%b<>%s+(%S+)%s+(%S+)" )

and this :-

name = GetItemByName(Name)

brings up this syntex error :-

Syntax Error: attempt to concat global `name' (a nil value)

which i take means u the strfind is 1) wrong or 2) it should be a arg arry ????

!sharesize <- cmd
<--- should be vuale name that is type in

which i think should have been some like :-

s,e,cmd,name = strfind( data, "%b<>%s+(%S+)(%s+)%S+" ) instaed of  
s,e,cmd,name = strfind( data, "%b<>%s+(%S+)%s+(%S+)" ) i think

 time is 01:08 am UK  so il check back l8z need bed .

PS .. i learn more by understanding the code than having it done for me :)

NN
Title:
Post by: ((UKSN))shad_dow on 30 January, 2004, 02:17:49
Quoteprint a user.sMyInfoString and study what's in it, Then you might find a way :)

please  may i ask how i print that out , Kepp ???  :D


-----------------------------------------------------------------------

cheers plop , thats was easy for me to start to digest as it was plain english :) .. (il read it agin tommorw )

right only 1 prob which i just relised is this :-

s,e,cmd,Name = strfind( data, "%b<>%s+(%S+)%s+(%S+)" )

and this :-

name = GetItemByName(Name)

brings up this syntex error :-

Syntax Error: attempt to concat global `name' (a nil value)

which i take means  that strfind is 1) wrong or 2) it should be a arg arry ????

!sharesize <- cmd
<--- should be vuale name that is type in

which i think should have been some like :-

s,e,cmd,name = strfind( data, "%b<>%s+%S+(%s+)(%S+)" ) instaed of  
s,e,cmd,name = strfind( data, "%b<>%s+(%S+)%s+(%S+)" ) i think (tryed but dident work, nothing happened)



 time is 01:08 am UK  so il check back l8z need bed .

PS .. i learn more by understanding the code than having it done for me , and i learning alot by the help from u  lot :)

NN
Title:
Post by: VidFamne on 30 January, 2004, 03:03:21
All strings in 'data' ends with an end-pipe '|'.
So I think its best  to remove this in the
DataArrival() function with this line;data=strsub(data,1,strlen(data)-1)  -- remove endpipeand than you can uses,e,cmd,name = strfind( data, "%b<>%s+(%S+)%s+(%S+)" )
Title:
Post by: ((UKSN))shad_dow on 30 January, 2004, 03:16:55
cheers VidFamne

thats better , all so need to add a GetArg function :D

working script below :-

-- users share size by ((uksn))shad_dow
-- this test  from Kepp , test = optaing share size from myinfo string
-- command !sharesize name
-- with help from plop , Kepp  and VidFamne
-- had to include a GetArg fuction  

botname = "shareinfo"



             
function MyInfoString(data)
s,e,share = strfind(data, "$MyINFO $ALL [^$]+$ $[^$]*$[^$]*$([^$]+)")
share = tonumber(share)                    
return share
end

function GetArg(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) == "<" ) then
 
data=strsub(data,1,strlen(data)-1)
 
s,e,cmd = strfind( data, "%b<>%s+(%S+)" )  
       
      if (user.bOperator) then      
         if (cmd=="!share") then
            name=GetArg(data)
            local usr = GetItemByName(name)
            share = MyInfoString(user.sMyInfoString)
            share1 = share / (1024*1024*1024)
            user:SendPM(botname, "user "..name.." is sharing "..share1.." GB")
           
         end
      end
   end
end

Result :-

[02:02] <((UKSN))shad_dow> !share ((UKSN))shad_dow

 PM From Bot :-

[02:02] user ((UKSN))shad_dow is sharing 19.11080632638186 GB

big thx to Kepp and Plop :)

for teaching me alot and yet i still hungery for more :)
Title:
Post by: plop on 30 January, 2004, 04:38:23
just found a tiny error in the scripting.txt from ptokax.
GetItemByName(nick) - Returns user object of the nick
  nick - the nick of user.
should be.
GetItemByName(nick) - Returns user object of the nick, or returns nil if user is not in the hub.
  nick - the nick of user.

that hint from VidFamne was good but if you remove the end pipe you should always place it back later if data is send back out again.
the end pipe is | this character, so your SendPM line should be changed a little bit.
not a big error as many ppl forget it and it's actualy working without but it can cause problems.
user:SendPM(botname, "user "..name.." is sharing "..share1.." GB|")thats all 2 it.
also take a look @ my pattern match howto, that should help you on the things you don't understand fully yet on strfind.
same simple english.

plop
Title:
Post by: ((UKSN))shad_dow on 30 January, 2004, 12:22:16
hello again plop and Kepp

right i get to stright to the prob cos ur all pretty busy :)

right , i sort of undstand this :- (based on plops strfind post from before)

s,e,whoTo,from,message = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.*)")

so i tryed to take the command from main :-
if( strsub(data, 1, 1) == "<" ) then
 
data=strsub(data,1,strlen(data)-1)
 
s,e,cmd = strfind( data, "%b<>%s+(%S+)" )

and make pm only which i coded like this :-

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

but nowt happens so im stuck  ?(  ?(  ?(  ?(

i know ive gone wroung some where in the strfind command

please help
Title:
Post by: tezlo on 30 January, 2004, 13:13:50
ad pipe..
data=strsub(data,1,strlen(data)-1)
this appeared in one of the first scripts ever posted here
since then almost every script's DataArrival starts with this line

data = strsub(data, 1, -2)
does the same a tiny bit faster

but usually a strfind follows..
and you can easily deal with the pipe there
local s, e, cmd, args = strfind(data, "^%b<> (%S+)%s?(.*)|$")

so really theres no need to remove it
Title:
Post by: VidFamne on 30 January, 2004, 22:25:30
QuoteOriginally posted by tezlo
data=strsub(data,1,strlen(data)-1)
this appeared in one of the first scripts ever posted here
since then almost every script's DataArrival starts with this line
Is it what they called to re-use code? ;D
Title:
Post by: ((UKSN))shad_dow on 03 February, 2004, 11:10:09
ello again , thakns to all thats has help :)

right 1 simple little Q.  any body give me a idea how i would made the users share amount apper to all ops when a new user connects :) .. thank u all in advance :)