How do you know the php?

DaMaster0

Member
I've been working with KOLMafia for a while now, and I was wondering, how do you find the php of a place??:confused: For example, I want to make a function that tells you if you have a display case or not. What I was planning to do was see if the Collection Collection had the text "manage your collection" but I don't know to php for the Collection Collection. How do I find that out?
 

Bale

Minion
I use the mini-browser. (General -> mini-browser) It shows me the visit_url to use whenever I do something there.
 

DaMaster0

Member
Oh cool! Thank you!

EDIT: Does this also work for GIF pictures? If it does, I can't figure out how to do it.
 
Last edited:

Catch-22

Active member
I use Firefox for that. The reason you probably couldn't see the correct URL is because KoL uses frames. If you're using Firefox, right click in the frame you want to see and click "This Frame > Show Only This Frame". You could also do "This Frame > View Frame Info", which gives you the URL and the referrer and you can also look through any media on that page (gif, etc.).
 

DaMaster0

Member
Ok, now I have a new problem. I wanted to delete kmail, and I looked through zarqon's registry script, and here's the function I came out with:
Code:
void delete_mail( int num )
{
	print("Deleting mail...");
	string del = "messages.php?the_action=delete&box=Inbox&pwd";
	del = del+"&sel"+num+"=checked";
	del = visit_url(del);
	if (contains_text(del,"1 message deleted.") || contains_text(del,"messages deleted."))
		print("Message deleted.");
	else abort("There was a problem deleting the mail.  Check your inbox.");
}
I sent myself some tests, and put in my id number for num. It said it deleted my mail, but the mail is still in my inbox! I tried looking at the php for deleting kmails, but when I press delete I get this message:
mv591u.jpg
 

Veracity

Developer
Staff member
In the Relay Browser, turn on debugging, go to where you want, and look at the debug log.

If you actually executed the request, you can see the URL of the request directly.
If you simply navigated to the place where you COULD execute the request by submitting a form (after entering text fields, clicking checkboxes, and pressing a button), you can figure it out from the HTML code of that page.

At least, that's what _I_ do to figure out URLs.
 

Catch-22

Active member
I sent myself some tests, and put in my id number for num. It said it deleted my mail, but the mail is still in my inbox! I tried looking at the php for deleting kmails, but when I press delete I get this message:
mv591u.jpg

Ah, this is because you are using the mini-browser, not the relay browser.

The string looks right, the only thing I can see different in mine is your string should be:
Code:
del = del+"&sel"+num+"=on";

Instead of:
Code:
del = del+"&sel"+num+"=checked";

but both should work.

Here's how the URL looks for me:

messages.php?the_action=delete&pwd=44e1f66990d2a29bb39724286575376c&box=Inbox&sel92216325=on

So I'm not sure why it wouldn't be working for you.

Edit:

Ok I've figured it out :) There's nothing wrong with your script, it's the num you're giving the function. The reason the script is saying it's deleted is because it's seeing the "messages deleted." in "0 messages deleted." because you are using the wrong num.

So I guess you should fix the num that you're putting in to the function, and maybe too add some checking for "0 messages deleted." ;)

Hope that helps!
 
Last edited:

Catch-22

Active member
How do I turn on the debug log? I don't know what num to put in.

It probably won't help you much, the num is unique to that message. As soon as you delete it, you won't be able to use that num again to refer to the message. You need to determine the nums by what's in your inbox, it's not a static number.
 

mredge73

Member
you can take a look at my Support Script -- Functions, toward the bottom I have a function called DumpJunkMail(). This one may be helpful in showing you how to parse and delete mail using Zarqon's script structure.

You will also see my interpretation of Zarqon's parse mail and delete mail. I took these from registry and built them into callable functions.
 

DaMaster0

Member
Help -> Start Debug Log

When I do that, nothing happens...

It probably won't help you much, the num is unique to that message. As soon as you delete it, you won't be able to use that num again to refer to the message. You need to determine the nums by what's in your inbox, it's not a static number.

I know that, but I'm looking for some variable in the php, such as when I delete mail, the id # appears in the url or something.

you can take a look at my Support Script -- Functions, toward the bottom I have a function called DumpJunkMail(). This one may be helpful in showing you how to parse and delete mail using Zarqon's script structure.

You will also see my interpretation of Zarqon's parse mail and delete mail. I took these from registry and built them into callable functions.

Oh you did? I need to check that script out!
EDIT: Ok, I checked out your script, and as far as I know, the function doesn't work. I fed it a boolean[int] array with the id # set as true, but this is what I got:

Deleting mail...
There was a problem deleting your mail. Check your inbox.

Was I doing something wrong?
 
Last edited:

mredge73

Member
here is a test script for you, Send yourself a Kmail that has "Delete This" in the body of the message and then run the test script. The test script will delete the message with that in the body. You will need to have my two support scripts in your script folder somewhere (I am assuming you already have them).

