action.py - VikingsDev/Dentaku GitHub Wiki

action.py, The Action Class

All commands and keywords must inherit Action. Inheriting `Action' you these variables:

self.author_id

ID of the person who sent this action.

self.message_object

The action's message object. Type: fbchat.Message

self.thread_id

ID of the chat this action was sent in.

self.thread_type

Type of the chat this action was sent in. Type: fbchat.ThreadType(enum)

self.client

The Dentaku user account. Type: fbchat.Client

self.author

The object of the person who sent this action. Type: fbchat.User

self.database

A dictionary that exists independently of each Action. It is mutable, which means you can change self.database within your Action and that change would be seen in every Action run after that. Type: dict

self.memory

A dictionary that's specific to each user and Action. Allows you to make long term interactions. Example: rps.py in the commands module. Type: dict

self.gdb

An object representing the VikingsDev Cloud Firestore. Type: google.cloud.firestore_v1.client.Client

Guide on how to use Cloud Firestore The equivalent of db.collection(u'users') is self.gdb.collection(u'users')

self.documentation

The documentation object. Contains the properties "parameters" and "function". The parameters are to specify what the user should input after calling the action. The function is to describe what the action does.

Example:

countdown.py

self.documentation = {

"parameters": "NUMBER",
"function": "To countdown recursively, starting from NUMBER."

}

Implement self.documentation in your action by adding the function define_documentation(self) within the class of your action.

def define_documentation(self):
    self.documentation = {
        "parameters": "NUMBER",
        "function": "Counts down recursively from NUMBER."
    }

You must run the function define_documentation before retrieving the documentation object or else it will be empty.

Important: When you define the parameters of your command, please make them capitalized. If you have no parameters, simply use "None" as your parameter. When defining "function", be as concise as possible and reference all possible parameters.

(If you are confused, take a peek at the other commands to see self.documentation conventions!)