<commit_before>from __future__ import absolute_import
import os, os.path
import traceback as sys_traceback
import time as sys_time
import re
import locale
encoding = locale.getdefaultlocale()[1] or "ascii"
import threading
import argparse
import irc.client
import sqlite3
import shlex
import datetime
import json

__all__ = ["Plugin", "StandardPlugin", "CorePlugin", "PrivilegedPlugin", "PrivilegedCorePlugin", "ChannelHandler", "ChannelJoinHandler", "Poller", "Announcer", "register_plugin", "register_channel_handler", "register_channel_join_handler", "register_poller", "register_announcer", "from_utf8", "to_utf8", "green", "red", "bold", "exc2str"]

_tehbot = None
_modules = []

class ArgumentParserError(Exception):
    pass

class ThrowingArgumentParser(argparse.ArgumentParser):
    def error(self, message):
        raise ArgumentParserError(message)

    def print_help(self, file=None):
        self.help_requested = True

    def parse_args(self, args=None, namespace=None, decode=True):
        self.help_requested = False
        if isinstance(args, basestring):
            args = mysplit(args, decode)

        try:
            return argparse.ArgumentParser.parse_args(self, args, namespace)
        except SystemExit:
            pass

class Plugin:
    """This is where the help text goes."""

    def __init__(self):
        self.tehbot = _tehbot
        self.logtodb = True
        self.pub_allowed = True
        self.priv_allowed = True
        self.initialize(self.tehbot.dbconn)

    def handle(self, connection, event, extra, dbconn):
        if not self.settings["enabled"]:
            return

        if irc.client.is_channel(event.target):
            target = event.target
            if not self.pub_allowed:
                return
        else:
            target = event.source.nick
            if not self.priv_allowed:
                return

        res = self.execute(connection, event, extra, dbconn)
        if isinstance(res, basestring):
            res = [("say", res)]
        elif res is None:
            res = [("none",)]

        for r in res:
            if r[0] == "say" or r[0] == "me":
                globals()[r[0]](connection, target, r[1], dbconn if self.logtodb else None)
            elif r[0] == "nopriv":
                say(connection, target, u"%s is NOT privileged" % event.source.nick, dbconn if self.logtodb else None)
                break
            elif r[0] == "doauth":
                extra["request_priv_called"] = True

                params = self.tehbot.settings.connection_params(connection)
                for t, s in params["operators"]:
                    if t == "host" and s == event.source.host:
                        self.tehbot.privusers[connection].add(event.source.nick)
                        self.tehbot.mainqueue.put((self, (connection, event, extra)))
                        return

                self.tehbot.privqueue[connection, event.source.nick].put((self, (connection, event, extra)))
                connection.whois(event.source.nick)
                return<commit_msg>change output of priv call<commit_after>from __future__ import absolute_import
import os, os.path
import traceback as sys_traceback
import time as sys_time
import re
import locale
encoding = locale.getdefaultlocale()[1] or "ascii"
import threading
import argparse
import irc.client
import sqlite3
import shlex
import datetime
import json

__all__ = ["Plugin", "StandardPlugin", "CorePlugin", "PrivilegedPlugin", "PrivilegedCorePlugin", "ChannelHandler", "ChannelJoinHandler", "Poller", "Announcer", "register_plugin", "register_channel_handler", "register_channel_join_handler", "register_poller", "register_announcer", "from_utf8", "to_utf8", "green", "red", "bold", "exc2str"]

_tehbot = None
_modules = []

class ArgumentParserError(Exception):
    pass

class ThrowingArgumentParser(argparse.ArgumentParser):
    def error(self, message):
        raise ArgumentParserError(message)

    def print_help(self, file=None):
        self.help_requested = True

    def parse_args(self, args=None, namespace=None, decode=True):
        self.help_requested = False
        if isinstance(args, basestring):
            args = mysplit(args, decode)

        try:
            return argparse.ArgumentParser.parse_args(self, args, namespace)
        except SystemExit:
            pass

class Plugin:
    """This is where the help text goes."""

    def __init__(self):
        self.tehbot = _tehbot
        self.logtodb = True
        self.pub_allowed = True
        self.priv_allowed = True
        self.initialize(self.tehbot.dbconn)

    def handle(self, connection, event, extra, dbconn):
        if not self.settings["enabled"]:
            return

        if irc.client.is_channel(event.target):
            target = event.target
            if not self.pub_allowed:
                return
        else:
            target = event.source.nick
            if not self.priv_allowed:
                return

        res = self.execute(connection, event, extra, dbconn)
        if isinstance(res, basestring):
            res = [("say", res)]
        elif res is None:
            res = [("none",)]

        for r in res:
            if r[0] == "say" or r[0] == "me":
                globals()[r[0]](connection, target, r[1], dbconn if self.logtodb else None)
            elif r[0] == "nopriv":
                say(connection, target, u"%s is \x02not\x02 privileged" % event.source.nick, dbconn if self.logtodb else None)
                break
            elif r[0] == "doauth":
                extra["request_priv_called"] = True

                params = self.tehbot.settings.connection_params(connection)
                for t, s in params["operators"]:
                    if t == "host" and s == event.source.host:
                        self.tehbot.privusers[connection].add(event.source.nick)
                        self.tehbot.mainqueue.put((self, (connection, event, extra)))
                        return

                self.tehbot.privqueue[connection, event.source.nick].put((self, (connection, event, extra)))
                connection.whois(event.source.nick)
                return
{'fraction_non_alphanumeric': 0.10753036437246964, 'fraction_numerical': 0.004210526315789474, 'mean_word_length': 2.3767085839256423, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, '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': '1045909', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1718, 'n_words': 451}