<commit_before>from ast import literal_eval
import os
import time

from zirc.util import repl
import config
import log
from utils.util import add_cmd
import utils


@add_cmd("eval", alias=['py', '>>'], min_args=1, owner=True, hide=True)
def eval_cmd(bot, event, irc, args):
    """Admin console"""
    console = repl.Repl({'self': bot, 'bot': bot, 'irc': irc, 'event': event})
    try:
        output = console.run(" ".join(args)).splitlines()
        for line in output:
            if len(line):
                irc.reply(event, line)

    except Exception as e:
        irc.reply(event, "{0}: {1}".format(e.__class__.__name__, e.args[0]))
        utils.util.print_error(irc, event)


@add_cmd("nick", owner=True, min_args=1)
def nick(bot, event, irc, args):
    """<nick>
    Changes the bot's nickname"""
    bot.config['nickname'] = args[0]
    irc.nick(args[0])


@add_cmd("log.level", admin=True, min_args=1)
def log_level(bot, event, irc, args):
    """<level>
    Changes the logging level"""
    try:
        log.setLevel(log.getattr(args[0].upper()))
        irc.reply(event, "Set log level to {0}".format(args[0]))
    except AttributeError:
        irc.reply(event, "Invalid log level {0}".format(args))


@add_cmd("config", admin=True, min_args=1, alias=['cfg'])
def config_cmd(bot, event, irc, args):
    """<nick>
    Changes or displays a config variable"""
    if len(args) > 1:
        if hasattr(config, args[0]):
            try:
                value = literal_eval(args[1])
            except Exception:
                value = args[1]
            setattr(config, args[0], value)
            irc.reply(event, "Set config.{0} to {1}".format(args[0], args[1]))
        else:
            irc.reply(event, "Invalid config variable {}".format(args[0]))
    else:
        if hasattr(config, args[0]):
            if args[0] == 'password' and event.target.startswith('#'):
                irc.reply(event, config.secretEntry)
            else:
                irc.reply(event, repr(getattr(config, args[0])))
        else:
            irc.reply(event, "Invalid config variable {}".format(args[0]))

<commit_msg>Fix log.level<commit_after>from ast import literal_eval
import os
import time

from zirc.util import repl
import config
import log
from utils.util import add_cmd
import utils


@add_cmd("eval", alias=['py', '>>'], min_args=1, owner=True, hide=True)
def eval_cmd(bot, event, irc, args):
    """Admin console"""
    console = repl.Repl({'self': bot, 'bot': bot, 'irc': irc, 'event': event})
    try:
        output = console.run(" ".join(args)).splitlines()
        for line in output:
            if len(line):
                irc.reply(event, line)

    except Exception as e:
        irc.reply(event, "{0}: {1}".format(e.__class__.__name__, e.args[0]))
        utils.util.print_error(irc, event)


@add_cmd("nick", owner=True, min_args=1)
def nick(bot, event, irc, args):
    """<nick>
    Changes the bot's nickname"""
    bot.config['nickname'] = args[0]
    irc.nick(args[0])


@add_cmd("log.level", admin=True, min_args=1)
def log_level(bot, event, irc, args):
    """<level>
    Changes the logging level"""
    try:
        log.setLevel(getattr(log, args[0].upper()))
        irc.reply(event, "Set log level to {0}".format(args[0]))
    except AttributeError:
        irc.reply(event, "Invalid log level {0}".format(args))


@add_cmd("config", admin=True, min_args=1, alias=['cfg'])
def config_cmd(bot, event, irc, args):
    """<nick>
    Changes or displays a config variable"""
    if len(args) > 1:
        if hasattr(config, args[0]):
            try:
                value = literal_eval(args[1])
            except Exception:
                value = args[1]
            setattr(config, args[0], value)
            irc.reply(event, "Set config.{0} to {1}".format(args[0], args[1]))
        else:
            irc.reply(event, "Invalid config variable {}".format(args[0]))
    else:
        if hasattr(config, args[0]):
            if args[0] == 'password' and event.target.startswith('#'):
                irc.reply(event, config.secretEntry)
            else:
                irc.reply(event, repr(getattr(config, args[0])))
        else:
            irc.reply(event, "Invalid config variable {}".format(args[0]))


{'fraction_non_alphanumeric': 0.16239717978848414, 'fraction_numerical': 0.012690951821386603, 'mean_word_length': 2.7300613496932513, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '1599145', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1378, 'n_words': 350}