Skip to content

Commit

Permalink
Include vendor defined value if not defined
Browse files Browse the repository at this point in the history
Remove excess includes; Vendor-ready

x2

Dropped a \

Fix typo with in-line documentation

More vendor readiness

x2

x3

Whoops
  • Loading branch information
valzargaming committed Aug 23, 2021
1 parent 6ca9f87 commit 193ee80
Show file tree
Hide file tree
Showing 26 changed files with 42 additions and 60 deletions.
2 changes: 0 additions & 2 deletions channel_roles.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
include_once 'custom_functions.php';

$channelroles = array(
"Anime" => "πŸ“Ί",
"Art" => "πŸ–ŒοΈ",
Expand Down
2 changes: 1 addition & 1 deletion config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//Variables need to be reinitialized within the event listener by using the GLOBAL keyword (e.g. GLOBAL $bot_id;)

$server_invite = "https://discord.com/oauth2/authorize?client_id=662093882795753482&scope=bot&permissions=8"; //Invite link to add this bot to the server
$bot_id = "662093882795753482"; //id of this bot (change it to match your bot if not using Palace Bo#9203)
$bot_id = "662093882795753482"; //id of this bot (change it to match your bot if not using Palace Bot#9203)

//These are default options that should be set up before the bot is started for the first time. Any future changes need to be done with a chat command
$react_option = true;
Expand Down
4 changes: 2 additions & 2 deletions constants.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
$BASE_DIR = __DIR__ . "/../";
$DIR = __DIR__ . "\\";
$BASE_DIR = getcwd() . "/../";
$DIR = getcwd() . "\\";
$now = new DateTime();
16 changes: 8 additions & 8 deletions custom_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function CheckDir($foldername)
{
//echo "CheckDir" . PHP_EOL;
include("constants.php");
$path = $DIR.$foldername."/";
$path = getcwd().$foldername."/";
$exist = false;
//Create folder if it doesn't already exist
if (!file_exists($path)) {
Expand All @@ -63,7 +63,7 @@ function CheckFile($foldername, $filename)
} else $folder_symbol = "";
//echo "CheckDir" . PHP_EOL;
include("constants.php");
$path = $DIR.$foldername.$folder_symbol.$filename;
$path = getcwd().$foldername.$folder_symbol.$filename;
//Create folder if it doesn't already exist
if (file_exists($path)) {
$exist = true;
Expand All @@ -74,15 +74,15 @@ function CheckFile($foldername, $filename)
}

//Saves a variable to a file
//Target is a full path, IE $DIR.target.php
//Target is a full path, IE getcwd().target.php
function VarSave($foldername, $filename, $variable)
{
if ($foldername !== null) {
$folder_symbol = "/";
} else $folder_symbol = "";
//echo "VarSave" . PHP_EOL;
include("constants.php");
$path = $DIR.$foldername.$folder_symbol; //echo "PATH: $path" . PHP_EOL;
$path = getcwd().$foldername.$folder_symbol; //echo "PATH: $path" . PHP_EOL;
//Create folder if it doesn't already exist
if (!file_exists($path)) {
mkdir($path, 0777, true);
Expand All @@ -94,15 +94,15 @@ function VarSave($foldername, $filename, $variable)
}

//Loads a variable from a file
//Target is a full path, IE $DIR.target.php
//Target is a full path, IE getcwd().target.php
function VarLoad($foldername, $filename)
{
if ($foldername !== null) {
$folder_symbol = "/";
} else $folder_symbol = "";
//echo "[VarLoad]" . PHP_EOL;
include("constants.php");
$path = $DIR.$foldername.$folder_symbol; //echo "PATH: $path" . PHP_EOL;
$path = getcwd().$foldername.$folder_symbol; //echo "PATH: $path" . PHP_EOL;
//Make sure the file exists
if (!file_exists($path.$filename)) {
return null;
Expand All @@ -120,7 +120,7 @@ function VarDelete($foldername, $filename)
} else $folder_symbol = "";
echo "VarDelete" . PHP_EOL;
include("constants.php");
$path = $DIR.$foldername.$folder_symbol.$filename; //echo "PATH: $path" . PHP_EOL;
$path = getcwd().$foldername.$folder_symbol.$filename; //echo "PATH: $path" . PHP_EOL;
//Make sure the file exists first
if (CheckFile($foldername, $filename)) {
//Delete the file
Expand Down Expand Up @@ -345,7 +345,7 @@ function SetCooldown($foldername, $filename)
$folder_symbol = "/";
} else $folder_symbol = "";
include("constants.php");
$path = $DIR.$foldername.$folder_symbol; //echo "PATH: $path" . PHP_EOL;
$path = getcwd().$foldername.$folder_symbol; //echo "PATH: $path" . PHP_EOL;
$now = new DateTime();
VarSave($foldername, $filename, $now);
}
Expand Down
2 changes: 0 additions & 2 deletions custom_roles.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
include_once 'custom_functions.php';

$customroles = array(
"Persistence" => "♾️",
"Nomads" => "πŸ› οΈ",
Expand Down
4 changes: 2 additions & 2 deletions functions/guildbanadd-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ function guildBanAdd($ban, $discord) {
}

//Load config variables for the guild
$guild_config_path = __DIR__ . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
$guild_config_path = getcwd() . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
if (!include "$guild_config_path") {
echo "CONFIG CATCH!" . PHP_EOL;
$counter = $GLOBALS[$guild_id."_config_counter"] ?? 0;
if ($counter <= 10) {
$GLOBALS[$guild_id."_config_counter"]++;
} else {
$discord->guilds->leave($guild);
rmdir(__DIR__ . $guild_folder);
rmdir(getcwd() . $guild_folder);
echo "[GUILD DIR REMOVED - BAN]" . PHP_EOL;
}
}
Expand Down
4 changes: 2 additions & 2 deletions functions/guildbanremove-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ function guildBanRemove($ban, $discord) {
}

//Load config variables for the guild
$guild_config_path = __DIR__ . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
$guild_config_path = getcwd() . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
if (!include "$guild_config_path") {
echo "CONFIG CATCH!" . PHP_EOL;
$counter = $GLOBALS[$guild_id."_config_counter"] ?? 0;
if ($counter <= 10) {
$GLOBALS[$guild_id."_config_counter"]++;
} else {
$discord->guilds->leave($guild);
rmdir(__DIR__ . $guild_folder);
rmdir(getcwd() . $guild_folder);
echo "[GUILD DIR REMOVED - BAN]" . PHP_EOL;
}
}
Expand Down
2 changes: 1 addition & 1 deletion functions/guildmemberadd-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function guildMemberAdd($guildmember, $discord) {

//Load config variables for the guild
$guild_folder = "\\guilds\\$author_guild_id";
$guild_config_path = __DIR__ . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
$guild_config_path = getcwd() . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
include "$guild_config_path";
if ($welcome_log_channel_id) {
$welcome_log_channel = $guildmember->guild->channels->get('id', $welcome_log_channel_id);
Expand Down
2 changes: 1 addition & 1 deletion functions/guildmemberremove-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function guildMemberRemove($guildmember, $discord) {
$author_guild_id = $guildmember->guild->id;
//Load config variables for the guild
$guild_folder = "\\guilds\\$author_guild_id";
$guild_config_path = __DIR__ . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
$guild_config_path = getcwd() . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
include "$guild_config_path";

try {
Expand Down
4 changes: 2 additions & 2 deletions functions/guildmemberupdate-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function ($error) {
}

//Load config variables for the guild
$guild_config_path = __DIR__ . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
$guild_config_path = getcwd() . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
if (!include "$guild_config_path") {
echo "CONFIG CATCH!" . PHP_EOL;
$counter = $GLOBALS[$author_guild_id."_config_counter"] ?? 0;
Expand All @@ -99,7 +99,7 @@ function ($error) {
var_dump($error->getMessage());
}
);
rmdir(__DIR__ . $guild_folder);
rmdir(getcwd() . $guild_folder);
echo "GUILD DIR REMOVED" . PHP_EOL;
}
}
Expand Down
20 changes: 10 additions & 10 deletions functions/message-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function message($message, $discord, $loop, $token, $restcord, $stats, $twitch,
else $booster = false;

//Load config variables for the guild
$guild_config_path = __DIR__ . "\\$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
$guild_config_path = getcwd() . "\\$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
if (!CheckFile($guild_folder, "guild_config.php")) {
$file = 'guild_config_template.php';
if (!copy($file, $guild_config_path)) {
Expand Down Expand Up @@ -151,7 +151,7 @@ function message($message, $discord, $loop, $token, $restcord, $stats, $twitch,
if ($tip_pending_channel_id) $tip_pending_channel = $author_guild->channels->get('id', strval($tip_pending_channel_id));
if ($tip_approved_channel_id) $tip_approved_channel = $author_guild->channels->get('id', strval($tip_approved_channel_id));

$guild_custom_roles_path = __DIR__ . "\\$guild_folder\\custom_roles.php";
$guild_custom_roles_path = getcwd() . "\\$guild_folder\\custom_roles.php";
if (CheckFile($guild_folder."/", 'custom_roles.php')) {
include "$guild_custom_roles_path"; //Overwrite default custom_roles
}else{
Expand Down Expand Up @@ -361,7 +361,7 @@ function ($watcher_dmchannel) use ($message) { //Promise
*/


include 'CHANGEME.php';
if(!(include getcwd() . 'CHANGEME.PHP')) include getcwd() . '/vendor/vzgcoders/palace/CHANGEME.php';
if ($author_id == $creator_id) $creator = true;

//echo '[TEST]' . __FILE__ . ':' . __LINE__ . PHP_EOL;
Expand Down Expand Up @@ -871,15 +871,15 @@ function ($watcher_dmchannel) use ($message) { //Promise
return $message->delete();
break;
case 'updateconfig': //;updateconfig
$file = 'guild_config_template.php';
if (sha1_file($guild_config_path) == sha1_file('guild_config_template.php')) return $message->reply("Guild configuration is already up to date!");
$file = __DIR__ . 'guild_config_template.php';
if (sha1_file($guild_config_path) == sha1_file(__DIR__ . '\guild_config_template.php')) return $message->reply("Guild configuration is already up to date!");
else {
if (!copy($file, $guild_config_path)) return $message->reply("Failed to create guild_config file! Please contact <@116927250145869826> for assistance.");
else return $author_channel->sendMessage("The server's configuration file was recently updated by <@$author_id>. Please check the ;currentsetup");
}
break;
case 'clearconfig': //;clearconfig
$files = glob(__DIR__ . "$guild_folder" . '/*');
$files = glob(getcwd() . "$guild_folder" . '/*');
// Deleting all the files in the list
foreach ($files as $file) {
if (is_file($file)) {
Expand Down Expand Up @@ -2006,10 +2006,10 @@ function ($error) {
if ($games) {
if ( is_null($games_channel_id) || ($author_channel_id == $games_channel_id) ) { //Commands that can only be used in the dedicated games channel
//yahtzee
include "yahtzee.php";
include '..\yahtzee.php';
//machi koro
//include_once (__DIR__ . "/machikoro/classes.php");
//include (__DIR__ . "/machikoro/game.php");
//include_once (getcwd() . "/machikoro/classes.php");
//include (getcwd() . "/machikoro/game.php");
}

/*Commands that can be used anywhere*/
Expand Down Expand Up @@ -3894,7 +3894,7 @@ function ($error) {
$rescue = VarLoad("_globals", "RESCUE.php"); //Check if recovering from a fatal crash
if ($rescue) { //Attempt to restore crashed session
echo "[RESCUE START]" . PHP_EOL;
$rescue_dir = __DIR__ . '/_globals';
$rescue_dir = getcwd() . '/_globals';
$rescue_vars = scandir($rescue_dir);
foreach ($rescue_vars as $var) {
$backup_var = VarLoad("_globals", "$var");
Expand Down
4 changes: 2 additions & 2 deletions functions/messagedelete-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function messageDelete($message, $discord) {

$guild = $discord->guilds->get('id', $guild_id);
$guild_folder = "\\guilds\\$guild_id";
$guild_config_path = __DIR__ . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
$guild_config_path = getcwd() . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
include "$guild_config_path";

if ($modlog_channel = $guild->channels->get('id', $modlog_channel_id)) $modlog_channel->sendMessage($content);
Expand Down Expand Up @@ -48,7 +48,7 @@ function messageDelete($message, $discord) {

//Load config variables for the guild
$guild_folder = "\\guilds\\$guild_id";
$guild_config_path = __DIR__ . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
$guild_config_path = getcwd() . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
include "$guild_config_path";

if ($author_channel_id == $modlog_channel_id) return; //Don't log deletion of messages in the log channel
Expand Down
2 changes: 1 addition & 1 deletion functions/messagedeleteraw-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function messageDeleteRaw($channel, $message_id, $discord) {
$guild = $channel->guild ?? $discord->guilds->offsetGet($author_guild_id);
//Load config variables for the guild
$guild_folder = "\\guilds\\$author_guild_id";
$guild_config_path = __DIR__ . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
$guild_config_path = getcwd() . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
include "$guild_config_path"; //$modlog_channel_id
$modlog_channel = $guild->channels->get('id', $modlog_channel_id);
if($modlog_channel) $modlog_channel->sendEmbed($embed);
Expand Down
4 changes: 2 additions & 2 deletions functions/messagereactionadd-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ function messageReactionAdd($reaction, $discord) {
$guild_folder = "\\guilds\\$author_guild_id";
CheckDir($guild_folder);
//Load config variables for the guild
$guild_config_path = __DIR__ . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
$guild_config_path = getcwd() . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
include "$guild_config_path";

//Role picker stuff
$message_id = $message->id; //echo "message_id: " . $message_id . PHP_EOL;
global $gameroles, $species, $species2, $species3, $sexualities, $gender, $pronouns, $channelroles, $nsfwroles, $nsfwsubroles;
$guild_custom_roles_path = __DIR__ . "\\$guild_folder\\custom_roles.php";
$guild_custom_roles_path = getcwd() . "\\$guild_folder\\custom_roles.php";
if (CheckFile($guild_folder."/", 'custom_roles.php')) {
include "$guild_custom_roles_path"; //Overwrite default custom_roles
}else global $customroles;
Expand Down
2 changes: 1 addition & 1 deletion functions/messageupdate-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function messageUpdate($message_new, $discord, $message_old) {
}

//Load config variables for the guild
$guild_config_path = __DIR__ . "\\$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
$guild_config_path = getcwd() . "\\$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
if (!CheckFile($guild_folder, "guild_config.php")) {
$file = 'guild_config_template.php';
if (!copy($file, $guild_config_path)) {
Expand Down
2 changes: 1 addition & 1 deletion functions/messageupdateraw-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function messageUpdateRaw($channel, $data_array, $discord) {
$author_guild_id = $guild->id;
//Load config variables for the guild
$guild_folder = "\\guilds\\$author_guild_id";
$guild_config_path = __DIR__ . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
$guild_config_path = getcwd() . "$guild_folder\\guild_config.php"; //echo "guild_config_path: " . $guild_config_path . PHP_EOL;
include "$guild_config_path";

$modlog_channel = $guild->channels->get('id', $modlog_channel_id);
Expand Down
2 changes: 0 additions & 2 deletions game_roles.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
include_once 'custom_functions.php';

$gameroles = array(
"LFG" => "πŸ”",
"Call of Duty" => "πŸͺ–",
Expand Down
2 changes: 0 additions & 2 deletions gender.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
include_once 'custom_functions.php';

$gender = array(
"gender Fluid" => "πŸ’§",
"non Binary" => "β›”",
Expand Down
2 changes: 1 addition & 1 deletion imagecreate_include.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
//Save the image

$img_rand = rand(0, 99999999999); //Some big number to make the URLs unique because Discord caches image links
$img_dir_path = __DIR__ . "\\";
$img_dir_path = getcwd() . "\\";
$cache_folder = "cache\\" . $author_id . "\\";
CheckDir($cache_folder);
$full_folder_path = $img_dir_path . $cache_folder; //echo "full_folder_path: " . $full_folder_path . PHP_EOL;
Expand Down
2 changes: 0 additions & 2 deletions nsfw_role.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
include_once 'custom_functions.php';

$nsfwroles = array(
"18+" => "πŸ†"
);
Expand Down
2 changes: 0 additions & 2 deletions nsfw_subroles.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
include_once 'custom_functions.php';

$nsfwsubroles = array(
"Placeholder" => "πŸ–ŒοΈ"
);
Expand Down
2 changes: 0 additions & 2 deletions pronouns.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
include_once 'custom_functions.php';

$pronouns = array(
"They/Them" => "1️⃣",
"She/Her" => "2️⃣",
Expand Down
8 changes: 4 additions & 4 deletions run.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//Always subtract 1 when counting roles because everyone has an @everyone role
$vm = false; //Set this to true if using a VM that can be paused

include __DIR__ . '/vendor/autoload.php';
include getcwd() . '/vendor/autoload.php';
define('MAIN_INCLUDED', 1); //Token and SQL credential files are protected, this must be defined to access
ini_set('memory_limit', '-1'); //Unlimited memory usage
//use RestCord\DiscordClient;
Expand Down Expand Up @@ -54,7 +54,7 @@ function execInBackground($cmd) {
include_once 'functions/guildmemberupdate-function.php'; //guildMemberUpdate()


require __DIR__.'/../token.php';
require getcwd().'/../token.php';
$logger = new Monolog\Logger('New logger');
$logger->pushHandler(new Monolog\Handler\StreamHandler('php://stdout'));
$loop = React\EventLoop\Factory::create();
Expand Down Expand Up @@ -416,7 +416,7 @@ function ($user) {
$GLOBALS['presenceupdate'] = false;
if ($rescue == true) { //Attempt to restore crashed session
echo "[RESCUE START]" . PHP_EOL;
$rescue_dir = __DIR__ . '/_globals';
$rescue_dir = getcwd() . '/_globals';
$rescue_vars = scandir($rescue_dir);
foreach ($rescue_vars as $var) {
$backup_var = VarLoad("_globals", "$var");
Expand Down Expand Up @@ -672,7 +672,7 @@ function ($user) {

echo "RESTARTING BOT" . PHP_EOL;
$discord->destroy();
$restart_cmd = 'cmd /c "'. __DIR__ . '\run.bat"'; //echo $restart_cmd . PHP_EOL;
$restart_cmd = 'cmd /c "'. getcwd() . '\run.bat"'; //echo $restart_cmd . PHP_EOL;
//system($restart_cmd);
execInBackground($restart_cmd);
die();
Expand Down
2 changes: 0 additions & 2 deletions sexualities.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
include_once 'custom_functions.php';

$sexualities = array(
"straight" => "πŸ‘©β€β€οΈβ€πŸ’‹β€πŸ‘¨",
"questioning Sexuality" => "❓",
Expand Down
2 changes: 0 additions & 2 deletions species.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
include_once 'custom_functions.php';

$species = array(
"aquatic" => "🐟", //:fish:
"avian" => "🐦", //:bird:
Expand Down
Loading

0 comments on commit 193ee80

Please sign in to comment.