private function main_menu() { $DbUser = new User($this->db); $group_chats = $DbUser->getActiveChatsByUser($this->Message->User); $Vote = new Vote($this->db); $popularity = $Vote->getVoteTotalForUser($this->Message->User); $ranking = Query::getGlobalRanking($this->db, $this->Message->User); $this->out = emoji(0x1f44b) . " Hi *" . $this->Message->User->getName() . "*!" . "\nI'm *" . BOT_FRIENDLY_NAME . "*, your _Premier Shitposting Solution_ " . emoji(0x2122) . "." . "\n\n" . emoji(0x1f481) . emoji(0x1f3fb) . "You're a " . $this->Message->User->getLevelAndTitle() . " with `" . $this->Message->User->getBalance() . "` Coin." . "\nOverall, your popularity is at *{$popularity}* points, and you're ranked *" . addOrdinalNumberSuffix($ranking) . "* on the global leaderboard."; $this->out .= "\n\n*This menu system is currently under development and may be incomplete/broken. You've been warned!*"; if ($group_chats) { $this->out .= "\n\nI see you in the following group chats:"; foreach ($group_chats as $chat) { $this->out .= "\n` `• `" . $chat->title . "`"; } } $this->out .= "\n\nWhat would you like?"; $this->keyboard = [[['text' => emoji(0x2754) . ' Help', 'callback_data' => '/help help'], ['text' => emoji(0x1f4bc) . ' Business', 'callback_data' => '/help business']], [['text' => emoji(0x1f3ae) . ' Play a game', 'callback_data' => '/help games'], ['text' => emoji(0x2699) . ' Change preferences', 'callback_data' => '/preferences']]]; }
public function main() { $Transact = new Transact($this->db); if ($this->noParams() == 2) { $user_receiving = Query::getUserMatchingStringOrErrorMessage($this->db, $this->Message->Chat, $this->getParam()); if (is_string($user_receiving)) { Telegram::talk($this->Message->Chat->id, $user_receiving); return false; } $Transaction = new Transaction($this->Message->User, $user_receiving, $this->getParam(1), new TransactionType(TransactionType::Manual)); $Transact->performTransaction($Transaction); if ($Feedback = $Transact->Feedback->getFeedback()) { $out = emoji("0x1F4E2") . " " . $Feedback . "\n` `• `" . $user_receiving->getName() . "` now has 💰*" . $user_receiving->getBalance() . "*" . "\n` `• `You've` got 💰*" . $this->Message->User->getBalance() . "* left."; if ($user_receiving->user_id != -1) { $out .= "\n` `• `The Bank` took 2%, or 💰*" . round($this->getParam(1) * 0.02, 2) . "*"; } Telegram::talk($this->Message->Chat->id, $out); } else { Telegram::talk($this->Message->Chat->id, "I'm so sorry brah..."); } } else { Telegram::talk($this->Message->Chat->id, "Like this fam " . emoji("0x1F449") . " /send richardstallman 10"); } return true; }
public function main() { if ($this->isParam()) { $user = Query::getUserMatchingStringOrErrorMessage($this->db, $this->Message->Chat, $this->getParam()); if (is_string($user)) { Telegram::talk($this->Message->Chat->id, $user); return false; } Telegram::talk($this->Message->Chat->id, $user->getNameLevelAndTitle() . " has " . emoji("0x1F4B0") . "*" . $user->getBalance() . "*, brah"); } else { Telegram::talk($this->Message->Chat->id, "You've got " . emoji("0x1F4B0") . "*" . $this->Message->User->getBalance() . "*, brah"); } return true; }
/** * @return User[]|bool */ private function getUsers() { $ascending = false; $no_users = 10; if ($this->isParam()) { if ($this->contains($this->getAllParams(), ['global', 'all', 'every'])) { $this->chat = NULL; $this->global = true; } if ($this->contains($this->getAllParams(), ['bottom', 'last'])) { $ascending = true; } } return Query::getUsersByLevel($this->db, $this->chat, true, $ascending, $no_users); //return Query::getUsersByMoneyAndLevel($this->db, $this->chat, true, $ascending, $no_users); }
public function main() { $Level = new \GroupBot\Brains\Level\Level(); if ($this->isParam()) { $user = Query::getUserMatchingStringOrErrorMessage($this->db, $this->Message->Chat, $this->getParam()); if (is_string($user)) { $out = $user; } else { $out = emoji(0x1f4ef) . " Make way for " . $user->getNameLevelAndTitle() . "!"; } } else { $user = $this->Message->User; $out = emoji(0x1f4ef) . " Greetings " . $user->getNameLevelAndTitle() . "." . "\nYou may rise to level " . ($user->level + 1) . " for a price of " . $Level->getLevelPrice($user->level + 1) . " Coin." . "\nPlease use /buylevel to do this."; } Telegram::talk($this->Message->Chat->id, $out); }
private function performVote() { if (isset($this->chat)) { $user = Query::getUserMatchingStringOrErrorMessage($this->db, $this->chat, $this->getParam(0)); } else { $user = Query::getUserMatchingStringOrErrorMessage($this->db, $this->Message->Chat, $this->getParam(0)); } if (is_string($user)) { return $user; } if (strcasecmp($this->getParam(0), BOT_FRIENDLY_NAME) === 0) { return "wow, thx brah! " . emoji(0x1f618); } if (!$user) { return emoji(0x1f44e) . " Can't find that user, brah"; } if ($user->user_id == $this->Message->User->user_id) { return emoji(0x1f44e) . " You can't vote for yourself!"; } switch ($this->getParam(1)) { case 'up': $voteType = new VoteType(VoteType::Up); break; case 'down': $voteType = new VoteType(VoteType::Down); break; case 'neutral': $voteType = new VoteType(VoteType::Neutral); break; default: return emoji(0x1f44e) . " Your vote must be either *up*, *down* or *neutral*."; } $DbUser = new \GroupBot\Database\User($this->db); $voted_for = $DbUser->getUserFromId($user->user_id); $userVote = new UserVote(); $userVote->construct($this->Message->User, $voted_for, $voteType); $Vote = new \GroupBot\Brains\Vote\Vote($this->db); if ($Vote->SQL->check_if_vote_exists($userVote)) { $this->vote_cast = true; return emoji(0x1f528) . " Vote unchanged - you've voted this way before!"; } $Vote->SQL->update_vote($userVote); $this->vote_cast = true; $rank = $Vote->getVoteTotalForUserInChat($userVote->voted_for, $this->Message->Chat->id); $vote_prefix = $rank > 0 ? "+" : ""; return emoji(0x1f528) . " Vote updated. *" . $userVote->voted_for->getName() . "* is now on *{$vote_prefix}{$rank}*"; }
public static function getGlobalRanking(\PDO $db, \GroupBot\Types\User $user) { $leaderboard = Query::getUsersByMoneyAndLevel($db, NULL, true, false); foreach ($leaderboard as $key => $usr) { if ($usr->user_id == $user->user_id) { return $key + 1; } } return false; }
private function poorbonuses() { $total_coin = $this->Transact->CoinSQL->getTotalCoinExisting(false); $total_users = $this->UserSQL->GetTotalNumberOfUsers(false); $average_coin = $total_coin / $total_users; $Users = Query::getUsersByMoneyAndLevel($this->db, NULL, false, false); $Users = $this->filterUsersByLastActivity($Users); /** @var User[] $PoorestUsers */ $PoorestUsers = array(); foreach ($Users as $User) { if ($User->getBalance(true) < $average_coin) { $PoorestUsers[] = $User; } } $bank = $this->UserSQL->getUserFromId(COIN_BANK_ID); $to_give = $bank->getBalance(true) * COIN_POOR_BONUS / count($PoorestUsers); $this->Transact->removeMoney($bank, $bank->getBalance(true) * COIN_POOR_BONUS); foreach ($PoorestUsers as $User) { $this->Transact->addMoney($User, $to_give); $User->save($this->db); } $this->Transact->maintainFixedLevel($bank); $bank->save($this->db); Telegram::customShitpostingMessage(emoji(0x1f4e2) . " Oh happy day! " . round($bank->getBalance() * COIN_POOR_BONUS, 2) . " of " . COIN_TAXATION_BODY . "'s wealth has been spread amongst the poorest members of the community."); return true; }