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

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

  snprintf(dl->help, MAX_COMMAND_HELP_LEN,
	   "/msg %s BADCHANNELLIST\nList all illegal channels. People joining channels matching this list, will be killed at once.\n", BOT_NAME);
  snprintf(dl->summary, MAX_COMMAND_SUMMARY_LEN,
	   "List all illegal channels");
  dl->level = 990;
#if 0
  dl->func = m_badchannellist;
#else
  dl->func = (void (*)(char*)) DL_sym(dl->val, "m_badchannellist");
#endif
  return 1;
}

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

MODULE_PUBLIC void m_badchannellist(char *a)
{
  ListElem *el;
  struct bad_chan *bad_channel;
  char tmp[256];
  int i;
  struct dbaseuser *db;
  struct dbaseuser *owner;
  db = sender_au->dbuser;
  if(db) {
    log("From: %s badchannellist\n", db->nick);
  } else
    return;
  if(!is_oper()) {
    say_sender("You are not an Oper.");
    log("To: %s Is not an Oper\n", db->nick);
    return;
  }
  say_sender( "Bad channels are:");
  el = GetHead(bad_channel_list);
  i = 0;
  while(el) {
    bad_channel = ((struct bad_chan *)(el->data));
    if(bad_channel && bad_channel->channel) {
      i++;
      owner = finduserfromid(bad_channel->owner);
      if(owner)
	snprintf(tmp, 256, "%2d: %-20s %s %s", i, bad_channel->channel, owner->nick, bad_channel->reason);
      else
	snprintf(tmp, 256, "%2d: %-20s %s %s", i, bad_channel->channel, "???", bad_channel->reason);
      say_sender( tmp);
    }
    el = GetSucc(el);
  }
  say_sender("Done.");
  return;
}
