nsdotjs
    Preparing search index...

    Class NSScript

    Represents a script for interacting with NationStates, providing methods for authentication, nation management, storage, and web requests.

    Manages NationStates-specific operations like logging in, moving regions, applying to the World Assembly, and making authenticated HTML requests.

    Index

    Constructors

    • Initializes a new NSScript instance with script metadata and current user information.

      Parameters

      • name: string

        The name of the script

      • version: string

        The version of the script

      • author: string

        The author of the script

      • user: string

        The current user of the script

      • userInputHandler: () => Promise<void> = waitForSpace

      Returns NSScript

    Properties

    currentUser: string
    isHtmlRequestInProgress: boolean = false
    statusBubble: StatusBubble
    userInputHandler: () => Promise<void> = waitForSpace

    Methods

    • Attempts to abort an embassy that is currently being opened.

      Parameters

      • regionName: string

        The name of the region to abort the embassy opening with.

      Returns Promise<boolean>

      A Promise that resolves to true if the embassy opening is aborted, false otherwise.

    • Adds a tag to the current region.

      Parameters

      Returns Promise<boolean>

      A Promise that resolves to true if the tag is added, false otherwise.

    • Attempts to apply to or reapply to the World Assembly.

      Parameters

      • Optionalreapply: boolean

        Whether to reapply to the World Assembly if you've already recently applied

      Returns Promise<boolean>

      A Promise that resolves to true if the application is successful, false otherwise.

    • Attempts to ban and eject a nation from the current region.

      Parameters

      • nationName: string

        The name of the nation to ban and eject.

      Returns Promise<boolean>

      A Promise that resolves to true if the ban and eject is successful, false otherwise.

    • Attempts to close an embassy with the specified region.

      Parameters

      • regionName: string

        The name of the region to close the embassy with.

      Returns Promise<boolean>

      A Promise that resolves to true if the embassy is closed, false otherwise.

    • Attempts to cancel an embassy closure.

      Parameters

      • regionName: string

        The name of the region to cancel the embassy closure with.

      Returns Promise<boolean>

      A Promise that resolves to true if the embassy closure is canceled, false otherwise.

    • Attempts to change the World Factbook Entry for the current region.

      Parameters

      • wfe: string

        The new World Factbook Entry.

      Returns Promise<boolean>

      A Promise that resolves to true if the change is successful, false otherwise.

    • Attempts to create a new region with the specified parameters.

      Parameters

      • regionName: string

        The name of the region to create.

      • wfe: string

        The World Factbook Entry for the region.

      • password: string = ""

        Optional password for the region.

      • frontier: boolean = false

        Whether the region is a frontier region. Defaults to false.

      • executiveDelegate: boolean = false

        Whether the region has an executive delegate. Defaults to false.

      Returns Promise<boolean>

      A Promise that resolves to true if the creation is successful, false otherwise.

    • Attempts to eject a nation from the current region.

      Parameters

      • nationName: string

        The name of the nation to ban and eject.

      Returns Promise<boolean>

      A Promise that resolves to true if the ban and eject is successful, false otherwise.

    • Attempts to endorse a nation in the World Assembly.

      Parameters

      • nationName: string

        The name of the nation to endorse.

      Returns Promise<boolean>

      A Promise that resolves to true if the endorsement is successful, false otherwise.

    • Retrieves a value from the IndexedDB key-value store by its key.

      Parameters

      • key: string

        The key of the value to retrieve

      Returns Promise<unknown>

      A Promise that resolves to the stored value, or undefined if the key is not found

    • Fetches and processes an HTML page from the NationStates site. Handles security checks and captcha detection.

      Parameters

      • pagePath: string

        The path to the page on NationStates.

      • Optionalpayload: Record<string, string | number | boolean>

        Optional payload to send with the request.

      Returns Promise<string>

      A Promise that resolves to the HTML content of the page as a string.

      Error if the request fails, security check fails, or captcha is detected.

    • Attempts to join the World Assembly as a member.

      Parameters

      • nationName: string

        The name of the nation to join as.

      • appId: string

        The application ID for the nation.

      Returns Promise<boolean>

      A Promise that resolves to true if the join is successful, false otherwise.

    • Attempts to log in to a NationStates nation.

      Parameters

      • nationName: string

        The name of the nation to log in to.

      • password: string

        The password for the nation.

      Returns Promise<boolean>

      A Promise that resolves to true if login is successful, false otherwise.

    • Makes a request to a page on the NationStates HTML site.

      Parameters

      • pagePath: string

        The path to the page on NationStates (e.g., "index.html", "page=create_nation"). This path is relative to "https://www.nationstates.net/".

      • Optionalpayload: Record<string, string | number | boolean>

        An object containing key-value pairs to be sent as the request payload.

      • followRedirects: boolean = true

      Returns Promise<Response>

      A Promise that resolves to the Fetch API's Response object.

    • Attempts to move the current nation to a different region.

      Parameters

      • regionName: string

        The name of the region to move to.

      • Optionalpassword: string

        Optional password for the region.

      Returns Promise<boolean>

      A Promise that resolves to true if the move is successful, false otherwise.

    • Re-authenticates the current session by fetching the region page for RWBY, getting the CHK and localid values from the response.

      Returns Promise<void>

    • Removes a tag from the current region.

      Parameters

      Returns Promise<boolean>

      A Promise that resolves to true if the tag is removed, false otherwise.

    • Requests an embassy from the current region to the specified region.

      Parameters

      • regionName: string

        The name of the region to request an embassy from.

      Returns Promise<boolean>

      A Promise that resolves to true if the request is successful, false otherwise.

    • Attempts to resign from the World Assembly.

      Returns Promise<boolean>

      A Promise that resolves to true if the resignation is successful, false otherwise.

    • Attempts to create a new nation in the specified region.

      Parameters

      • nationName: string

        The name of the nation to create.

      • password: string

        Optional password for the nation.

      Returns Promise<boolean>

      A Promise that resolves to true if the creation is successful, false otherwise.

    • Stores a key-value pair in the IndexedDB key-value store.

      Parameters

      • key: string

        The key under which the value will be stored

      • value: unknown

        The value to be stored, which can be of any type

      Returns Promise<void>

      A Promise that resolves when the value is successfully stored

    • Attempts to unendorse a nation in the World Assembly.

      Parameters

      • nationName: string

        The name of the nation to unendorse.

      Returns Promise<boolean>

      A Promise that resolves to true if the unendorsement is successful, false otherwise.

    • Attempts to vote in the World Assembly.

      Parameters

      • council: "ga" | "sc"

        The council to vote in ("ga" for General Assembly, "sc" for Security Council).

      • vote: "for" | "against"

        The vote type ("for" or "against").

      Returns Promise<boolean>

      A Promise that resolves to true if the vote is successful, false otherwise.