-
Notifications
You must be signed in to change notification settings - Fork 1
Documentation
Never hesitate to take a look at the sources in case of confusion ! 😉
Class representing a page of the help system. A page is displayed to the user, and the user can navigate through pages using reactions or messages.
Name | Type | Description |
---|---|---|
msg |
str |
Message to send to the user when displaying the page. |
links |
list of Link |
List of links associated to this page. These are the possible path to navigate to another page. |
msg_link |
MsgLink |
MsgLink if there is one. It's not part of the link list because there can't be several MsgLink associated to a given page. |
parent |
Link |
Link to the parent page. |
root |
Link |
Link to the root page. |
sep |
str |
String used to separate the message and the links description. Used only for formatting messages to send to user. |
links_sep |
str |
String used to separate each link description. Used only for formatting messages to send to user. |
type |
PageType |
Type of the page. Can be PageType.MESSAGE or PageType.EMBED . |
embed_kwargs |
dict |
Others keywords arguments, used to initialize the Embed for display. Only used if the type of the page is PageType.EMBED . |
Constructor. All links are set to None
or empty list.
def __init__(self, msg='', sep='\n\n', links_sep='\n')
Argument | Type | Default | Description |
---|---|---|---|
msg |
str |
'' |
Message to send to user when displaying this page. |
sep |
str |
'\n\n' |
String used to separate the message and the links description while formatting the message to send. |
links_sep |
str |
'\n' |
String used to separate each links description while formatting the message to send. |
embed |
bool |
'\n' |
If set to True , create a page of type PageType.EMBED , if False the page type is PageType.MESSAGE . Defaults to True . |
embed_kwargs |
dict |
{} |
Others keywords arguments, used to initialize the Embed for display. Only used if the type of the page is PageType.EMBED . |
Create a link between the current page and the given page(s). This method is used to construct the tree.
def link(self, pages, reaction=None, description=None, callbacks=[], user_input=False, is_parent=True, parent_reaction='🔙')
Argument | Type | Default | Description |
---|---|---|---|
pages |
list of Page or Page
|
Required | Pages to associate to this link. |
reaction |
str |
None |
Reaction emoji needed by the user to take that link. If None is given, use a default reaction (digits 1 ~ 9). |
description |
str |
None |
Description of the link, to explain to user where this link will bring him. |
callbacks |
list |
[] |
List of functions to call when taking this link. |
user_input |
bool |
False |
Boolean indicating if this is a MsgLink. If True , a MsgLink is created, ignoring the reaction parameter. |
is_parent |
bool |
True |
Boolean indicating if the current page should be the parent of the linked pages. If True a link will be created between pages to the current page as a parent link. |
parent_reaction |
str or list of str
|
🔙 |
Emoji to use for the pages to go back to their parent : the current page. Used only if is_parent is True . Please use this only for advanced customization. To go even further, you can specify a list of string, where each string is the emoji to use for each page of the list of pages given. |
Throws :
-
IndexError
: Only the 9 first links are provided with default reactions (digit 1 ~ 9). If you try to create more link with default reaction, this exception will be thrown. -
ValueError
: The number of parent reactions given does not match the number of child pages.
Link a list of pages to the current page as a parent. This method is used to construct the tree, in order to set specific parent for some pages.
def parent_of(self, pages, parent_reaction='🔙')
Argument | Type | Default | Description |
---|---|---|---|
pages |
list of Page or Page
|
Required | Given pages will have the current page as a parent. |
parent_reaction |
str or list of str
|
🔙 |
Emoji to use for the pages to go back to their parent : the current page. Please use this only for advanced customization. To go even further, you can specify a list of string, where each string is the emoji to use for each page of the list of pages given. |
Throws :
-
ValueError
: The number of parent reactions given does not match the number of child pages.
Link a list of pages to the current page as root. This method is used to construct the tree, in order to set the root for some pages.
def root_of(self, pages, root_reaction='🔝')
Argument | Type | Default | Description |
---|---|---|---|
pages |
list of Page or Page
|
Required | Given pages will have the current page as root. |
root_reaction |
str or list of str
|
'🔝' | Emoji to use for the pages to go back to the root : the current page. Please use this only for advanced customization. To go even further, you can specify a list of string, where each string is the emoji to use for each page of the list of pages given. |
Throws :
-
ValueError
: The number of root reactions given does not match the number of pages given.
This method is called by the Help if the page is a PageType.MESSAGE
.
It returns the formatted content of the Page as a string.
This will display the main message of the Page, as well as the message describing each Link of the Page.
This method simply construct the string to send to the channel.
def get_message(self)
Returns :
-
str
: The content to display to user.
This method is called by the Help if the page is a PageType.EMBED
.
It returns an Embed
object, representing the formatted page.
This will display the main message of the Page, as well as the message describing each Link of the Page.
def get_embed(self)
Returns :
-
Embed
: Embed to display to user.
Method used by the Help, to retrieve the list of reactions that the user can use when visualizing the current page, to interact with the Help.
def reactions(self)
Returns :
-
list of str
: List of reactions that the user can use for this page.
Method used by the Help to know if a user can input something when using this page, or should only use reactions.
def need_user_input(self)
Returns :
-
bool
: ReturnTrue
if a MsgLink is associated to this page,False
otherwise.
Method used by the Help to access the next Link based on the reaction given. If the reaction is None
, retrieve the MsgLink. If the reaction is not valid (no link associated to this reaction), None
is returned.
def next_link(self, reaction=None)
Argument | Type | Default | Description |
---|---|---|---|
reaction |
str |
None |
Reaction chosen by the user, representing a Link. If None , the link returned is a MsgLink. |
Returns :
-
Link
: The next Link to display, based on the reaction of the user, orNone
if the choice of the user is not valid.
Enum representing the existing type of page. The type of a page define how this page will be displayed.
PageType.MESSAGE
PageType.EMBED
Base class representing all type of link. Links are the branches of the help tree. All links can have callbacks, and a description. Links also have a list of child pages.
Most of the time, we want a simple link, so the link have a single child, which is displayed if the link is taken. But sometimes we want something more complex, displaying different pages depending on the callbacks. It's multiple choices link. In that case, a link can have several child pages.
By default, if callbacks don't change this behavior, the first page of the list is selected.
Name | Type | Description |
---|---|---|
pages |
list of Page |
List of pages associated to this link. |
description |
str |
Descripton of this link, to explain to user the effect of this link. |
callbacks |
list |
List of functions to call when taking this link. |
path |
int |
Which child page will be displayed. Default to 0 (the first Page of the list). |
Constructor. Create a Link. Default path is 0.
def __init__(self, pages, description=None, callbacks=[])
Argument | Type | Default | Description |
---|---|---|---|
pages |
list of Page or Page
|
Required | List of pages associated to this link. If a single Page is given, it will create the list for you. |
description |
str |
None |
Description of this link, to explain to user the effect of this link. |
callbacks |
list |
[] |
List of functions to call when taking this link. |
Method called by the Help, after calling the callbacks. So the path was updated (or not) to select the right page, and this method return the appropriate page.
def page(self)
Returns :
-
Page
: The page selected by callbacks (or default choice).
Class for link using reaction to navigate to next page. Subclass of Link.
Name | Type | Description |
---|---|---|
... | ... | ... |
reaction |
str |
Reaction needed by the link to display the next page. |
Constructor. Create a ReactLink.
def __init__(self, reaction, pages, description=None, callbacks=[])
Argument | Type | Default | Description |
---|---|---|---|
reaction |
str |
Required | Reaction needed by the link to display the page. |
pages |
list of Page or Page
|
Required | List of pages associated to this link. If a single Page is given, it will create the list for you. |
description |
str |
None |
Description of this link, to explain to user the effect of this link. |
callbacks |
list |
[] |
List of functions to call when taking this link. |
Class for link using message from user to navigate to next page. Subclass of Link.
Name | Type | Description |
---|---|---|
... | ... | ... |
Constructor. Create a MsgLink.
def __init__(self, pages, description=None, callbacks=[])
Argument | Type | Default | Description |
---|---|---|---|
pages |
list of Page or Page
|
Required | List of pages associated to this link. If a single Page is given, it will create the list for you. |
description |
str |
None |
Description of this link, to explain to user the effect of this link. |
callbacks |
list |
[] |
List of functions to call when taking this link. |
Class for the first link of the tree : the root link. Subclass of Link.
Name | Type | Description |
---|---|---|
... | ... | ... |
Constructor. Create a RootLink.
There is no need of description, because this kind of links can never be described to user.
def __init__(self, pages, callbacks=[])
Argument | Type | Default | Description |
---|---|---|---|
pages |
list of Page or Page
|
Required | List of pages associated to this link. If a single Page is given, it will create the list for you. |
callbacks |
list |
[] |
List of functions to call when taking this link. |
Class representing the whole Help system. It's through this class that you can display the help system, and interact with the user.
Name | Type | Description |
---|---|---|
client |
Discord.Client |
Client Discord (from the python Discord API) used to send message, react, etc... |
tree |
RootLink |
First link of the tree, representing the whole help system. |
quit_react |
str |
Reaction used to leave the help system. |
Constructor. Create a the Help object. It also creates the RootLink as starting point.
def __init__(self, client, pages, callbacks=[], quit_react='❌')
Argument | Type | Default | Description |
---|---|---|---|
client |
Discord.Client |
Required | Discord client used to send message, react, etc... |
pages |
list of Page or Page
|
Required | List of pages representing the starting point of the help system. |
callbacks |
list |
[] |
List of functions to call when taking this link. |
quit_react |
str |
'❌' |
Reaction used to leave the help system. |
Main function of the object : when a user request help, simply call this function. It will display the first message of the help system, and then wait the user to react. Depending on the reaction, it will display the next page, etc...
It finishes when the user quit the help system.
Note : This function is asynchronous. Be sure to call it like this : await h.display(...)
async def display(self, member)
Argument | Type | Default | Description |
---|---|---|---|
member |
Discord.Member |
Required | Discord member who requested help. Help will be displayed as a private message to him. You can obtain the member from a message like this : member = message.author
|