<commit_before>#
# MUES::CommandShell environment manipulation commands.
# $Id: environments.cmd,v 1.1 2002/09/05 04:07:11 deveiant Exp $
#
# == Authors:
# * <NAME> <<EMAIL>>
#

### Load environment
= loadenv

== Restriction

admin

== Usage

  loadenv <class> [as] <name>
  loadenv <name>

== Abstract

Create and/or load a environment object and make it available.

== Description

If specified with a class argument, creates a new environment of the specified
class and associates it with the specified name. If there is already an
environment associated with the given name, either in memory or in the Engine's
objectstore, this results in an error.

If specified with only a name, attempt to load the environment from the Engine's
objectstore. If no such environment exists in the objectstore, this results in
an error.

== Code

	if args =~ %r{(\w+)\s+(?:as\s+)?(\w+)}
		return OutputEvent.new( usage() )
	end

	return [ OutputEvent.new( "Attempting to load the '#{$1}' environment as '#{$2}'\n" ),
		LoadEnvironmentEvent.new( $2, $1, context.user ) ]


### Unload environment
= unloadenv

== Abstract

Shut down and unload a loaded environment object.

== Description

This command causes the server to unload a running environment after shutting it
down and disconnecting all participants.

== Usage

  unloadenv <environment name>

== Restriction

admin

== Code

  unless args =~ %r{(\w+)}
	  return OutputEvent.new( usage() )
  end

  return UnloadEnvironmentEvent.new( $1, context.user )


### List environments
= envlist

== Abstract
List known environment classes which may be loaded.

== Description
This command outputs a list of all available environment classes which may be
instantiated and run in the server.

== Restriction
admin

== Usage
  envlist

== Code
  output = "\nAvailable MUES Environment classes:\n\t"
  list = MUES::Environment.listEnvClasses
  if list.empty?
	  output << "(None)"
  else
	  output << list.join("\n\t")
  end
  output << "\n"

  return OutputEvent.new( output )<commit_msg>- Removed classless invocation of 'loadenv'.<commit_after>#
# MUES::CommandShell environment manipulation commands.
# $Id: environments.cmd,v 1.2 2002/09/12 12:53:28 deveiant Exp $
#
# == Authors:
# * <NAME> <<EMAIL>>
#

### Load environment
= loadenv

== Restriction

admin

== Usage

  loadenv <class> [as] <name>

== Abstract

Create and/or load a environment object and make it available.

== Description
Creates a new environment of the specified class and associates it with the
specified name. If there is already an environment associated with the given
name, an error occurs.

== Code

  results = []

  if argString =~ %r{(\w+)\s+(?:as\s+)?(\w+)}
	klass = $1
	name = $2

	results <<
		MUES::OutputEvent::new( "Attempting to load the '#{klass}' environment as '#{name}'\n" ) <<
		MUES::LoadEnvironmentEvent::new( name, klass, context.user )

  else
    results << MUES::OutputEvent::new( self.usage )
  end

  return results



### Unload environment
= unloadenv

== Abstract

Shut down and unload a loaded environment object.

== Description

This command causes the server to unload a running environment after shutting it
down and disconnecting all participants.

== Usage

  unloadenv <environment name>

== Restriction

admin

== Code

  unless argString =~ %r{(\w+)}
	  return MUES::OutputEvent::new( self.usage )
  end

  return [UnloadEnvironmentEvent.new( $1, context.user )]


### List environments
= envlist

== Abstract
List known environment classes which may be loaded.

== Description
This command outputs a list of all available environment classes which may be
instantiated and run in the server.

== Restriction
admin

== Usage
  envlist

== Code
  output = "\nAvailable MUES Environment classes:\n\t"
  list = MUES::Environment.listEnvClasses
  if list.empty?
	  output << "(None)"
  else
	  output << list.join("\n\t")
  end
  output << "\n"

  return [MUES::OutputEvent::new( output )]


### 'Connect' command
= connect

== Synonyms
play

== Abstract
Connect to the specified environment in the specified role.

== Usage
  connect [to] <environment> [as] <role>

