class InfiniteCraft

Initialize an Infinite Craft session.

InfiniteCraft(
    api_url: str                      = "https://neal.fun",
    api_rate_limit: int               = 400,
    manual_control: bool              = False,
    discoveries_storage: str          = "discoveries.json",
    encoding: str                     = "utf-8",
    do_reset: bool                    = False,
    make_file: bool                   = True,
    headers: MutableMapping[str, str] = {},
    element_cls: type[Element]        = Element,
    logger: Any                       = Logger(),
    debug: bool                       = False
)

Attributes

discoveries (list[Element]): List of Element objects that have been discovered.

closed (bool | None): Whether the Infinite Craft session is closed or not. None if session has not been started.

Arguments

api_url (str, optional): The API URL to contact.

Defaults to "https://neal.fun/api/infinite-craft"

api_rate_limit (int, optional): The requests per minute the API can handle before ratelimiting. 0 if you want no ratelimit. Must be greater than or equal to 0.

Defaults to 400 requests per minute

manual_control (bool, optional): Manually control InfiniteCraft.start() and InfiniteCraft.stop(). Useful when using async with multiple times.

Defaults to False

discoveries_storage (str, optional): Path to discoveries storage JSON.

Defaults to "discoveries.json"

encoding (str, optional): Encoding to use while reading or saving json files.

Defaults to "utf-8"

do_reset (bool, optional): Whether to reset the discoveries storage JSON and emoji cache JSON.

Defaults to False

headers (dict, optional): Headers to send to the API.

Defaults to {}

element_cls (Element, optional): Class to be used for creating elements. NOTE: Must be a subclass of Element.

Defaults to Element

logger (class, optional): An initialized logger class or module with methods info, warn, error, fatal, and debug to use for logging.

Defaults to a custom logger Logger

debug (bool, optional): Whether to send debug logs. This sets the current logger to Logger(log_level=5). Only works when bool(logger) is False or when the custom logger is used.

Defaults to False

async def ping() -> float

Ping the API with a simple pair request and return the latency.

This function only works when the session has been started.

Returns

float: The latency in seconds.

async def start()

Start the InfiniteCraft session.

Raises

RuntimeError: Raises when session is closed or has already started.

async def close()

Start the InfiniteCraft session.

Raises

RuntimeError: Raises when session has not been started or is already closed.

async def stop()

Alias for self.close()

async def pair() -> Element

Pair two elements and return the resulting element.

async def pair(
    first: Element,
    second: Element,
    *,
    store: bool = True
) -> Element

If the elements could not be paired, it would result in an Element with all attributes set to None. We can check if all attributes are None by doing bool(). If it returns False, then all attributes are None. Useful in if statements.

Arguments

first (Element): The first element.

Required

second (Element): The second element.

Required

store (bool, optional): Whether to store the result Element to self.discoveries.

Defaults to True

Raises

TypeError: If first or second is not an instance of Element.

Returns

Element: The resulting element as an Element object or an Element with all attributes as None if they could not be paired.

async def merge()

Alias for InfiniteCraft.pair()

async def combine()

Alias for InfiniteCraft.pair()

def get_discoveries() -> Element, None

Get a list containing all discovered elements fetched from the discoveries.json file.

def get_discoveries(
    *,
    set_value: bool = False,
    check: Callable[[Element], bool] | None = None
) -> 

Arguments

set_value (bool, optional): Whether to set the value for the self.discoveries attribute after getting it.

Defaults to None

check (Callable[[Element], bool], optional): A callable functions that accepts an argument for element and returns a bool to whether add the element or not.

Defaults to None

Returns

list[Element]: The list containing every Element discovered.

def get_discovery() -> Element, None

Get a discovered Element from self.discoveries.

Arguments

name (str): Name of element to get.

Required

from_file (bool, optional): Whether to check the discoveries JSON file for the element.

Defaults to False

Returns

Element | None: The discovered Element or None if it wasn't discovered.

@staticmethod

def reset()

Reset the discoveries.json file to its initial state.

This is a @staticmethod, hence it can be used using InfiniteCraft.reset() without initialising the class.

def reset(
    *,
    discoveries_storage: str = "discoveries.json",
    encoding: str = "utf-8",
    indent: int = 2,
    make_file: bool = False
)

โ‰๏ธThis is it?

Last updated