ForgePages is a extension built for ForgeScript, enabling you to easily create, manage, and navigate through paginated data directly in your bot.
npm install github:xloxn69/ForgePagesconst { ForgeClient } = require("@tryforge/forgescript");
const ForgePages = require("forgepages");
const client = new ForgeClient({
extensions: [
new ForgePages()
]
});Creates or overwrites a pagination store with data split by separator.
Parameters:
id(String) - Store identifierseparator(String) - Separator to split data byrawData(String) - Raw data string to split
Returns: Boolean (true if successful)
Example:
$pagesInit[users;,;Alice,Bob,Charlie,David,Eve]
$c[Returns: true - Creates store "users" with 5 entries]
Appends new entries to an existing store.
Parameters:
id(String) - Store identifiervalues(String) - Values to append (will be split by store's separator)
Returns: Boolean (true if successful)
Example:
$!pagesInit[fruits;,;Apple,Banana]
$!addPageData[fruits;Cherry,Date]
$pagesList[fruits;1;10]
$c[Returns: "Apple,Banana,Cherry,Date" - Added 2 new entries to store]
Removes one entry by 1-based index.
Parameters:
id(String) - Store identifierindex(Number) - 1-based index to remove
Returns: Boolean (true if item was removed, false if index out of bounds)
Example:
$!pagesInit[colors;,;Red,Green,Blue,Yellow]
$!removePageEntry[colors;2]
$pagesList[colors;1;10]
$c[Returns: "Red,Blue,Yellow" - Removed "Green" (index 2)]
Returns a specific page of data.
Parameters:
id(String) - Store identifierpage(Number) - Page number to get (1-based)itemsPerPage(Number) - Items per page
Returns: String (joined data using store's separator)
Example:
$!pagesInit[items;,;Item1,Item2,Item3,Item4,Item5,Item6]
$pagesList[items;2;3]
$c[Returns: "Item4,Item5,Item6" - Page 2 with 3 items per page]
Returns an arbitrary slice of data from start index.
Parameters:
id(String) - Store identifierstartIndex(Number) - 1-based start indexcount(Number) - Number of items to get
Returns: String (joined data using store's separator)
Example:
$!pagesInit[letters;,;A,B,C,D,E,F,G,H]
$pagesSlice[letters;3;4]
$c[Returns: "C,D,E,F" - 4 items starting from position 3]
Returns the total number of pages for given items per page.
Parameters:
id(String) - Store identifieritemsPerPage(Number, optional) - Items per page (default: 10)
Returns: Number (total pages)
Example:
$!pagesInit[data;,;1,2,3,4,5,6,7,8,9,10,11,12,13]
$pageCount[data;5]
$c[Returns: 3 - 13 items divided by 5 per page = 3 pages]
Finds the page number where a search query first appears.
Parameters:
id(String) - Store identifierquery(String) - Search query (case-insensitive)itemsPerPage(Number, optional) - Items per page (default: 10)
Returns: Number (page number, or 0 if not found)
Example:
$!pagesInit[animals;,;Cat,Dog,Elephant,Fish,Giraffe,Horse]
$searchPages[animals;Elephant;3]
$c[Returns: 1 - "Elephant" found on page 1 with 3 items per page]
Maps through each entry in a paging store, runs code for each entry, and returns all results joined by separator.
Parameters:
id(String) - The store identifiervariable(String) - The name of the variable to assign each entry to (accessible as$env[variable])code(String) - ForgeScript code to execute for each entry (use $return to output values)
Returns: String (all returned values joined by store's separator)
Example:
$!pagesInit[numbers;,;1,2,3,4,5]
$advancedSearchPages[numbers;num;$return[$math[$env[num] * 2]]]
$c[Returns: "2,4,6,8,10" - Each number doubled using $return]
Sorts the store data alphabetically.
Parameters:
id(String) - Store identifierdirection(String, optional) - Sort direction: "asc" (default) or "desc"
Returns: Boolean (true if successful)
Example:
$!pagesInit[names;,;Zoe,Alice,Bob,Charlie]
$!sortPages[names;asc]
$pagesList[names;1;10]
$c[Returns: "Alice,Bob,Charlie,Zoe" - Sorted alphabetically ascending]
Advanced sort for page store entries using custom comparison logic.
Parameters:
id(String) - The store identifiervar1(String) - The $env variable 1 to hold first comparison valuevar2(String) - The $env variable 2 to hold second comparison valuecode(String) - Code to execute for comparison (should return number: negative if first < second, 0 if equal, positive if first > second)
Returns: Boolean (true if successful)
Example:
$!pagesInit[words;,;Cat,Elephant,Dog,Fish,Snake]
$!advancedSortPages[words;w1;w2;$sub[$charCount[$env[w1]];$charCount[$env[w2]]]]
$pagesList[words;1;10]
$c[Returns: "Cat,Dog,Fish,Snake,Elephant" - Sorted by string length (shortest first)]
If you need any assistance, don't hesitate to reach out by opening a support form in the official BotForge Discord server! :D
MIT