<commit_before>import json


class Database(dict):
    """Holds a dict that contains all the information
    about the users and their last seen actions in a channel"""
    def __init__(self, irc):
        super(Database, self).__init__(json.load(open("userdb.json")))
        self.irc = irc

    def change_attr(self, name, attr, value, channel=None):
        if channel is not None:
            self[channel][name][attr] = value
        for i in self:
            try:
                if attr == "host":
                    nick_ident = self[i][name]["hostmask"].split("@")[0]
                    self[i][name]["hostmask"] = nick_indent + value
                self[i][name][attr] = value
            except KeyError:
                pass

    def remove_entry(self, event, nick):
        try:
            del self[event.target][nick]
        except KeyError:
            for i in self[event.target].values():
                if i['host'] == event.source.host:
                    del self[event.target][i['hostmask'].split("!")[0]]
                    break

    def add_entry(self, channel, nick, hostmask, account):
        temp = {
            'hostmask': hostmask,
            'host': hostmask.split("@")[1],
            'account': account,
            'seen': None
        }
        if nick in self[channel]:
            del temp['seen']
            self[channel][nick].update(temp)
        else:
            self[channel][nick] = temp

    def get_user_host(self, channel, nick):
        try:
            host = "*!*@" + self[channel][nick]['host']
        except KeyError:
            self.irc.send("WHO {0} nuhs%nhuac".format(channel))<commit_msg>Fix the database change_attr function with CHGHOST<commit_after>import json


class Database(dict):
    """Holds a dict that contains all the information
    about the users and their last seen actions in a channel"""
    def __init__(self, irc):
        super(Database, self).__init__(json.load(open("userdb.json")))
        self.irc = irc

    def change_attr(self, name, attr, value, channel=None):
        if channel is not None:
            self[channel][name][attr] = value
        for i in self:
            try:
                if attr == "host":
                    nick_ident = self[i][name]["hostmask"].split("@")[0]
                    self[i][name]["hostmask"] = nick_indent + '@' + value
                    self[i][name][attr] = value
                elif attr == "ident":
                    self[i]["hostmask"] = name + '!' + value
                else:
                    self[i][name][attr] = value
            except KeyError:
                pass

    def remove_entry(self, event, nick):
        try:
            del self[event.target][nick]
        except KeyError:
            for i in self[event.target].values():
                if i['host'] == event.source.host:
                    del self[event.target][i['hostmask'].split("!")[0]]
                    break

    def add_entry(self, channel, nick, hostmask, account):
        temp = {
            'hostmask': hostmask,
            'host': hostmask.split("@")[1],
            'account': account,
            'seen': None
        }
        if nick in self[channel]:
            del temp['seen']
            self[channel][nick].update(temp)
        else:
            self[channel][nick] = temp

    def get_user_host(self, channel, nick):
        try:
            host = "*!*@" + self[channel][nick]['host']
        except KeyError:
            self.irc.send("WHO {0} nuhs%nhuac".format(channel))
{'fraction_non_alphanumeric': 0.13448471121177802, 'fraction_numerical': 0.0022650056625141564, 'mean_word_length': 1.76015625, 'pattern_counts': {'":': 3, '<': 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': '2530870', 'n_tokens_mistral': 1011, 'n_tokens_neox': 974, 'n_words': 248}