Condition help

Hi again ! (Ruri don’t ban me please for stupid questions please! lol)
Things can start to become really confusing fast, so basically I’m using Puppeteer to farm cookies for an http request, the cookies are valid for a given time (which I don’t know), to avoid cycling the whole script from the beginning, I’m trying to use conditions, it’s easy to check if we’re not logged out anymore by searching a specific keyword, so I tried with lolicode, at the very end :

IF STRINGKEY @data.SOURCE Contains "Your cart (1)"
JUMP #ADD_ITEM
ELSE
JUMP #LOGIN
END

I tried running it, but it seems like even though I’m not kicked from the session, it will still run the script from the Open Browser block.

EDIT: maybe it would be a better idea to use HTTP status code right after the #ADD_ITEM block instead of string search ? When session expired it will redirect, thus, throwing 302 HTTP.

EDIT 2: situation is giving me headaches, the condition is set right before the keycheck, problem is, there is another block if the keycheck returns success, so not sure where to place the loop

IF INTKEY @data.RESPONSECODE EqualTo 302
JUMP #LOGIN
END

If I put it after the #ADD_ITEM block, it will continue executing like normal, and if I put it after the keycheck, if it fails, it will stop executing… I have to put another condition somewhere, but where ?

I think the problem here is that you are checking using data.SOURCE while you should get the DOM instead with a Get Dom block and make the keycheck on the output variable of that block.

I am getting the dom before the keycheck.

Anyway, I managed to make the config works fully HTTP requests, but I still have a loop problem, here is the scheme :
2022-01-13 12_51_28-Window

What I’m trying to achieve:
Run script
If HTTP error code is 302 JUMP to BLOCK1
If not, loop from BLOCK5

Problem I’m facing: last Lolicode block contains the jump to BLOCK5 if everything is fine, but won’t get executed if Keycheck failed, which makes sense, what am I supposed to do ?

Contents of Lolicode blocks:
1st: #BLOCK1

2nd:
#BLOCK5

3rd:
IF INTKEY @data.RESPONSECODE EqualTo 302
JUMP #BLOCK1
END

Last:
JUMP #BLOCK5

EDIT: @Ruri the workaround I’ve found would be to change the config settings and putting Fail in the “continue” statuses, and then putting this :

IF STRINGKEY @data.STATUS EqualTo "FAIL"
JUMP #BLOCK5
END

EDIT2: Sadly, stuck in endless loop.

You need an exit condition. You can easily terminate the script by writing return; where you want.

Mind throwing an example in my situation please?

You are always jumping back to block 5 at the end, so of course there is an endless loop, you need to break out of the loop somewhere. I don’t think I can help you more unless you literally give me a sample LoliCode that reconstructs your blocks to reproduce the error

Can I send you private message with the sample ?

I guess… if you really cannot just write some dummy code that produces the same issue

Ok, I tried to be most accurate possible with comments:

#BLOCK1

// Requests here

IF INTKEY @data.RESPONSECODE EqualTo 500
JUMP #BLOCK1
END

// Other requests

#BLOCK5

// Main request (BLOCK 5)

BLOCK:Keycheck
  banIfNoMatch = False
  KEYCHAIN FAIL OR
    STRINGKEY @data.SOURCE Contains "fail"
  KEYCHAIN SUCCESS OR
    STRINGKEY @data.SOURCE Contains $"<input.CODE> ok"
ENDBLOCK

// Session expires on 302, go back to the start
IF INTKEY @data.RESPONSECODE EqualTo 302
JUMP #BLOCK1
END

// Final request

// Everything went well, go back to main request (BLOCK 5)
JUMP #BLOCK5

What I’m trying to achieve: farm cookies and tokens for main request (block5), loop from there until cookies and tokens are not valid anymore (which is triggered by a status code 302), thus, whatever the keycheck is.

Okay please ping me tomorrow and I will go through it and find a solution, cause today I’m a bit busy

@Ruri /crossfingers lol :heartpulse:

Hmmm @Ruri , I was thinking, is there a way to prevent OB2 from clearing cookies at the end of the script? That way the workaround would be to check on first request if we’re logged in already or not, if logged in can jump directly to BLOCK5, less effective than the first idea though (because we’re adding a request)

There is a guide for global cookies, maybe give it a read

Can’t use global variables, as I don’t want other bots to use same variables, sadly.
Each bot should have its own session.

Yeah you need to wait until I implement this [REQUEST] BOTNUM Variable (Parallelizer Type = ThreadBased) · Issue #332 · openbullet/OpenBullet2 · GitHub so that you can set globals per bot like in OB1

Bump, if someone else has any idea, this thing is giving me headaches for days lol

Okay I went through everything, I think the problem is that you aren’t clearing the cookies before jumping to the beginning so you’re already in an expired session.

Inside the IF, before the JUMP, put a Clear Cookies block and it should help.

No, the session is not expired, it takes some time before it expires, sadly looks like its random, sometimes 30 minutes sometimes 50…
And if I clear cookies, there is no point to jump to BLOCK5 as the request will then be invalid without any cookies.

Also, I did a big mistake while writting the dummy code, at the end it should be JUMP #BLOCK5
So maybe you misunderstood because of that.

Basically I’m farming tokens and cookies, and should execute BLOCK5 in loop until session expires.

Oh okay, yeah I was misled by the jump to block 1 at the end.
Anyways man I have no clue, sorry :confused:

Maybe someone else can pitch in and help?

For some reason in the debugger it works well :

>> Keycheck (CheckCondition) <<

Matched key 


<!doctype html>
<!--[if lt IE 7]> <html class=" [...] Contains <span id="error" class="e [...]

Matched key FAIL EqualTo FAIL

>> BLOCK5 (HttpRequestStandard) <<

But when running bot, it will stuck at BLOCK5 without returning any status