<commit_before><?php

require('../vendor/autoload.php');

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Guzzle\Http\Client;


$app = new Silex\Application();

$app['debug'] = true;

// Register the postgres service
$dbopts = parse_url(getenv('DATABASE_URL'));
$app->register(new Herrera\Pdo\PdoServiceProvider(),
  array(
    'pdo.dsn' => 'pgsql:dbname='.ltrim($dbopts["path"],'/').';host='.$dbopts["host"],
    'pdo.port' => $dbopts["port"],
    'pdo.username' => $dbopts["user"],
    'pdo.password' => $dbo<PASSWORD>["<PASSWORD>"]
  )
);

// Register the monolog logging service
$app->register(new Silex\Provider\MonologServiceProvider(), array(
  'monolog.logfile' => 'php://stderr',
));

function request($app,$slackUser,$text) 
{
	$returnArray = array("text" => "");

  	$app['monolog']->addDebug('REQUEST routine: ' . $text );

	if (strpos($text,"by") === false)
	{
		$returnArray['text'] = $slackUser . ', requests need to be of the form SONG by ARTIST. Try again.';
	} else
	{
		// write the command to the DB
		$status = writeToDB($app,$slackUser,"request",$text);
		if ($status)
		{
			$returnArray['text'] = 'OK, ' . $slackUser . ' I\'ve submitted your request for ' . $text . ' to the music controller';
		} else
		{
			$returnArray['text'] = 'I\'m sorry ' . $slackUser . ', I was unable to submit your request for ' . $text . ' to the music controller';
		}
	}

	$returnJSON = json_encode($returnArray);	

  	$app['monolog']->addDebug('REQUEST routine returning: ' . $returnJSON );

	return $returnJSON;
}

function play($app,$slackUser,$text) 
{
	$returnArray = array("text" => "");

  	$app['monolog']->addDebug('PLAY routine: ' . $text );
	//echo "PLAY routine " . $text . "\n";

	// write the command to the DB
	$status = writeToDB($app,$slackUser,"play","");
	if ($status)
	{
		$returnArray['text'] = 'OK, ' . $slackUser . ' I\'ve asked the music controller to play some funky beats';
	} else
	{
		$returnArray['text'] = 'I\'m sorry ' . $slackUser . ', I was unable to ask the music controller to play some funky beats';
	}

	$returnJSON = json_encode($returnArray);	

  	$app['monolog']->addDebug('PLAY routine returning: ' . $returnJSON );

	return $returnJSON;
}

function skip($app,$slackUser,$text) 
{
	$returnArray = array("text" => "");

  	$app['monolog']->addDebug('SKIP routine: ' . $text );
	//echo "NEXT routine " . $text . "\n";

	// write the command to the DB
	$status = writeToDB($app,$slackUser,"next","");
	if ($status)
	{
		$returnArray['text'] = 'OK, ' . $slackUser . ' I\'ve asked the music controller to skip to the next track';
	} else
	{
		$returnArray['text'] = 'I\'m sorry ' . $slackUser . ', I was unable to ask the music controller to skip to the next track';
	}

	$returnJSON = json_encode($returnArray);	

  	$app['monolog']->addDebug('SKIP routine returning: ' . $returnJSON );

	return $returnJSON;
}

function stop($app,$slackUser,$text) 
{
	$returnArray = array("text" => "");

  	$app['monolog']->addDebug('STOP routine: ' . $text );

	// write the command to the DB
	$status = writeToDB($app,$slackUser,"stop","");
	if ($status)
	{
		$returnArray['text'] = 'OK, ' . $slackUser . ' I\'ve asked the music controller to stop the beats';
	} else
	{
		$returnArray['text'] = 'I\'m sorry ' . $slackUser . ', I was unable to ask the music controller to stop the beats';
	}

	$returnJSON = json_encode($returnArray);	

  	$app['monolog']->addDebug('PAUSE routine returning: ' . $returnJSON );

	return $returnJSON;
}

function nowplaying($app,$slackUser,$text) 
{
	$returnArray = array("text" => "");

  	$app['monolog']->addDebug('NOWPLAYING routine: ' . $text );

	// write the command to the DB
	$status = writeToDB($app,$slackUser,"nowplaying","");
	if ($status)
	{
		$returnArray['text'] = 'OK, ' . $slackUser . ' I\'ve asked the music controller to report back what is playing';
	} else
	{
		$returnArray['text'] = 'I\'m sorry ' . $slackUser . ', I was unable to ask the music controller what is playing';
	}

	$returnJSON = json_encode($returnArray);	

  	$app['monolog']->addDebug('NOWPLAYING routine returning: ' . $returnJSON );

	return $returnJSON;
}

