/*
 * delchan.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_delchan(char *a);

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

  snprintf(dl->help, MAX_COMMAND_HELP_LEN,
	   "/msg %s DELCHAN <channel>\nDeletes a channel from the lists of the bot. COMPLETELY. Do not use this command unless you really mean it.\n", BOT_NAME);
  snprintf(dl->summary, MAX_COMMAND_SUMMARY_LEN,
	   "Deletes a channel from the lists");
  dl->level = 950;
#if 0
  dl->func = m_delchan;
#else
  dl->func = (void (*)(char*)) DL_sym(dl->val, "m_delchan");
#endif
  return 1;
}

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

MODULE_PUBLIC void m_delchan(char *a)
{
  int i;
  char channel[CHANNELLEN+1];
  struct dbaseuser *db;
  db = sender_au->dbuser;
  if(db) {
    log("From: %s delchan [%s]\n", db->nick, a);
  } else
    return;
  if(!is_oper()) {
    say_sender("You are not an Oper.");
    log("To: %s Is not an Oper\n", db->nick);
    return;
  }

  i=0;
  strncpy(channel,getword(a,&i),CHANNELLEN);
  channel[CHANNELLEN] = '\0';
  if(!strlen(channel)) {
    say_sender( "You forgot to type the channelname");
    say_sender_( "/msg %s DELCHAN #channel", BOT_NAME);
    return;
  }
#if 0
  /* could be nice to be able to remove strange channels without '#' */
  if(channel[0]!='#') {
    say_sender( "Channel must begin with a '#'");
    say_sender_( "/msg %s DELCHAN #channel", BOT_NAME);
    return;
  }
#endif
  if(delchannel(channel)) {
    say_sender( "Channel deleted.");
  } else {
    say_sender( "Couldn't find that channel.");
  }
  say_sender("Done.");
  return;
}
