/*
 * help.c
 * (C) Christian Magnusson 2000, Email: d1mag@dtek.chalmers.se
 * This program is copyright, and covered by the Gnu Public License.
 * The Q bot.
 */

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include "settings.h"
#include "bottypes.h"
#include "globals.h"
#include "dl.h"

void m_help(char *a);

MODULE_PUBLIC int _init_help(void *a, void *b)
{
  dl_command_entry_t *dl = a;
  if(!a) return 0;

  snprintf(dl->help, MAX_COMMAND_HELP_LEN,
	   "/msg %s HELP <command>\nGives the full help (like this!) instead of the short help for a particular bot command.\n"
	   , BOT_NAME);
  snprintf(dl->summary, MAX_COMMAND_SUMMARY_LEN,
	   "Gives full help on a particular bot command.");
  dl->level = 0;
#if 0
  dl->func = m_help;
#else
  dl->func = (void (*)(char*)) DL_sym(dl->val, "m_help");
#endif
  return 1;
}

MODULE_PUBLIC int _remove_help(char *a, char *b)
{
  remove_command("help");
  return 1;
}

MODULE_PUBLIC void m_help(char *a)
{
  int i;
  dl_command_entry_t *cmd;
  char helpcom[80+1];

  if(!sender_au) return;
  i=0;
  strncpy(helpcom, getword(a,&i), 80);
  helpcom[80] = '\0';
  if(strlen(helpcom) > 0) {
    cmd = findcommand(helpcom);
    if(cmd) {
      dumpmessage_u(sender_au, cmd->help);
      return;
    }
    say_sender_("No help found on that topic. Try /msg %s SHOWCOMMANDS.", BOT_NAME);
  } else {
    say_sender_("Try /msg %s SHOWCOMMANDS  or /msg %s HELP <command>", BOT_NAME, BOT_NAME);
  }
  return;
}
