Hardware Reference
In-Depth Information
def prof_post_chat_message_display(jid, message) : Here comes the
most important function of our plugin. Every time a new chat message is
received and displayed by Profanity, we do the following:
° Check if jid (the unique identifier of your friend) has already started
a chat session with the bot, and if not, create one now.
° Take the message received from your friend, send it to the bot
using the .think method and store the response from the bot in the
variable named response .
° Send the response back to your friend using the versatile send_line
function, which can be used to trigger any command in Profanity.
def _cmd_agentbot(state) : Here we define the Profanity command /
agentbot , which is used to enable , disable , or query the current status if
issued without arguments.
def prof_init(version, status) : When our plugin loads, we use the
register_command function to register our /agentbot command. The
arguments are as follows:
° The crucial command as typed in Profanity.
° Minimum command arguments. In this case we want to be able to
type /agentbot without arguments to request status, so 0 .
° Maximum command arguments. We also want to be able to specify
enable or disable , so that's 1 argument.
° Usage information (currently unused).
° Short help text (currently unused).
° Long help text (currently unused).
° Name of function to call when command is issued.
Awakening the bot
Now all that is left for us to do is to tell Profanity to load the plugin. Open up the
Profanity configuration file for editing:
pi@raspberrypi ~ $ nano ~/.config/profanity/profrc
Now add these two lines:
[plugins]
load=agentbot.py
 
Search WWH ::




Custom Search