<commit_before>part of polymorphic.bot;

class Bot {

  /**
   * The network name.
   */
  final String server;

  /**
   * Holds basic information to start a bot.
   */
  final serverConfig;

  /**
   * Holds the channel information the bot should auto join.
   */
  final channelConfig;

  /**
   * Holds the prefix information for the network or individual channels.
   */
  final prefixConfig;

  /**
   * Holds all the permission nodes the user has permission to.
   */
  final permsConfig;

  /**
   * Holds all the permission nodes for each group.
   */
  final groupsConfig;

  /**
   * The client which manages the IRC connections and data.
   */
  IRC.Client get client => _client;
  IRC.Client _client;

  /**
   * The manager handles permissions
   */
  Auth get authManager => _authManager;
  Auth _authManager;

  Bot(this.server, this.serverConfig, this.channelConfig, this.prefixConfig, this.permsConfig, this.groupsConfig) {
    var botConfig = new IRC.IrcConfig();
    botConfig.nickname = serverConfig['nickname'];
    botConfig.realname = serverConfig['realname'];
    botConfig.host = serverConfig['host'];
    botConfig.port = serverConfig['port'];
    _client = new IRC.Client(botConfig);

    _registerRawHandler();
    _registerReadyHandler();
    _registerMessageHandler();
    _registerCommandHandler();

    client.register((IRC.CTCPEvent event) {
      if (event.message.trim().toUpperCase() == "ARE YOU A BOT") {
        client.sendCTCP(event.user, "I AM A BOT");
      }
    });

    client.register((IRC.NickChangeEvent event) {
      if (_botMemory.containsKey(event.original)) {
        _botMemory[event.now] = _botMemory[event.original];
        _botMemory.remove(event.original);
      }
    });
  }

  void start() {
    print("[$server] Connecting");
    client.connect();
  }

  Map<String, bool> _botMemory = {};

  void clearBotMemory() => _botMemory.clear();

  Future<bool> isUserBot(String user) {
    if (user == client.nickname) {
      return new Future.value(true);
    }

    var isBot = false;

    if (_botMemory.containsKey(user)) {
      return new Future.value(_botMemory[user]);
    }

    if (client.getChannel("#bot-communication") == null) {
      return new Future.value(false);
    } else if (!client.getChannel("#bot-communication").allUsers.contains(user)) {
      return new Future.value(false);
    }

    client.register((IRC.MessageEvent event) {
      isBot = true;
    }, filter: (IRC.MessageEvent e) => e.from != user || e.channel != "#bot-communication" || e.message != "${client.nickname}: I AM A BOT.", once: true);
    client.sendMessage("#bot-communication", "${user}: ARE YOU A BOT?");

    return new Future.delayed(new Duration(seconds: 2), () {
      _botMemory[user] = isBot;
      return isBot;
    });
  }

  void _registerRawHandler() {
    void _rawHandler(IRC.LineReceiveEvent event) {
      print("[$server] ${event.line}");
    }
    client.register(_rawHandler);
    client.register((IRC.ReadyEvent event) {
      new Future.delayed(new Duration(milliseconds: 20), () {
        client.unregister(_rawHandler);
      });
    });
  }

  void _registerReadyHandler() {
    client.register((IRC.ReadyEvent event) {
      if (serverConfig['owner'] != null) {
        client.identify(username: serverConfig['owner'], password: serverConfig['password'], nickserv: serverConfig['nickserv'] != null ? serverConfig['nickserv'] : "NickServ");
      }
      print("[$server] Bot is Ready");
      for (var chan in channelConfig) {
        print("[$server] Joining $chan");
        event.join(chan);
      }

      if (serverConfig['broadcast'] != null && serverConfig['broadcast']) {
        event.join("#bot-communication");
      }
    });
  }

