/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/ 
 * 
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License. 
 *
 * The Original Code is ChatZilla
 * 
 * The Initial Developer of the Original Code is
 * Robert Ginda
 * Portions created by Robert Ginda are Copyright (C) 2003 Robert Ginda.
 *
 * Alternatively, the contents of this file may be used under the
 * terms of the GNU Public License (the "GPL"), in which case the
 * provisions of the GPL are applicable instead of those above.
 * If you wish to allow use of your version of this file only
 * under the terms of the GPL and not to allow others to use your
 * version of this file under the MPL, indicate your decision by
 * deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL.  If you do not delete
 * the provisions above, a recipient may use your version of this
 * file under either the MPL or the GPL.
 *
 * Contributor(s):
 *  Robert Ginda, <rginda@hacksrus`com>, original author
 */

/*
 * So in ChatZilla 0.8.x, the plugin story was pretty simple.  You create a .js
 * file anywhere on your disk and point chatzilla to it.  That still works, 
 * but with 0.9.x, you also have the ability to store your scripts in a known
 * place, and have chatzilla discover them for itself.  The idea is that this
 * should make it much easier to share your scripts with other users.
 *
 * As of 0.9.x, ChatZilla treats the "initialScripts" pref as a search path.
 * If an entry in the initialScripts path is a file it is loaded as it was in
 * 0.8.x, but if it is a directory, something different happens.  ChatZilla 
 * first checks to see if there is a file called "init.js" in the directory.
 * If so, the file will be loaded and executed.  Once that happens, ChatZilla
 * will scan just the first level of subdirectories for more init.js files,
 * executing each one it finds.
 *
 * The upshot of all this is that once you point chatzilla at a directory,
 * installing a new plugin is as easy as dropping init.js in a subdirectory.
 *
 * If you havn't previously set your initialScripts pref, it will default
 * to your-profile-path/chatzilla/scripts.  This is the recommended place
 * to store plugins.  If you have already set your initialScripts pref,
 * you can restore the default value by typing ``/ initialScripts -''.  Then
 * copy your old startup script to the chatzilla/scripts directory, giving
 * it the name init.js.  The next time you start ChatZilla, you should see
 * your script loaded as usual.
 *
 * As of 0.9.x, ChatZilla automatically creates a |plugin| object for you,
 * which starts off as a mostly blank object.  This object can be used to
 * communicate to ChatZilla or other plugins, information about your state.
 * ChatZilla will now invoke |initPlugin| when your plugin is first loaded,
 * passing you a reference to your global object.  If you would like to support
 * being disabled/enabled, define disablePlugin and enablePlugin functions.
 * ChatZilla will call these functions in response to the /disable-plugin
 * and /enable-plugin commands.
 *
 * You are expected to decorate the plugin object with at least the following
 * properties:
 *          plugin.id   A unique identifier for your plugin.  Used to
 *                      identify the plugin for some commands.
 *       plugin.minor   Minor version number
 *       plugin.major   Major version number
 *     plugin.version   String representation of version number
 * plugin.description   String description of plugin.
 *
 * This information can be queried at runtime with the /list-plugins command.
 *
 * If you'd like to install a plugin created by someone else, just copy it into
 * a subdirectory of chatzilla/scripts and everything should Just Work.
 */

plugin.id = "example-plugin";
plugin.major = 0
plugin.minor = 1
plugin.version = plugin.major + "." + plugin.minor;
plugin.description = "Adds shortcuts to the faces motifs and a /cycle " +
                     "command.";

plugin.init =
function initPlugin(glob)
{
    /* This function will be called when chatzilla first loads the plugin.
     * We initialize some of the plugin object's properties, define a new
     * command and some new prefs, and print out a message.
     */     

    /* a global pref will be created for each item in the pref array.
     * By adding these motif.* preferences, we're creating shortcuts
     * that can be used with the /motif command.
     */


    /* A command will be created for each item in here.
     * The first position contains the command name, then the function to
     * be associated with this command (if this is a string instead of a
     * function, an alias will be created.)  The the flags.  If null is
     * passed, the default flags will be used.  The final column is the
     * parameter list, which is used to parse the command line and initialize
     * the |e| object.
     *
     * The following flags are available:
     *
     *   CMD_CONSOLE   The command is available from the console.
     *
     *   CMD_NEED_NET  The command requires a network.  Your command
     *                 will be *guaranteed* to have a valid e.network object
     *                 when it is invoked, regardless of your parameter
     *                 list.
     *
     *   CMD_NEED_SRV  The command requires a *connected* server.
     *
     *  CMD_NEED_CHAN  The command requires a channel.
     *
     *  CMD_NEED_USER  The command requires a user.
     *
     *    CMD_NO_HELP  Tells the command manager not to complain about commands
     *                 without help text.
     *
     * The default flags are CMD_CONSOLE | CMD_NO_HELP.
     */
    plugin.cmdary =
			[/* comand name     function               	flags    usage*/
			["nowplaying",		cmdNowPlaying,		   	null,],
			["np",				cmdNowPlaying,			null,],

        ];  
    
    client.commandManager.defineCommands(plugin.cmdary);

    display("loaded from url " + plugin.url);
}

plugin.disable =
function disablePlugin(status)
{
    display("disabling " + plugin.id);
}

plugin.enable =
function enablePlugin(status)
{
    display("enabling " + plugin.id);
}

//calls readfile and dispatches the nowplaying value to the current channel.
function cmdNowPlaying(e)
{
	nowplaying = readFile("C:\\Users\\Ramon\\AppData\\Local\\nowplaying.txt");
	dispatch("me " + nowplaying, {channelName: e.channelName});
}

//Opens the file, reads from it and returns the value
function readFile(fileName)
{
	/*calls the file again, < means read only*/
	var f = new LocalFile(fileName,"<");
	nowplaying = f.read();
	//closing ensures the file isn't left open, allowing us to use it in other ways in the future
	f.close(); 
	return nowplaying;
}

