Making your first keyword - VikingsDev/Dentaku GitHub Wiki

Making your first keyword

Contribution guidelines

For a full, comprehensive read on contribution, take a look at our CONTRIBUTING.md.

Step 1 - Decide on a keyword

Think up of a keyword! For this tutorial, we will be using the keyword ligma.

Step 2 - Add your keyword to the keywords.json file

Use your favourite text editor to open up keywords.json, and you might see something like this:

{
  "bruh": "bruh",
  "candince": "cndce",
  "sugma": "sugma_keyword_balls"
}

Now, we'll add ligma in like this:

{
  "bruh": "bruh",
  "candince": "cndce",
  "sugma": "sugma_keyword_balls",
  "ligma": "ligmaballs"
}

The left side of the colon is the keyword, and the right side is the python file that will be run by it. That is to say, when "ligma" is typed in chat, the file ligmaballs.py will be run.

Step 3 - Making the Python File

Now we'll add ligmaballs.py in the folder keywords. Just create a new file in that folder, or use touch ligmaballs.py

Inside ligmaballs.py, start with this template: (Replace all occurrences of 'ligmaballs' with your chosen file name.)

from keywords.keyword import Keyword
from fbchat import Message
from fbchat import Mention


class ligmaballs(Keyword):

    def run(self):
        response_text = "@" + self.author.first_name + " more like ligma BALLS! HA!"
        mentions = [Mention(self.author_id, length=len(self.author.first_name) + 1)]

        self.client.send(
            Message(text=response_text, mentions=mentions),
            thread_id=self.thread_id,
            thread_type=self.thread_type
        )

    def define_documentation(self):
        self.documentation = {
            "trigger": "ligma",
            "function": "Makes a ligma joke."
        }