  void _registerMessageHandler() {
    client.register((IRC.MessageEvent event) {
      var from = event.from;
      var msg = event.message;

      if (event.channel.name == "#bot-communication") {
        if (msg.trim() == "${client.nickname}: ARE YOU A BOT?") {
          event.reply("${event.from}: I AM A BOT.");
        } else if (msg.trim().endsWith(": I AM A BOT.")) {
          var nick = msg.split(":")[0].trim();
          if (_botMemory[nick] != true) {
            _botMemory[nick] = true;
            Globals.pluginHandler.pm.sendAll({
              "type": "event",
              "event": "bot-detected",
              "network": server,
              "user": nick
            });
          }
        } else if (msg.trim() == "FIND BOTS") {
          event.reply("${event.from}: I AM A BOT.");
        } else if (msg.trim() == "PREFIXES") {
          event.reply("MY PREFIX FOR ${event.channel.name} IS ${getPrefix(event.channel.name)}");
        } else if (msg.trim().startsWith("${client.nickname}: WHAT IS YOUR PREFIX FOR ") && msg.trim().endsWith("?")) {
          var channel = msg.trim().substring("${client.nickname}: WHAT IS YOUR PREFIX FOR ".length, msg.trim().length - 1);
          event.reply("${event.from}: MY PREFIX FOR ${channel} IS ${getPrefix(channel)}");
        } else if (msg.trim() == "${client.nickname}: WHAT EXTENSIONS DO YOU SUPPORT?") {
          event.reply("${event.from}: I SUPPORT " + Globals.EXTENSIONS.join(" "));
        } else if (msg.trim() == "${client.nickname}: WHAT POLYMORPHIC PLUGINS DO YOU HAVE?") {
          event.reply("${event.from}: I HAVE THE POLYMORPHIC PLUGINS ${Globals.pluginHandler.pm.plugins.join(" ")}");
        }
        return;
      }

      if (event.isPrivate) {
        print("[$server] <$from> $msg");
      } else {
        print("[$server] <${event.channel.name}><$from> $msg");<commit_msg>Dont use puncuation.<commit_after>part of polymorphic.bot;

class Bot {

  /**
   * The network name.
   */
  final String server;

  /**
   * Holds basic information to start a bot.
   */
  final serverConfig;

  /**
   * Holds the channel information the bot should auto join.
   */
  final channelConfig;

  /**
   * Holds the prefix information for the network or individual channels.
   */
  final prefixConfig;

  /**
   * Holds all the permission nodes the user has permission to.
   */
  final permsConfig;

  /**
   * Holds all the permission nodes for each group.
   */
  final groupsConfig;

  /**
   * The client which manages the IRC connections and data.
   */
  IRC.Client get client => _client;
  IRC.Client _client;

  /**
   * The manager handles permissions
   */
  Auth get authManager => _authManager;
  Auth _authManager;

  Bot(this.server, this.serverConfig, this.channelConfig, this.prefixConfig, this.permsConfig, this.groupsConfig) {
    var botConfig = new IRC.IrcConfig();
    botConfig.nickname = serverConfig['nickname'];
    botConfig.realname = serverConfig['realname'];
    botConfig.host = serverConfig['host'];
    botConfig.port = serverConfig['port'];
    _client = new IRC.Client(botConfig);

    _registerRawHandler();
    _registerReadyHandler();
    _registerMessageHandler();
    _registerCommandHandler();

    client.register((IRC.CTCPEvent event) {
      if (event.message.trim().toUpperCase() == "ARE YOU A BOT") {
        client.sendCTCP(event.user, "I AM A BOT");
      }
    });

    client.register((IRC.NickChangeEvent event) {
      if (_botMemory.containsKey(event.original)) {
        _botMemory[event.now] = _botMemory[event.original];
        _botMemory.remove(event.original);
      }
    });
  }

  void start() {
    print("[$server] Connecting");
    client.connect();
  }

  Map<String, bool> _botMemory = {};

  void clearBotMemory() => _botMemory.clear();

  Future<bool> isUserBot(String user) {
    if (user == client.nickname) {
      return new Future.value(true);
    }

    var isBot = false;

    if (_botMemory.containsKey(user)) {
      return new Future.value(_botMemory[user]);
    }

    if (client.getChannel("#bot-communication") == null) {
      return new Future.value(false);
    } else if (!client.getChannel("#bot-communication").allUsers.contains(user)) {
      return new Future.value(false);
    }

    client.register((IRC.MessageEvent event) {
      isBot = true;
    }, filter: (IRC.MessageEvent e) => e.from != user || e.channel != "#bot-communication" || e.message != "${client.nickname}: I AM A BOT.", once: true);
    client.sendMessage("#bot-communication", "${user}: ARE YOU A BOT?");

    return new Future.delayed(new Duration(seconds: 2), () {
      _botMemory[user] = isBot;
      return isBot;
    });
  }

  void _registerRawHandler() {
    void _rawHandler(IRC.LineReceiveEvent event) {
      print("[$server] ${event.line}");
    }
    client.register(_rawHandler);
    client.register((IRC.ReadyEvent event) {
      new Future.delayed(new Duration(milliseconds: 20), () {
        client.unregister(_rawHandler);
      });
    });
  }

  void _registerReadyHandler() {
    client.register((IRC.ReadyEvent event) {
      if (serverConfig['owner'] != null) {
        client.identify(username: serverConfig['owner'], password: serverConfig['password'], nickserv: serverConfig['nickserv'] != null ? serverConfig['nickserv'] : "NickServ");
      }
      print("[$server] Bot is Ready");
      for (var chan in channelConfig) {
        print("[$server] Joining $chan");
        event.join(chan);
      }

      if (serverConfig['broadcast'] != null && serverConfig['broadcast']) {
        event.join("#bot-communication");
      }
    });
  }

  void _registerMessageHandler() {
    client.register((IRC.MessageEvent event) {
      var from = event.from;
      var msg = event.message;

      if (event.channel.name == "#bot-communication") {
        if (msg.trim() == "${client.nickname}: ARE YOU A BOT") {
          event.reply("${event.from}: I AM A BOT");
        } else if (msg.trim().endsWith(": I AM A BOT")) {
          var nick = msg.split(":")[0].trim();
          if (_botMemory[nick] != true) {
            _botMemory[nick] = true;
            Globals.pluginHandler.pm.sendAll({
              "type": "event",
              "event": "bot-detected",
              "network": server,
              "user": nick
            });
          }
        } else if (msg.trim() == "FIND BOTS") {
          event.reply("${event.from}: I AM A BOT");
        } else if (msg.trim() == "PREFIXES") {
          event.reply("MY PREFIX FOR ${event.channel.name} IS ${getPrefix(event.channel.name)}");
        } else if (msg.trim().startsWith("${client.nickname}: WHAT IS YOUR PREFIX FOR ")) {
          var channel = msg.trim().substring("${client.nickname}: WHAT IS YOUR PREFIX FOR ".length);
          event.reply("${event.from}: MY PREFIX FOR ${channel} IS ${getPrefix(channel)}");
        } else if (msg.trim() == "${client.nickname}: WHAT EXTENSIONS DO YOU SUPPORT") {
          event.reply("${event.from}: I SUPPORT " + Globals.EXTENSIONS.join(" "));
        } else if (msg.trim() == "${client.nickname}: WHAT POLYMORPHIC PLUGINS DO YOU HAVE") {
          event.reply("${event.from}: I HAVE THE POLYMORPHIC PLUGINS ${Globals.pluginHandler.pm.plugins.join(" ")}");
        }
        return;
      }

      if (event.isPrivate) {
        print("[$server] <$from> $msg");
      } else {
        print("[$server] <${event.channel.name}><$from> $msg");
{'fraction_non_alphanumeric': 0.15804597701149425, 'fraction_numerical': 0.0008081896551724138, 'mean_word_length': 2.766317213391951, 'pattern_counts': {'":': 12, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '716548', 'n_tokens_mistral': 3486, 'n_tokens_neox': 3360, 'n_words': 786}