예제 #1
0
 public function run()
 {
     $explode = explode(" ", $this->message->content);
     $authString = isset($explode[1]) ? $explode[1] : "";
     if ($this->message->getChannelAttribute()->is_private) {
         return $this->message->reply("**Error** You are trying to send your auth token in private. This won't work because i need the guild information, which i can only get if you post it in a public channel on the server you want to get authed on.");
     }
     $authData = $this->db->queryRow("SELECT * FROM authRegs WHERE authString = :authString AND active = 1", array(":authString" => $authString));
     if ($authData) {
         $groups = json_decode($authData["groups"], true);
         $characterID = $authData["characterID"];
         /** @var Role $roles */
         $roles = $this->message->getFullChannelAttribute()->getGuildAttribute()->getRolesAttribute();
         /** @var Member $member */
         $member = $this->message->getFullChannelAttribute()->getGuildAttribute()->getMembersAttribute()->get("id", $this->message->author->id);
         $username = $this->message->author->username;
         $discordID = $this->message->author->id;
         // @todo Force ingame name
         $characterName = json_decode($this->curl->get("https://evedata.xyz/api/character/shortinformation/{$characterID}/"))->characterName;
         // Doesn't work yet, but it should be something like $member->nick($characterName);
         //$member->user->setAttribute("username", $characterName);
         /** @var Role $role */
         foreach ($roles as $role) {
             $roleName = $role->name;
             if (in_array($roleName, $groups)) {
                 $member->addRole($role);
             }
         }
         // Save the member object, so all the roles are set
         $member->save();
         $this->db->execute("UPDATE authRegs SET discordID = :discordID, active = 0 WHERE authString = :authString", array(":discordID" => $discordID, ":authString" => $authString));
         $this->log->addInfo("{$username} authenticated in {$this->message->getChannelAttribute()->name} on {$this->message->getChannelAttribute()->getGuildAttribute()->name}");
         $this->message->reply("You have now been added to the following groups: " . implode(", ", $groups));
     } else {
         $this->message->reply("**Error** You are trying to authenticate with an already used (or not existing) auth token..");
     }
     // Mark this as garbage
     $this->isGarbage();
 }
예제 #2
-1
 /**
  *
  */
 public function run()
 {
     $guildID = $this->message->getFullChannelAttribute()->guild_id;
     $cleverBotNick = $this->db->queryField("SELECT nick FROM cleverbot WHERE serverID = :serverID", "nick", array(":serverID" => $guildID));
     // Simply remove the <id> part of the string, since it seems to make the responses from Cleverbot be less idiotic and terrible..
     $msg = str_replace("<@{$this->discord->getClient()->id}>", "", $this->message->content);
     $response = $this->curl->post("https://cleverbot.io/1.0/ask", array("user" => $this->config->get("user", "cleverbot"), "key" => $this->config->get("key", "cleverbot"), "nick" => $cleverBotNick, "text" => $msg));
     if ($response) {
         $resp = @json_decode($response);
         $reply = isset($resp->response) ? $resp->response : false;
         if ($reply) {
             $this->message->getChannelAttribute()->broadcastTyping();
             $this->message->reply($reply);
         }
     }
 }