Menu Item


There are certain advantages to tipmenus existing inside of an app or bot. One such thing used to implement tipmenus is the menuitem class, which represents individual items in the menu.


Instances of this class are used to fill a Menu Section with items.

This class has an active() function callback, which defaults to a function which always returns true. This establishes a condition in which the item is active. An inactive item does not appear in the tipmenu to users, but still exists in code; useful for permanent references and limiting garbage collector activity.

This class can optionally hold a handler function, which is to be called when the item is tipped for, as well as parameters for the handler function.



The name of the menu item; what it is displayed as.


The cost of the menu item; how many tokens it requires.


If the menu item has an associated handler, call it. This should be called somewhere in cb.onTip() after a match has been made, on the match.


New menu items are created through new menuitem(). At the absolute simplest, both a name and cost must be declared, like new menuitem("example", 10), which creates an item called example which costs 10 tokens. Optionally, an active callback function can be declared, which establishes the conditions in which this item is active on the menu; and a handler function can be declared and passed, with optional paramters, like so new menuitem("example", 10, () => { return true }, handler, handlerParam1, handlerParam2). The active callback, handler and parameters are stored with the item.