<commit_before><?php

require_once("settings.php");

// *** DISALLOWS DIRECT ACCESS OF SOME FILES, DETERS HACKERS *** //
if(!defined("IN_STORYBOT")) {
	die("Invalid access!");
}
// *** ----------------------------------------------------- *** //

// *** FIRST TIME RUNNING? DIRECT TO INSTALL DIR *** //
if(($config['firstsetup'] == true) && (!defined("IN_INSTALL"))) {
	header("Location: install/");
}
// *** ----------------------------------------- *** //

// *** DISABLED? *** //
if(!defined("IN_INSTALL")) {
	$db = new mysqli($config['dbhost'], $config['dbuser'], $config['dbpass'], $config['dbname']); //do not edit
	if(($config['enabled'] == "false") && (!is_admin(mod_id(), $db))) {
		die("Storybot is disabled for non-admin use at the moment!");
	}
}
// *** --------- *** //

if(defined("IN_INSTALL")) {
	require_once("../src/snapchat.php"); //required for Snapchat API
	if(file_exists("lock.true")) {
		$db = new mysqli($config['dbhost'], $config['dbuser'], $config['dbpass'], $config['dbname']); //do not edit
		addModerator(mod_id(), $db);
		die("<h1>Storybot is successfully installed!</h1>You should delete the /install/ directory for security purposes. You can now visit the root directory and begin to moderate Storybot if you selected moderation=true, or if you didn't, you should now set up a Cron job for bot.php on some interval. Enjoy! If you have any questions, please contact <a href='http://www.reddit.com/u/bicycle'>/u/bicycle</a> on Reddit or visit <a href='http://www.reddit.com/r/storybot'>/r/storybot</a>.");
	}
} else {
	require_once("src/snapchat.php"); //required for Snapchat API
}

//***************************************************************************************************
//VARIABLES
//***************************************************************************************************

// *** CONNECT TO DATABASE *** //
if($config['firstsetup'] != true) {
	$db = new mysqli($config['dbhost'], $config['dbuser'], $config['dbpass'], $config['dbname']); //do not edit
	if($db->connect_errno > 0){
	    die("Database connection error: ".$db->connect_error);
	}
}
// *** ------------------- *** //

// *** INITIALIZE SNAPCHAT *** //
$snapchat = new Snapchat($config['username'], $config['gusername'], $config['gpassword'], $debug);
$snapchat->login($config['password']);
// *** ------------------- *** //

//***************************************************************************************************
//FUNCTIONS
//***************************************************************************************************

// *** CHECK FOR BANNED SNAPCHAT USER *** //
function is_banned($username) {
	$sql = "SELECT * FROM `bans` WHERE `bans`.`username` = '".$username."'";
	if(!$result = $GLOBALS['db']->query($sql)){
	    die("Database error! (is_banned)");
	}
	while($row = $result->fetch_assoc()){
		if($row['username'] != "") {
			return true;
		} else {
			return false;
		}
	}
}
// *** ------------------------------ *** //

// *** CHECK IF USER IS MOD *** //
function is_mod($id) {
	$sql = "SELECT * FROM `mods` WHERE `mods`.`mod_id` = '".$id."'";
	if(!$result = $GLOBALS['db']->query($sql)){<commit_msg>don't init snapchat inside install<commit_after><?php

require_once("settings.php");

// *** DISALLOWS DIRECT ACCESS OF SOME FILES, DETERS HACKERS *** //
if(!defined("IN_STORYBOT")) {
	die("Invalid access!");
}
// *** ----------------------------------------------------- *** //

// *** FIRST TIME RUNNING? DIRECT TO INSTALL DIR *** //
if(($config['firstsetup'] == true) && (!defined("IN_INSTALL"))) {
	header("Location: install/");
}
// *** ----------------------------------------- *** //

// *** DISABLED? *** //
if(!defined("IN_INSTALL")) {
	$db = new mysqli($config['dbhost'], $config['dbuser'], $config['dbpass'], $config['dbname']); //do not edit
	if(($config['enabled'] == "false") && (!is_admin(mod_id(), $db))) {
		die("Storybot is disabled for non-admin use at the moment!");
	}
}
// *** --------- *** //

if(defined("IN_INSTALL")) {
	require_once("../src/snapchat.php"); //required for Snapchat API
	if(file_exists("lock.true")) {
		$db = new mysqli($config['dbhost'], $config['dbuser'], $config['dbpass'], $config['dbname']); //do not edit
		addModerator(mod_id(), $db);
		die("<h1>Storybot is successfully installed!</h1>You should delete the /install/ directory for security purposes. You can now visit the root directory and begin to moderate Storybot if you selected moderation=true, or if you didn't, you should now set up a Cron job for bot.php on some interval. Enjoy! If you have any questions, please contact <a href='http://www.reddit.com/u/bicycle'>/u/bicycle</a> on Reddit or visit <a href='http://www.reddit.com/r/storybot'>/r/storybot</a>.");
	}
} else {
	require_once("src/snapchat.php"); //required for Snapchat API
}

//***************************************************************************************************
//VARIABLES
//***************************************************************************************************

// *** CONNECT TO DATABASE *** //
if($config['firstsetup'] != true) {
	$db = new mysqli($config['dbhost'], $config['dbuser'], $config['dbpass'], $config['dbname']); //do not edit
	if($db->connect_errno > 0){
	    die("Database connection error: ".$db->connect_error);
	}
}
// *** ------------------- *** //

// *** INITIALIZE SNAPCHAT *** //
if(!$config['firstsetup']) {
	$snapchat = new Snapchat($config['username'], $config['gusername'], $config['gpassword'], $debug);
	$snapchat->login($config['password']);
}
// *** ------------------- *** //

//***************************************************************************************************
//FUNCTIONS
//***************************************************************************************************

// *** CHECK FOR BANNED SNAPCHAT USER *** //
function is_banned($username) {
	$sql = "SELECT * FROM `bans` WHERE `bans`.`username` = '".$username."'";
	if(!$result = $GLOBALS['db']->query($sql)){
	    die("Database error! (is_banned)");
	}
	while($row = $result->fetch_assoc()){
		if($row['username'] != "") {
			return true;
		} else {
			return false;
		}
	}
}
// *** ------------------------------ *** //

// *** CHECK IF USER IS MOD *** //
function is_mod($id) {
	$sql = "SELECT * FROM `mods` WHERE `mods`.`mod_id` = '".$id."'";
	if(!$result = $GLOBALS['db']->query($sql)){
{'fraction_non_alphanumeric': 0.375, 'fraction_numerical': 0.0009433962264150943, 'mean_word_length': 3.711851851851852, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2709571', 'n_tokens_mistral': 1940, 'n_tokens_neox': 1834, 'n_words': 420}