Update of "Menu Item"

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.


Artifact ID: 87d33baf55f3258ccc477617e41596bfcd91bdc1
Page Name:Menu Item
Date: 2017-11-09 15:48:18
Original User: Entomy
Parent: 8c96ce0469080d0413f7d8eaab8ad40252eab10b


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 suggestion patterns, for which a message is checked against each, and if a match is found, the item is suggested to the user who sent that message.

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.


Check the message parameter against any suggestion RegExp's set for this menu item. If a match is found, suggest this item to the user who sent the message.


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; suggestion RegExp's can be declared, which are patterns which if found in a message, should have this item suggested to the user; and a handler function can be declared and passed, with optional paramters, like so new menuitem("example", 10, () => { return true }, [/foo/i, /bar/i], handler, param1, param2). The active callback, suggestions, handler and parameters are stored with the item.