== Code

  results = []
  if argString =~ %r{(?:\s*to\s*)?(\w+)\s+(?:as\s*)?(\w+)}
	  envName, roleName = $1, $2

	  ### Look for the requested role in the requested
	  ### environment, returning the new filter object if we find
	  ### it. Catch any problems as exceptions, and turn them into
	  ### error messages for output.
	  begin
		  env = MUES::ServerFunctions::getEnvironment( envName ) or
			  raise CommandError, "No such environment '#{envName}'."
		  role = env.getAvailableRoles( context.user ).find {|role|
			  role.name == roleName
		  }
		  raise CommandError, "Role '#{roleName}' is not currently available to you." unless
			  role.is_a?( MUES::Role )

		  results << OutputEvent.new( "Connecting..." )
		  results << env.getParticipantProxy( context.user, role )
		  results << OutputEvent.new( "connected.\n\n" )
	  rescue CommandError, SecurityViolation => e
		  results << OutputEvent.new( e.message )
	  end
  else
	  results << OutputEvent.new( usage() )
  end

  return results.flatten



### 'Disconnect' command
= disconnect

== Abstract
Disconnect from the specified role in the specified environment.

== Usage
  disconnect [<role> [in]] <environment>

== Code

  results = []
  roleName = nil
  envName = nil

  ### Parse the arguments, returning a usage message if we can't
  ### parse
  if argString =~ %r{(\w+)\s+(?:in\s*)?(\w+)}
	  roleName, envName = $1, $2
  elsif argString =~ %r{(\w+)}
	  envName = $1
  else
	  return [ MUES::OutputEvent.new( usage() ) ]
  end

  ### Look for a proxy from the specified environment
  begin
	  targetEnv = MUES::ServerFunctions::getEnvironment( envName ) or
		  raise CommandError, "No such environment '#{envName}'."
	  targetProxy = context.stream.findFiltersOfType( MUES::ParticipantProxy ).find {|f|
		  f.env == targetEnv && ( roleName.nil? || f.role.name == roleName )
	  } or raise CommandError, "Not connected to #{envName} #{roleName ? 'as ' + roleName : ''}"

	  results << OutputEvent.new( "Disconnecting from #{envName}..." )
	  targetEnv.removeParticipantProxy( targetProxy )
	  context.stream.removeFilters( targetProxy )
	  results << OutputEvent.new( " disconnected.\n\n" )
  rescue CommandError, SecurityViolation => e
	  results << OutputEvent.new( e.message )
  end

  return results.flatten


### 'Roles' command
= roles

== Abstract
List available roles in the specified environments.

== Usage
  roles [<environment names>]

== Code

  results = []
  envNames = []
  list = nil

  ### If they passed at least one environment name, parse them out
  ### of the line.
  if argString =~ %r{\w}
	  envNames = argString.scan(/\w+/)
  else
	  envNames = MUES::ServerFunctions::getEnvironmentNames
  end

  list = "\n"
  roleCount = 0
  envNames.each {|envName|

	  ### Look for the roles in the requested environment. Catch any
	  ### problems as exceptions, and turn them into error messages
	  ### for output.
	  begin
		  env = MUES::ServerFunctions::getEnvironment( envName ) or
			  raise CommandError, "No such environment '#{envName}'."
		  list << "%s (%s)\n" % [ envName, env.class.name ]
		  env.getAvailableRoles( context.user ).each {|role|
			  list << "    #{role.to_s}\n"
			  roleCount += 1
		  }
	  rescue CommandError, SecurityViolation => e
		  list << e.message + "\n"
	  end

	  list << "\n"
  }

  list << "(#{roleCount}) role/s currently available to you.\n\n"

  results << MUES::OutputEvent::new( list )
  return results.flatten



{'fraction_non_alphanumeric': 0.12630604417405106, 'fraction_numerical': 0.006216108980293612, 'mean_word_length': 3.667901234567901, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 24, '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': '5884409', 'n_tokens_mistral': 2473, 'n_tokens_neox': 2281, 'n_words': 793}