<commit_before>import json
from twisted.plugin import IPlugin
from typing import Union
from zope.interface import implementer

from desertbot.message import IRCMessage
from desertbot.moduleinterface import IModule
from desertbot.modules.commandinterface import admin, BotCommand
from desertbot.response import IRCResponse, ResponseType

from desertbot.utils.api_keys import path as api_key_path


@implementer(IPlugin, IModule)
class APIKeys(BotCommand):
    def triggers(self):
        return ["apikey"]

    def onLoad(self):
        with open(api_key_path) as f:
            self.keys = json.load(f.read())

    def saveKeys(self):
        with open(api_key_path, "w") as f:
            json.dump(self.keys, f)

    def actions(self):
        return super(APIKeys, self).actions() + [("apikeys-getkey", 1, self.getKey)]

    def help(self, query):
        return f"{self.bot.commandChar}apikey add/remove <name> <apikey> -- Add or remove the specified API key to the bot."

    @admin("[APIKey] Only my admins may manage API keys!")
    def execute(self, message: IRCMessage):
        if len(message.parameterList) < 3:
            return self.help(None)
        command = message.parameterList[0].lower()
        key = message.parameterList.pop()
        keyname = " ".join(message.parameterList[1:])<commit_msg>Right, json.load() takes an fp, not a string.<commit_after>import json
from twisted.plugin import IPlugin
from typing import Union
from zope.interface import implementer

from desertbot.message import IRCMessage
from desertbot.moduleinterface import IModule
from desertbot.modules.commandinterface import admin, BotCommand
from desertbot.response import IRCResponse, ResponseType

from desertbot.utils.api_keys import path as api_key_path


@implementer(IPlugin, IModule)
class APIKeys(BotCommand):
    def triggers(self):
        return ["apikey"]

    def onLoad(self):
        with open(api_key_path) as f:
            self.keys = json.load(f)

    def saveKeys(self):
        with open(api_key_path, "w") as f:
            json.dump(self.keys, f)

    def actions(self):
        return super(APIKeys, self).actions() + [("apikeys-getkey", 1, self.getKey)]

    def help(self, query):
        return f"{self.bot.commandChar}apikey add/remove <name> <apikey> -- Add or remove the specified API key to the bot."

    @admin("[APIKey] Only my admins may manage API keys!")
    def execute(self, message: IRCMessage):
        if len(message.parameterList) < 3:
            return self.help(None)
        command = message.parameterList[0].lower()
        key = message.parameterList.pop()
        keyname = " ".join(message.parameterList[1:])
{'fraction_non_alphanumeric': 0.10425291682348513, 'fraction_numerical': 0.0030109145652992097, 'mean_word_length': 3.4373956594323873, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '4922595', 'n_tokens_mistral': 791, 'n_tokens_neox': 784, 'n_words': 230}