-
Notifications
You must be signed in to change notification settings - Fork 7
Making your first keyword
Ratana edited this page Feb 1, 2020
·
5 revisions
For a full, comprehensive read on contribution, take a look at our CONTRIBUTING.md.
Think up of a keyword! For this tutorial, we will be using the keyword ligma
.
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.
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."
}