Difference between pages "Help:To Do List" and "User:Philmasterplus/Sandbox"

From Kolmafia
(Difference between pages)
Jump to navigation Jump to search
imported>Bale
(user_confirm updated by roippi. Thank you roippi!)
 
 
Line 1: Line 1:
{{TOCright}}
+
<onlyinclude>{{{{{format|Function2}}}
 +
|name=User:Philmasterplus/Sandbox
 +
|function1.return_type=buffer
 +
|function1.description=Returns the original HTML source of the page being overridden inside a relay override script.
 +
|function2.return_type=buffer
 +
|function2.description=Visits a web page and returns its HTML source.
 +
|function2.param1=url
 +
|function2.param1.type=string
 +
|function2.param1.description=URL of the page to visit. If a relative URL is provided, it is treated as an in-game page.
 +
|function2.param2=use_POST
 +
|function2.param2.type=boolean
 +
|function2.param2.optional=yes
 +
|function2.param2.default=true
 +
|function2.param2.description=If <code>true</code>, makes an HTTP POST request when visiting the URL. Otherwise, makes a GET request.
 +
|function2.param3=encoded
 +
|function2.param3.type=boolean
 +
|function2.param3.optional=yes
 +
|function2.param3.default=false
 +
|function2.param3.description=If <code>true</code>, KoLmafia assumes that <code>url</code> has already been [[wikipedia:Percent-encoding|URL-encoded]] and will not encode it.
 +
|description=
 +
<p>Returns the HTML from the visited page (not just what is displayed when visiting the page, but all markup) by performing a POST request if {{pspan|use_POST}} is omitted or true, or a GET request if false. Note that for addresses inside of KoL, it is only necessary to supply the page name for {{pspan|page}}, and KoLmafia will populate the rest of the url. However, pages outside of KoL require the full url to be supplied for {{pspan|page}}.</p>
  
== "To Do" List ==
+
<p>The version with no parameters is only meaningful in a relay override script; it retrieves the server page that your script is overriding.  All four versions behave slightly differently in a relay script; they retrieve a version of the page with any KoLmafia decorations added, rather than the raw page from the server.</p>
  
This is a list of stuff that is missing from the wiki or else needs major work. Please help!
+
<p>In a POST request, if &pwd is part of the {{pspan|page}} string, it will automatically be replaced by &pwd=###### where ###### is the password hash for the current session. For a GET request the password hash will not be added so you'll want to use {{f|my_hash}}.</p>
 +
|code1={{CodeSample
 +
  |title=Code Samples
 +
  |description=Visits your private character sheet.
 +
  |code=
 +
<syntaxhighlight lang="java">
 +
visit_url( "charsheet.php" );
 +
</syntaxhighlight>}}
 +
|code2={{CodeSample
 +
  |description=Visits Google.
 +
  |code=
 +
<syntaxhighlight lang="java">
 +
visit_url( "http://www.google.com/");
 +
</syntaxhighlight>}}
 +
|code3={{CodeSample
 +
  |description=Given a player ID, parse a player's profile for his name.
 +
  |code=
 +
<syntaxhighlight lang="java">
 +
string [int] getPlayerName( int playerID ) {
 +
  string playerName;
  
 +
  // use visit_url() to store the player profile's HTML in a string
 +
  string playerProfile = visit_url("showplayer.php?who=" + playerID);
 +
  if ( contains_text(playerProfile, "<td>Sorry, this player could not be found.</td>") ) {
 +
      print("Player " + playerID + "does not exist.","red");
 +
      return "";
 +
  }
 +
  // find player name in the string returned by visit_url()
 +
  matcher match_name = create_matcher("<b>([^<]+)</b> \\(#" + playerID + "\\)<br>", playerProfile);
 +
  if ( match_name.find() ) {
 +
      playerName = match_name.group(1);
 +
  }
 +
  else {
 +
      print("Problem occurred while parsing for player name","red");
 +
      return "";
 +
  }
  
If you need tips for editing the wiki, find that here: [[Help:Editing]].
+
  return playerName;
 
+
}
*CLI Commands are usually only added to the [[CLI Reference]]. Only very complicated commands require their own page.
+
</syntaxhighlight>}}
 
+
|see_also={{SeeAlso|make_url|run_choice}}
*ASH commands need to be listed on their category page as well as on the [[Ash Functions]] list.
+
|cli_equiv=The CLI commands "text", or "http:" will also visit specified urls.
**It is not necessary to always create a code sample, although it is preferred.
+
|more_info=Note that this function returns an empty string if the page does not exist or if the request times out.
**If you don't add a code sample, please remember to add '''needscode=yes|''' to the page.
+
|special=Some people claim that it is better to [[append|append]] the result of this function to a buffer instead of saving it as a string when dealing with an especially large page to avoid time-out. This claim appears to be purely circumstantial and unsupported by the mafia's code.
 
+
|{{{1|}}}
 
+
}}</onlyinclude>
== Missing Stuff ==
+
[[Category:Adventuring]]
10078: ash function format_dtg
 
10081: ash function format_dtg renamed to be
 
string '''format_date_time(inFormat, dtg, outFormat)'''
 
more info: http://kolmafia.us/showthread.php?8451-time_to_string()-with-parameter&p=64058&viewfull=1#post64058
 
 
 
Modify examples on proxy record page because of:
 
10122: Add the boolean "fancy" and "candy" fields to item '''proxy records'''.
 
10147: Initial support for "Crimbo 2011" coinmaster: trade candy for Candy Credits
 
10412: Add $skill '''proxy records''': .dailylimit and .timescast
 
10879: Add a boolean "boss" field to $monster[]
 
 
 
10227: Add the <s>"'''closet empty'''" CLI command, and</s> the '''empty_closet()''' ASH function.
 
 
 
r9181, 9183, 9184 & r9190: '''moods''' per slyz's summary here: http://kolmafia.us/showthread.php?8852-Composable-Moods
 
 
 
r10344 Add '''tavern( string goal )''' ASH function.
 
goal can be "faucet", "baron", or "explore" (to explore all remaining unexplored squares).
 
r10345 Add ASH '''tavern( "fight" )''' to explore cellar until the Baron's mansion is found
 
and then go in to fight him.
 
 
 
r10753-6 '''get_goals()''' returns a string[int] containing all the conditions that KoLmafia will  
 
try to satisfy. Add g'''oal_exists()''' where you can pass in a goal type (choiceadv, autostop,
 
meat, health, mana, item) and KoLmafia will tell you if there are any goals that match.
 
 
 
'''static''' scope is added!
 
r10765: Add a "final" scope type to ASH which allows data/commands to be executed only
 
once per session.
 
r10772: A final declaration can either take a block, surrounded by {}, or a single
 
command or declaration.
 
r10774: ASH: "final" -> "static"
 
 
 
10922: Add '''get_player_id()''' method to ASH
 
 
 
10937: Add '''minstrel_quest()''' boolean function,
 
which returns true when Clancy has a new quest for you.
 
 
 
10971: Added boolean '''hippy_stone_broken()''' function
 
 
 
11008: Add the ASH function int[effect] '''my_effects()''', which returns an array of
 
the character's current effects and their duration. Intrinsic effects have a duration of -1.
 
 
 
11023: Make the CLI "attack" command work again. Make "pvp" equivalent to "steal" instead
 
of "attack". Added "swagger" as equivalent to "flowers".
 
 
 
11055: Added a 2-parameter version of '''to_string()''', where the first parameter can
 
currently be an int or float (other types are possible, but didn't seem
 
useful), and the second is a format string as defined by the Java
 
String.format() method (which in turn is based on C printf() format strings).
 
For example, "%.2f" will output a float with exactly two digits after the
 
(localized) decimal point.
 
 
 
11110: Add ASH function: '''pvp_attacks_left()'''. This is guaranteed accurate only if you
 
have recently looked at the Fight! page. Tracking of PVP fights gained via
 
consumption or familiar action and initialization at login will come later -
 
after api.php is updated to include the figure.
 
 
Add '''beforePVPScript''' setting which contains a script to be executed before a PVP
 
attack. At the moment, this is only called from the Relay Browser - and only if
 
relayRunsBeforePVPScript is true
 
 
11112: Call beforePVPScript, if present, during automated PVP via the "flowers" command
 
 
 
11112: Change ASH '''have_outfit()''' to work with custom outfits, as well as normal outfit
 
Add ASH '''is_wearing_outfit()''' to return TRUE if you are currently wearing the
 
specified custom or normal outfit.
 
 
 
10815: Allow certain ASH constants to be used in custom combat settings.
 
$phylum[] refers to the monster categorization, see the built-in ASH constants documentation for more information.
 
$element[] refers to either the attack or the defense element. As long as one matches, this check will be satisfied. This may limit its usefulness, but we can evaluate it later.
 
$item[] refers to an item that the monster drops. If there are multiple monsters that drop the item, or if you just can't remember which one it is, and your combat strategy happens to depend on it...
 
In order to match, everything that you specify must match. So if you specify an impossible combination, that CCS section will not run.
 
 
[ $element[ spooky ] $item[ hobo nickel ] ]
 
skill entangling noodles
 
skill weapon of the pastalord
 
 
[ bathroom $element[ spooky ] ]
 
attack
 
 
[ $phylum[ beast ] ]
 
skill stomp
 
attack
 
 
 
11197: new ASH functions:
 
boolean '''is_familiar_equipment_locked()'''
 
-returns true if current familiar equipment is locked, otherwise false
 
void '''lock_familiar_equipment(boolean locking)'''
 
-tries to lock/unlock fam equipment accordingly.
 
 
 
11208: Add int '''get_clan_id()''' and string '''get_clan_name()''' functions.
 
 
 
11267: Pass chat events along to '''chatbotscript'''. The sender is an empty string,
 
the channel is "Events", and the message is stripped of its HTML.
 
 
 
== Needs Major Work ==
 
 
 
[[Proxy Records]] is only slightly better than a placeholder.
 
 
 
In r10047, the adventure tab interface was altered. Fix SinginSally's guide on pages...
 
 
http://wiki.kolmafia.us/index.php?title=KoLmafia_Guide:_Attack_Script
 
http://wiki.kolmafia.us/index.php?title=KoLmafia_Guide:_Custom_Combat_Script
 
http://wiki.kolmafia.us/index.php?title=KoLmafia_Guide:_Goal-Oriented_Adventuring
 
 
 
Information on moods calling other moods: http://kolmafia.us/showthread.php?8852-Composable-Moods&p=66468&viewfull=1#post66468
 
 
 
r10025: Added '''choice''' CLI command, to resolve manual or unsupported choiceadventures
 
Added "choice" CLI command, to resolve manual or unsupported choice
 
adventures without having to visit the relay browser - which might be
 
inconvenient if you're already in the CLI, and don't need to see the full
 
adventure text to decide which option you want. With no parameter, "choice"
 
just lists the options. With a numeric parameter, it picks that option.
 
With any other parameter, it picks the first option containing that text (in
 
either the actual button text, or mafia's spoiler text).
 
 
 
== Needs Code Samples ==
 
 
 
There is a list of all pages that require code samples: [[:Category:Needs_Code_Sample|Category:Needs Code Sample]]
 
 
 
Information on how to create a code sample: [[Template:CodeSample]]
 

Revision as of 10:34, 20 December 2020

Function Syntax

buffer User:Philmasterplus/Sandbox()

Returns the original HTML source of the page being overridden inside a relay override script.

buffer User:Philmasterplus/Sandboxstring url, boolean? use_POST = true, boolean? encoded = false )

Visits a web page and returns its HTML source.
  • url: URL of the page to visit. If a relative URL is provided, it is treated as an in-game page.
  • use_POST: If true, makes an HTTP POST request when visiting the URL. Otherwise, makes a GET request.
  • encoded: If true, KoLmafia assumes that url has already been URL-encoded and will not encode it.

Returns the HTML from the visited page (not just what is displayed when visiting the page, but all markup) by performing a POST request if use_POST is omitted or true, or a GET request if false. Note that for addresses inside of KoL, it is only necessary to supply the page name for page, and KoLmafia will populate the rest of the url. However, pages outside of KoL require the full url to be supplied for page.

The version with no parameters is only meaningful in a relay override script; it retrieves the server page that your script is overriding. All four versions behave slightly differently in a relay script; they retrieve a version of the page with any KoLmafia decorations added, rather than the raw page from the server.

In a POST request, if &pwd is part of the page string, it will automatically be replaced by &pwd=###### where ###### is the password hash for the current session. For a GET request the password hash will not be added so you'll want to use my_hash().

Code Samples

Visits your private character sheet.

visit_url( "charsheet.php" );

Visits Google.

visit_url( "http://www.google.com/");

Given a player ID, parse a player's profile for his name.

string [int] getPlayerName( int playerID ) {
   string playerName;

   // use visit_url() to store the player profile's HTML in a string
   string playerProfile = visit_url("showplayer.php?who=" + playerID);
   if ( contains_text(playerProfile, "<td>Sorry, this player could not be found.</td>") ) {
      print("Player " + playerID + "does not exist.","red");
      return "";
   }
   // find player name in the string returned by visit_url()
   matcher match_name = create_matcher("<b>([^<]+)</b> \\(#" + playerID + "\\)<br>", playerProfile);
   if ( match_name.find() ) {
      playerName = match_name.group(1);
   }
   else {
      print("Problem occurred while parsing for player name","red");
      return "";
   }

   return playerName;
}

CLI Equivalent

The CLI commands "text", or "http:" will also visit specified urls.

See Also

make_url() | run_choice()

More Information

Note that this function returns an empty string if the page does not exist or if the request times out.

Special

Some people claim that it is better to append the result of this function to a buffer instead of saving it as a string when dealing with an especially large page to avoid time-out. This claim appears to be purely circumstantial and unsupported by the mafia's code.