PtokaX forum

Development Section => HOW-TO's => HOW-TO requests => Topic started by: Psycho_Chihuahua on 25 August, 2004, 17:47:42

Title: Several questions...
Post by: Psycho_Chihuahua on 25 August, 2004, 17:47:42
how do i make an on/off switch for certain functions?

this one for instance:
function DataArrival( user , data )
if strsub( data , 1 , 7 ) == "$MyINFO" then
local _,_,openhubs = strfind( data , ".+H:(%d+)" );
if ( openhubs ~= "0" ) then
SendToNick( user.name , DisconnectMessage )
user:Disconnect()
end
end
end


Reason: I'm working on Black_Pearl 1.2 atm and i guess some (public) hubowners dont want this check to be done.

The other possibility would be to use it as an addon, hmmm dont know how to do that yet either.

Thanks for the effort ;)
Title: tt
Post by: Typhoon on 26 August, 2004, 02:16:43
you can do it like this ..


OpenCheck = 1  -- 1=on/0=off

function DataArrival( user , data )
      if strsub( data , 1 , 7 ) == "$MyINFO" then
         local _,_,openhubs = strfind( data , ".+H:(%d+)" );
         if OpenCheck == 1 then
            if (openhubs ~= "0") then
               SendToNick( user.name , DisconnectMessage )
               user:Disconnect()
            end
         end
      end
end



Hope it helps you to see the point ;)

Typhoon?
Title: tt
Post by: Psycho_Chihuahua on 01 September, 2004, 07:17:06
Thnx Typhoon


Well i got another Question:

How do i make a Bot read its variable (on/off) settings out of an *.ini file?

Settings needed are:
GuardianCheck = 1
notifyOps = 1
banuser = 1
GuardianFile = "scripts/Data/Blocklist/guarding.p2p"
denyMsg = "*** This is a private hub. You have no business here. - Dies ist ein privater Hub. Du hast hier nichts verloren."
banMsg = "*** Your IP has been banned. - Deine IP wurde gebannt"
OpenCheck = 1  -- 1=on/0=off
DisconnectMessage = "Du bist in einen oder mehreren Open Hubs. Dies verst?sst gegen unsere Regeln. Deshalb wird die Verbindung zur?ckgesetzt! - You are in one or more Open Hubs which is against our Rules!! Connection Terminated..."
Title: tt
Post by: BottledHate on 01 September, 2004, 08:34:34
this should help....

readfrom("yourfile.bleh")
while 1 do
   local line = read()
   if (line == nil) then
      break
   else
      if strsub(line,1,9) =="Status =" then
         setting1=strsub(line,9,srlen(line))
      elseif strsub(line..........................
         setting2=strsub(line...............
      end
end
readfrom()

-BH
Title: tt
Post by: Psycho_Chihuahua on 28 September, 2004, 02:09:51
ok..

lets say i have a script that has this in its Settings:
SendToMain = 0  -- Send in Main [if 0 send as PM]
then how would i make a cmd Trigger to change that

like !sendmainon sets it to 1 and !setmainoff sets it to 0?


The context its used by is
   if SendToMain==0 then
SendPmToAll(bot,tmp)
    else
SendToAll(bot,tmp)
    end
end
Title: tt
Post by: BottledHate on 28 September, 2004, 03:31:53
Psycho_Chihuahua:
http://board.univ-angers.fr/thread.php?threadid=2847&boardid=4&styleid=1


-BH
Title: Re: tt
Post by: sidetrack on 15 March, 2006, 15:16:51
Quote from: BottledHate on 28 September, 2004, 03:31:53
Psycho_Chihuahua:
http://board.univ-angers.fr/thread.php?threadid=2847&boardid=4&styleid=1


-BH

That board is dead again.. and I am so needing to figure out how to edit or make changes to a txt/ini file that I have been struggleing with for a long time now.. this thread looked like what I wanted to finally find out. then hit a dead link ARRRRGGGG!
Title: Re: Several questions...
Post by: plop on 15 March, 2006, 20:40:43
push all settings into a table.
opening works a bit like this.
function OpenIni()
tSettings = {}
for line in io.lines("settings.ini") do
local s,e,sSet,sVar = string.find(line, "^([^=]+)=([^=]+)")
if sSet and sVar then
tSettings[sSet] = sVar
end
end
end


changing a value for a settings becomes really easy now.
tSettings[sSet] = "new value"

plop
Title: Re: Several questions...
Post by: Herodes on 15 March, 2006, 21:00:08
Wanna try a more advanced one ? :)
Not really tested .. it just my inspiration typing ..

--- can detect:
-- setting = 'value' | "value" | 0-9* | {...}
-- setting_boolean_like-constant
-- use like: tSettings = OpenIni( 'path/to/filename.ini' )

function OpenIni( file )
t = {}
for line in io.lines(file) do
local s,e,sSet,sVar = string.find(line, "^%s*([^=]+)=([^=]+)%s*$")
if sSet and sVar then
sVar = string.gsub( sVar, "^%s*(.-)%s*$", "%1" )
if string.sub(sVar, 1,1) == "'" or string.sub(sVar, 1,1 ) == "\"" then
t[sSet] = sVar
elseif string.find( sVar, "%d+" )then
local s,e, sNum = string.find( sVar, "(%d+)" )
t[sSet] = tonumber( sNum )
elseif string.sub( sVar, 1,1 ) = '{' and string.sub( sVar, -1 ) == '}' then
t[sSet] = dostring( sVal )
elseif string.lower(sVar) == 'true' or string.lower(sVar) == 'false' then
t[sSet] = true
end
else -- in this way you may do things in an other maybe more convenient way in some cases.
s,e, sSet = string.find( line, "^%s*(%S+)%s*$" )
if sSet then
t[sSet] = true
end
end
end
end
Title: Re: Several questions...
Post by: bastya_elvtars on 15 March, 2006, 22:16:40
The file management wikipage is being worked on...