Code:
import <MrEdge73's Support Script -- Functions (Beta).ash>

//main
message[int] mail = parse_mail();
boolean[int] processed;
print ("checked mail");

for j from 0 upto (count(mail)-1)
{
    //print (mail[j].sender); 
    //print (mail[j].date); 
    print (mail[j].id,"red"); 
    print (mail[j].text,"green");
    //print (mail[j].meat); 
    foreach i in mail[j].things
        print (mail[j].things[i]+ " "+i,"olive"); 

    if (contains_text(mail[j].text, "Delete This"))
            processed[mail[j].id] = true;
    
   }
  //    DumpJunkMail();
DeleteMail(processed);
 
Last edited:

Heffed

Member
When I do that, nothing happens...

I'm willing to bet it started creating a debug log. Look in your KoLmafia folder for this log.

An easy way to tell if it is logging is to look under the help menu again. The choice will now be to stop debug logging.
 

Catch-22

Active member
I know that, but I'm looking for some variable in the php, such as when I delete mail, the id # appears in the url or something.

The num only appears in the URL if you are performing an action on it, such as a delete or save. To determine the number before you action it you will have to parse response text from the inbox page.
 

DaMaster0

Member
here is a test script for you, Send yourself a Kmail that has "Delete This" in the body of the message and then run the test script. The test script will delete the message with that in the body. You will need to have my two support scripts in your script folder somewhere (I am assuming you already have them).

Code:
import <MrEdge73's Support Script -- Functions (Beta).ash>

//main
message[int] mail = parse_mail();
boolean[int] processed;
print ("checked mail");

for j from 0 upto (count(mail)-1)
{
    //print (mail[j].sender); 
    //print (mail[j].date); 
    print (mail[j].id,"red"); 
    print (mail[j].text,"green");
    //print (mail[j].meat); 
    foreach i in mail[j].things
        print (mail[j].things[i]+ " "+i,"olive"); 

    if (contains_text(mail[j].text, "Delete This"))
            processed[mail[j].id] = true;
    
   }
  //    DumpJunkMail();
DeleteMail(processed);

Ok, your version works, but how do I call that function? I made an array with the id number = true, but that didn't work. What are you doing different?
 

mredge73

Member
My boolean DeleteMail(boolean[int] Erase) function based off of Zarqon's registry.ash delete logic accepts a map of ID numbers and erases the kmails that correspond to those ID numbers.

When running the test script with the DeleteMail(processed) commented out I get this:
Code:
> call scripts\Scripts\TEST.ash

Checking mail...
3 messages queued.
checked mail
92277104
Delete This One
92277099
Test2
92277089
Test1
Basically the Test script is just parsing your mailbox using parse_mail() and outputting what it has stored in its map.

Now the code:
Code:
if (contains_text(mail[j].text, "Delete This"))
            processed[mail[j].id] = true;
What this does is use the test case of finding a kmail with Delete This in the body to set it to delete. To do that it adds the message to the delete map by passing the ID number to it. In this case it would be:
Code:
processed[92277104]=true;
Now you pass that map off to the DeleteMail(boolean[int]) function and it deletes all messages added to the map. The purpose of having it pass a map is so that the function can delete more than one message at a time.







If you want to a function that only deletes one message and just accepts the Kmail ID use this one:

Code:
boolean DeleteMail(int ID)
{
    print("Deleting mail...");
    string del = visit_url("messages.php?the_action=delete&box=Inbox&pwd&sel"+ID+"=checked");
    //output message and error checking
    if (contains_text(del,"1 message deleted."))
        {
            print("1 message deleted.");
            return True;
        }
    else 
        {
            abort("There was a problem deleting your mail.  Check your inbox.");
            return False;
        }
    return False;
}
To call this using the above example you would just do this:
DeleteMail(92277104);
 
Last edited:

DaMaster0

Member
yeahh... about that.... This code:
Code:
boolean DeleteMail(int ID)
{
    print("Deleting mail...");
    string del = visit_url("messages.php?the_action=delete&box=Inbox&pwd&sel"+ID+"=checked");
    //output message and error checking
    if (contains_text(del,"1 message deleted."))
        {
            print("1 message deleted.");
            return True;
        }
    else 
        {
            abort("There was a problem deleting your mail.  Check your inbox.");
            return False;
        }
    return False;
}

void main()
{
	deletemail(1999853);
}

printed this in the cli:

> test

Deleting mail...
There was a problem deleting your mail. Check your inbox.

And it didn't delete the mail.
 

mredge73

Member
I agree, it is wrong.
The message id's are usually 8 digits long and the one you entered is only 7 digits and it looks like your player ID number.
The number that you need is the id number of the message to be deleted, rerun my test script from the earlier post and the number in red is the one you need.


FYI
Yes...it is your player ID number and not a message number at all.
You are The Bot2 (#1999853) Level 7
 
Last edited:
Top