コード例 #1
0
ファイル: apocalypse.php プロジェクト: squaredcircle/GroupBot
 private function losePopularity()
 {
     $this->out .= "\n" . emoji(0x1f465) . " Sickening groans surround you, as corpses rise from the earth. ";
     $Vote = new Vote($this->db);
     $DbUser = new User($this->db);
     $users_in_chat = $DbUser->getAllUsersInChat($this->Message->Chat->id);
     foreach ($users_in_chat as $user) {
         if ($user->user_id != $this->Message->User->user_id) {
             $userVote = new UserVote();
             $userVote->construct($user, $this->Message->User, new VoteType(VoteType::Down));
             $Vote->SQL->update_vote($userVote);
         }
     }
     $this->out .= "\n*" . $this->Message->User->getName() . "*, you become very unpopular. ";
 }
コード例 #2
0
ファイル: vote.php プロジェクト: squaredcircle/GroupBot
 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}*";
 }