function help($app,$slackUser,$text)
{
	$returnArray = array("text" => "");

  	$app['monolog']->addDebug('HELP routine: ' . $text );

	$helpText = 'You can ask me the following:\n';
	$helpText = $helpText . '*play* - play whatever is queued up\n';
	$helpText = $helpText . '*stop* - stop the funky beats\n';
	$helpText = $helpText . '*next* - skip to the next track\n';<commit_msg>change next to skip<commit_after><?php

require('../vendor/autoload.php');

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Guzzle\Http\Client;


$app = new Silex\Application();

$app['debug'] = true;

// Register the postgres service
$dbopts = parse_url(getenv('DATABASE_URL'));
$app->register(new Herrera\Pdo\PdoServiceProvider(),
  array(
    'pdo.dsn' => 'pgsql:dbname='.ltrim($dbopts["path"],'/').';host='.$dbopts["host"],
    'pdo.port' => $dbopts["port"],
    'pdo.username' => $dbopts["user"],
    'pdo.password' => $dbopts["pass"]
  )
);

// Register the monolog logging service
$app->register(new Silex\Provider\MonologServiceProvider(), array(
  'monolog.logfile' => 'php://stderr',
));

function request($app,$slackUser,$text) 
{
	$returnArray = array("text" => "");

  	$app['monolog']->addDebug('REQUEST routine: ' . $text );

	if (strpos($text,"by") === false)
	{
		$returnArray['text'] = $slackUser . ', requests need to be of the form SONG by ARTIST. Try again.';
	} else
	{
		// write the command to the DB
		$status = writeToDB($app,$slackUser,"request",$text);
		if ($status)
		{
			$returnArray['text'] = 'OK, ' . $slackUser . ' I\'ve submitted your request for ' . $text . ' to the music controller';
		} else
		{
			$returnArray['text'] = 'I\'m sorry ' . $slackUser . ', I was unable to submit your request for ' . $text . ' to the music controller';
		}
	}

	$returnJSON = json_encode($returnArray);	

  	$app['monolog']->addDebug('REQUEST routine returning: ' . $returnJSON );

	return $returnJSON;
}

function play($app,$slackUser,$text) 
{
	$returnArray = array("text" => "");

  	$app['monolog']->addDebug('PLAY routine: ' . $text );
	//echo "PLAY routine " . $text . "\n";

	// write the command to the DB
	$status = writeToDB($app,$slackUser,"play","");
	if ($status)
	{
		$returnArray['text'] = 'OK, ' . $slackUser . ' I\'ve asked the music controller to play some funky beats';
	} else
	{
		$returnArray['text'] = 'I\'m sorry ' . $slackUser . ', I was unable to ask the music controller to play some funky beats';
	}

	$returnJSON = json_encode($returnArray);	

  	$app['monolog']->addDebug('PLAY routine returning: ' . $returnJSON );

	return $returnJSON;
}

function skip($app,$slackUser,$text) 
{
	$returnArray = array("text" => "");

  	$app['monolog']->addDebug('SKIP routine: ' . $text );
	//echo "NEXT routine " . $text . "\n";

	// write the command to the DB
	$status = writeToDB($app,$slackUser,"next","");
	if ($status)
	{
		$returnArray['text'] = 'OK, ' . $slackUser . ' I\'ve asked the music controller to skip to the next track';
	} else
	{
		$returnArray['text'] = 'I\'m sorry ' . $slackUser . ', I was unable to ask the music controller to skip to the next track';
	}

	$returnJSON = json_encode($returnArray);	

  	$app['monolog']->addDebug('SKIP routine returning: ' . $returnJSON );

	return $returnJSON;
}

function stop($app,$slackUser,$text) 
{
	$returnArray = array("text" => "");

  	$app['monolog']->addDebug('STOP routine: ' . $text );

	// write the command to the DB
	$status = writeToDB($app,$slackUser,"stop","");
	if ($status)
	{
		$returnArray['text'] = 'OK, ' . $slackUser . ' I\'ve asked the music controller to stop the beats';
	} else
	{
		$returnArray['text'] = 'I\'m sorry ' . $slackUser . ', I was unable to ask the music controller to stop the beats';
	}

	$returnJSON = json_encode($returnArray);	

  	$app['monolog']->addDebug('PAUSE routine returning: ' . $returnJSON );

	return $returnJSON;
}

function nowplaying($app,$slackUser,$text) 
{
	$returnArray = array("text" => "");

  	$app['monolog']->addDebug('NOWPLAYING routine: ' . $text );

	// write the command to the DB
	$status = writeToDB($app,$slackUser,"nowplaying","");
	if ($status)
	{
		$returnArray['text'] = 'OK, ' . $slackUser . ' I\'ve asked the music controller to report back what is playing';
	} else
	{
		$returnArray['text'] = 'I\'m sorry ' . $slackUser . ', I was unable to ask the music controller what is playing';
	}

	$returnJSON = json_encode($returnArray);	

  	$app['monolog']->addDebug('NOWPLAYING routine returning: ' . $returnJSON );

	return $returnJSON;
}

function help($app,$slackUser,$text)
{
	$returnArray = array("text" => "");

  	$app['monolog']->addDebug('HELP routine: ' . $text );

	$helpText = 'You can ask me the following:\n';
	$helpText = $helpText . '*play* - play whatever is queued up\n';
	$helpText = $helpText . '*stop* - stop the funky beats\n';
	$helpText = $helpText . '*skip* - skip to the next track\n';
{'fraction_non_alphanumeric': 0.1891803635572004, 'fraction_numerical': 0.0, 'mean_word_length': 4.081858407079646, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 53, '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': '1492149', 'n_tokens_mistral': 3271, 'n_tokens_neox': 3158, 'n_words': 774}