From d50b3e2ef52e032ef1a55b2f40e219b89f5f5ce7 Mon Sep 17 00:00:00 2001 From: TimRuswick <31260618+TimRuswick@users.noreply.github.com> Date: Tue, 16 Oct 2018 20:52:26 -0500 Subject: [PATCH] Add files via upload --- PHPBotServer/functions.php | 197 +++++++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 PHPBotServer/functions.php diff --git a/PHPBotServer/functions.php b/PHPBotServer/functions.php new file mode 100644 index 0000000..3e39464 --- /dev/null +++ b/PHPBotServer/functions.php @@ -0,0 +1,197 @@ += 1){ + $lvl = $lvlbase * sqrt($xp);; + } else{ + $lvl = 0; + } + + //Returns level based total # of xp + return $lvl; +} +/* +function getLevel($xp,$lvlbase){ + if($xp >= 1){ + $lvl = log($xp,$lvlbase); + } else{ + $lvl = 0; + } + + //Returns level based total # of xp + return $lvl; +} +*/ + + +function getCurrentLevelProgress($xp,$lvl){ + + $baseLevel = floor($lvl); + $levelDecimal = $lvl - $baseLevel; + + $percentage = $levelDecimal*100; + $fullNumber = 100; + + $actualPercentage = floor(($percentage / 100) * $fullNumber); + + //Returns progress in percentage + return $actualPercentage; +} +/* + + +function getXp($lvl,$lvlbase){ + + $xp = floor(pow($lvlbase,ceil($lvl)) - pow($lvlbase,floor($lvl))); + + //Returns xp needed from start to finish to complete current level + return $xp; +} + +function getAllXp($lvl,$lvlbase){ + + + $xp = pow($lvlbase,floor($lvl)); + //Returns # of xp required to reach current level + return $xp; +} +function getCurrentLevelProgress($xp,$lvl,$lvlbase){ + + $xpInCurrentLevel = getXp($lvl,$lvlbase); + $totalXpRequiredForCurrentLevel = getAllXp($lvl,$lvlbase); + $xpTowardNextLevel = $xp - $totalXpRequiredForCurrentLevel; + + if($xpInCurrentLevel > 0){ + $xpProgress = round(($xpTowardNextLevel / $xpInCurrentLevel)*100,1); + }else{ + $xpProgress = 1; + } + + //Returns progress in percentage + return $xpProgress; +} +*/ + + +function addXp($uid,$xpamount){ + $con = mysqlConnect(); + $q = "UPDATE users SET xp=(xp + $xpamount) WHERE discordUserID = '$uid'"; + $r = mysqli_query($con,$q); +} +function getLevelBase(){ + return 1.2; +} + +function full_url() +{ + $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; + $sp = strtolower($_SERVER["SERVER_PROTOCOL"]); + $protocol = substr($sp, 0, strpos($sp, "/")) . $s; + $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); + return $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI']; +} +// CLASS FOR CONVERTING TIME TO AGO +class convertToAgo { + + function convert_datetime($str) { + + list($date, $time) = explode(' ', $str); + list($year, $month, $day) = explode('-', $date); + list($hour, $minute, $second) = explode(':', $time); + $timestamp = mktime($hour, $minute, $second, $month, $day, $year); + return $timestamp; + } + + function makeAgo($timestamp){ + + $difference = time() - $timestamp; + $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade"); + $lengths = array("60","60","24","7","4.35","12","10"); + for($j = 0; $difference >= $lengths[$j]; $j++) + $difference /= $lengths[$j]; + $difference = round($difference); + if($difference != 1) $periods[$j].= "s"; + if ( (($periods[$j] == "minute") or ($periods[$j] == "minutes") && ($difference < 3)) + or (($periods[$j] == "second") or ($periods[$j] == "seconds")) ){ + $text = "Just now"; + } else { + $text = "$difference $periods[$j] ago"; + } + return $text; + } + +} // END CLASS + + +function checkArrayFor($array, $key, $val) { + foreach ($array as $item) + if (isset($item[$key]) && $item[$key] == $val) + return true; + return false; +} + + + +function addhttp($url) { + if ($url != ''){ + if (!preg_match("~^(?:f|ht)tps?://~i", $url)) { + $url = "http://" . $url; + } + } + return $url; +} + + + +function mysqlConnect() { + $dbhost = 'INSERT DB HOST'; + $dbusername = 'INSERT DB USERNAME'; + $dbpassword = 'INSERT DB PASSWORD'; + $dbtable = 'INSERT DB TABLE'; + + $userDB = 'user'; + $userdataDB = 'userdata'; + $memberDB = 'member'; + $memberdataDB = 'memberdata'; + + $con = mysqli_connect($dbhost,$dbusername,$dbpassword,$dbtable); + if (!$con) { die('Could not connect: ' . mysqli_error());} + mysqli_select_db($con, "$dbtable")or die("cannot select DB"); + return $con; +} + +?>