Dongle/AddonTemplate

This is an example template for a setup for an addon that uses Dongle. It shows how to use the various API's that dongle offers such as the slash commands and the database.
-- This instantiates the Dongle object. From here you will be able to access
-- the Dongle API.
local addon = DongleStub('Dongle-1.1'):New('DongleAddonTemplate')
-- This is the table containing the default entries for the database. if
-- something cant be found in the database, this will automatically be
-- checked. This will not get saved in the database table.
local databasedefaults = {
	profile = {
		message = 'This is the default message!'
	}
}
--- PrintAbout: Print some text explaining the purpose of this addon.
-- This is for the slash command handler 'about'.
function addon:PrintAbout ()
	self:Print([[This addon is for developers to act as a template for
a setup for an addon that uses dongle. It shows how to use the various API's
that dongle offers such as the slash commands and the database.]])
end
--- PrintMessage: Print the message that is in the database.
-- This is for the slash command handler 'print-message'. It prints the
-- default message that is in the database or your own if you have saved your
-- own with the 'change-message' slash command.
function addon:PrintMessage ()
	-- Get the message from the database.
	local message = self.db.profile.message
	-- Check if the message exists and print it, if not; do nothing.
	if message then
		self:Print(message)
	end
end
--- ChangeMessage: Change the default message that the slash command
-- 'print-message' uses to something else.
-- @param message The message to change the default message to.
function addon:ChangeMessage (message)
	-- Check if there is a message, if not; do nothing.
	if message then
		self.db.profile.message = message
	end
end
--- Initialize: Initialize the addon. 
-- This will be executed at ADDON_LOADED after all the files of the addon have
-- been loaded.
-- Things like initializing the slash commands and database api as well as
-- other things your addon needs defined go here.
function addon:Initialize ()
	-- Initialize the database with the local defaults table.
	self.db = self:InitializeDB('DongleAddonTemplateDB', databasedefaults)
	-- Initialize the slash command.
	self.slashcmd = self:InitializeSlashCommand('DongleAddonTemplate Slash Command',
	'DONGLEADDONTEMPLATE', 'dat', 'dongleaddontemplate')
end
--- Enable: Enable the addon. 
-- This will be executed at PLAYER_LOGIN, after all addons have initialized.
-- The rest of the things that need to happen go in here, such as positioning
-- frames, enabling hooks and registering for events.
function addon:Enable ()
	-- Add a slash command handler called about that matches the lua pattern
	-- '^about$' to the function 'PrintAbout'.
	self.slashcmd:RegisterSlashHandler(
	'about: Print some text explaining the purpose of this addon.', '^about$',
	'PrintAbout')
	-- Add another slash command for printing a message. The pattern
	-- '^print-message (.+)$' will pass anything after 'print-message' to the
	-- handler function. The handler function fetches this in an argument.
	self.slashcmd:RegisterSlashHandler(
	'print-message: Print the message from the database', '^print-message (.+)$',
	'PrintMessage')
end
-- Disable: Disable the addon. 
-- This will be executed at PLAYER_LOGOUT.
-- Here you can unhook, unregister your events and clean up/reset things you
-- have changed.
function addon:Disable ()
end
Category:Dongle