<commit_before>"""
Staff commands.
"""
from src.server.commands.command import BaseCommand

class CmdRestart(BaseCommand):
    """
    Shuts the MUD server down silently. Supervisor restarts it after noticing
    the exit, and most users will never notice since the proxy maintains
    their connections.
    """
    name = '@restart'

    def func(self, invoker, parsed_cmd):
        invoker.emit_to("Restarting...")
        mud_service = invoker._mud_service
        mud_service.shutdown()


class CmdFind(BaseCommand):
    """
    Does a fuzzy name match for all objects in the DB. Useful for finding
    various objects.
    """
    name = '@find'

    def func(self, invoker, parsed_cmd):
        mud_service = invoker._mud_service

        search_str = ' '.join(parsed_cmd.arguments)

        if search_str.strip() == '':
            invoker.emit_to('@find requires a name to search for.')
            return

        invoker.emit_to("\nSearching for: %s" % search_str)

        # Performs a global fuzzy name match. Returns a generator.
        matches = mud_service.object_store.global_name_search(search_str)

        # Buffer for returning everything at once.
        retval = ''
        match_counter = 0
        for match in matches:
            retval += '\n  #%s %s %s' % (
                match.id.ljust(6),
                match.base_type.ljust(8),
                match.name[:80]
            )
            match_counter += 1
        # Send the results in one burst.
        invoker.emit_to(retval)
        invoker.emit_to('\nMatches found: %d' % match_counter)


class CmdDig(BaseCommand):
    """
    Digs a new room.
    """
    name = '@dig'

    def func(self, invoker, parsed_cmd):
        mud_service = invoker._mud_service

        name_str = ' '.join(parsed_cmd.arguments)

        if name_str.strip() == '':
            invoker.emit_to('@dig requires a name for the new room.')
            return

        room_parent = 'src.game.parents.base_objects.room.RoomObject'
        new_room = mud_service.object_store.create_object(
            room_parent,
            name=name_str,
        )
        invoker.emit_to('You have dug a new room: %s(%s)' % (
            new_room.name,
            new_room.id,
        ))

class CmdTeleport(BaseCommand):
    """
    Moves an object from one place to another
    """

    name = '@teleport'

    def func(self, invoker, parsed_cmd):
        mud_service = invoker._mud_service

        object = parsed_cmd.arguments[0]
        dest = parsed_cmd.arguments[1]

        invoker.emit_to('@teleporting: "%s" to "%s"' % (object,dest))

        if not object:
            invoker.emit_to('@teleport error: You must specify an object to teleport')

        if not dest:
            invoker.emit_to('@teleport error: You must specify a destination')

        if object.strip().lower() == 'me':
            object = invoker
        else:
            try:
                object = int(object)
            except ValueError:
                invoker.emit_to('@teleport error: Objects must be referenced by dbref')

            object = mud_service.object_store.get_object(object)
            if not object:
                invoker.emit_to('@teleport error: Invalid object')

        if dest.strip().lower() == 'me':
            dest = invoker.get_location()
        else:
            try:
                dest = int(dest)
            except ValueError:
                invoker.emit_to('@teleport error: Destinations must be referenced by dbref')

            dest = mud_service.object_store.get_object(dest)
            if not dest:
                invoker.emit_to('@teleport error: Invalid destination')

        object.set_location(dest)
        object.save()<commit_msg>Modified @teleport to use contextual_object_search<commit_after>"""
Staff commands.
"""
from src.server.commands.command import BaseCommand

class CmdRestart(BaseCommand):
    """
    Shuts the MUD server down silently. Supervisor restarts it after noticing
    the exit, and most users will never notice since the proxy maintains
    their connections.
    """
    name = '@restart'

    def func(self, invoker, parsed_cmd):
        invoker.emit_to("Restarting...")
        mud_service = invoker._mud_service
        mud_service.shutdown()


class CmdFind(BaseCommand):
    """
    Does a fuzzy name match for all objects in the DB. Useful for finding
    various objects.
    """
    name = '@find'

    def func(self, invoker, parsed_cmd):
        mud_service = invoker._mud_service

        search_str = ' '.join(parsed_cmd.arguments)

        if search_str.strip() == '':
            invoker.emit_to('@find requires a name to search for.')
            return

        invoker.emit_to("\nSearching for: %s" % search_str)

        # Performs a global fuzzy name match. Returns a generator.
        matches = mud_service.object_store.global_name_search(search_str)

        # Buffer for returning everything at once.
        retval = ''
        match_counter = 0
        for match in matches:
            retval += '\n  #%s %s %s' % (
                match.id.ljust(6),
                match.base_type.ljust(8),
                match.name[:80]
            )
            match_counter += 1
        # Send the results in one burst.
        invoker.emit_to(retval)
        invoker.emit_to('\nMatches found: %d' % match_counter)


class CmdDig(BaseCommand):
    """
    Digs a new room.
    """
    name = '@dig'

    def func(self, invoker, parsed_cmd):
        mud_service = invoker._mud_service

        name_str = ' '.join(parsed_cmd.arguments)

        if name_str.strip() == '':
            invoker.emit_to('@dig requires a name for the new room.')
            return

        room_parent = 'src.game.parents.base_objects.room.RoomObject'
        new_room = mud_service.object_store.create_object(
            room_parent,
            name=name_str,
        )
        invoker.emit_to('You have dug a new room: %s(%s)' % (
            new_room.name,
            new_room.id,
        ))

class CmdTeleport(BaseCommand):
    """
    Moves an object from one place to another
    """

    name = '@teleport'

    def func(self, invoker, parsed_cmd):

        object = parsed_cmd.arguments[0]
        dest = parsed_cmd.arguments[1]

        invoker.emit_to('@teleporting: "%s" to "%s"' % (object,dest))

        if not object:
            invoker.emit_to('@teleport error: You must specify an object to teleport')

        if not dest:
            invoker.emit_to('@teleport error: You must specify a destination')

        object = invoker.contextual_object_search(object)
        if not object:
            invoker.emit_to('@teleport error: Invalid object')

        dest = invoker.contextual_object_search(dest)
        if not dest:
            invoker.emit_to('@teleport error: Invalid destination')
        if dest.base_type == 'player':
            dest = dest.get_location()

        object.set_location(dest)
{'fraction_non_alphanumeric': 0.1021319504465572, 'fraction_numerical': 0.0023048112935753384, 'mean_word_length': 2.0954079358002673, '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': '3798680', 'n_tokens_mistral': 2080, 'n_tokens_neox': 1998, 'n_words': 527}