<commit_before>import json
import logging

from flask_restful import reqparse
from flask_restful import Resource
from sqlalchemy.orm import joinedload

import pajbot.modules
import pajbot.utils
import pajbot.web.utils
from pajbot.managers.adminlog import AdminLogManager
from pajbot.managers.db import DBManager
from pajbot.models.command import Command
from pajbot.models.command import CommandData
from pajbot.models.module import ModuleManager
from pajbot.models.sock import SocketClientManager
from pajbot.utils import find

log = logging.getLogger(__name__)


class APICommands(Resource):
    def get(self):
        commands = pajbot.web.utils.get_cached_commands()

        return {
                'commands': commands
                }, 200


class APICommand(Resource):
    def get(self, raw_command_id):
        command_string = raw_command_id
        command_id = None

        try:
            command_id = int(command_string)
        except (ValueError, TypeError):
            pass

        if command_id:
            command = find(lambda c: c['id'] == command_id, pajbot.web.utils.get_cached_commands())
        else:
            command = find(lambda c: c['resolve_string'] == command_string, pajbot.web.utils.get_cached_commands())

        if not command:<commit_msg>filter out any non-database-sourced commands from the commands list<commit_after>import json
import logging

from flask_restful import reqparse
from flask_restful import Resource
from sqlalchemy.orm import joinedload

import pajbot.modules
import pajbot.utils
import pajbot.web.utils
from pajbot.managers.adminlog import AdminLogManager
from pajbot.managers.db import DBManager
from pajbot.models.command import Command
from pajbot.models.command import CommandData
from pajbot.models.module import ModuleManager
from pajbot.models.sock import SocketClientManager
from pajbot.utils import find

log = logging.getLogger(__name__)


class APICommands(Resource):
    def get(self):
        commands = pajbot.web.utils.get_cached_commands()

        commands = list(filter(lambda c: c['id'] is not None, commands))

        return {
                'commands': commands
                }, 200


class APICommand(Resource):
    def get(self, raw_command_id):
        command_string = raw_command_id
        command_id = None

        try:
            command_id = int(command_string)
        except (ValueError, TypeError):
            pass

        if command_id:
            command = find(lambda c: c['id'] == command_id, pajbot.web.utils.get_cached_commands())
        else:
            command = find(lambda c: c['resolve_string'] == command_string, pajbot.web.utils.get_cached_commands())

        if not command:
{'fraction_non_alphanumeric': 0.07518518518518519, 'fraction_numerical': 0.0022222222222222222, 'mean_word_length': 3.2269170579029733, 'pattern_counts': {'":': 0, '<': 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': '1665925', 'n_tokens_mistral': 785, 'n_tokens_neox': 764, 'n_words': 207}