Example #1
0
 public function run()
 {
     $explode = explode(" ", $this->message->content);
     unset($explode[0]);
     $query = urlencode(implode(" ", $explode));
     $appID = urlencode($this->config->get("appID", "wolframalpha"));
     // WTB JSON endpoint...
     $data = json_decode(json_encode(new \SimpleXMLElement($this->curl->get("http://api.wolframalpha.com/v2/query?appid={$appID}&input={$query}"))), true);
     $result = $data["pod"][1]["subpod"];
     if (!empty($result)) {
         $image = $result["img"]["@attributes"]["src"];
         $text = $result["plaintext"];
         if (strlen($image) > 0) {
             $this->message->reply("{$text}\r\n {$image}");
             $wolfFileName = md5($query);
             file_put_contents(__DIR__ . "/../../../cache/image/{$wolfFileName}.gif", $image);
             $this->message->getChannelAttribute()->sendFile(__DIR__ . "/../../../cache/image/{$wolfFileName}.gif", "{$wolfFileName}.gif");
         } else {
             $this->message->reply("Result: {$image}");
         }
     } else {
         $this->message->reply("WolframAlpha did not have an answer to your query..");
     }
     // Mark this as garbage
     $this->isGarbage();
 }
Example #2
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();
 }
Example #3
0
 public function run(Message $message, Discord $discord, WebSocket $webSocket, Logger $log, &$audioStreams, Channel $channel, cURL $curl)
 {
     $exp = explode(" ", $message->content);
     unset($exp[0]);
     $youtubeLink = implode(" ", $exp);
     // URL Checker
     $parts = parse_url($youtubeLink);
     if (!stristr($parts["host"], "youtube.com")) {
         return $message->reply("Error, you can only use youtube links!");
     }
     // Generate song md5
     $md5 = md5($youtubeLink);
     // Now get the mp3 from the cache
     $songFile = __DIR__ . "/../../../../../cache/songs/{$md5}.mp3";
     $dl = new YoutubeDl(["extract-audio" => true, "audio-format" => "mp3", "audio-quality" => 0, "output" => $songFile]);
     $title = "";
     try {
         $video = $dl->download($youtubeLink);
         $title = $video->getTitle();
         $log->addNotice("Downloading {$title} from YouTube");
     } catch (NotFoundException $e) {
         $log->addError("Error: the song was not found: {$e->getMessage()}");
         $message->reply("Error: the song was not found: {$e->getMessage()}");
     } catch (PrivateVideoException $e) {
         $log->addError("Error: song has been made private: {$e->getMessage()}");
         $message->reply("Error: song has been made private: {$e->getMessage()}");
     } catch (CopyrightException $e) {
         $log->addError("Error: song is under copyright: {$e->getMessage()}");
         $message->reply("Error: song is under copyright: {$e->getMessage()}");
     } catch (\Exception $e) {
         $log->addError("Error: {$e->getMessage()}");
         $message->reply("Error: {$e->getMessage()}");
     }
     $webSocket->joinVoiceChannel($channel)->then(function (VoiceClient $vc) use($message, $discord, $webSocket, $log, &$audioStreams, $channel, $curl, $songFile, $title) {
         $guildID = $message->getChannelAttribute()->guild_id;
         if (file_exists($songFile)) {
             // Add this audio stream to the array of audio streams
             $audioStreams[$guildID] = $vc;
             $vc->setFrameSize(40)->then(function () use($vc, &$audioStreams, $guildID, $songFile, $log, $message, $title, $channel) {
                 $vc->setBitrate(128000);
                 $message->reply("Now playing **{$title}** in {$channel->name}");
                 $vc->playFile($songFile, 2)->done(function () use($vc, &$audioStreams, $guildID) {
                     unset($audioStreams[$guildID]);
                     $vc->close();
                 });
             });
         }
     });
 }
Example #4
0
 public function run(Message $message, Discord $discord, WebSocket $webSocket, Logger $log, &$audioStreams, Channel $channel, cURL $curl)
 {
     $webSocket->joinVoiceChannel($channel)->then(function (VoiceClient $vc) use($message, $discord, $webSocket, $log, &$audioStreams, $channel) {
         $guildID = $message->getChannelAttribute()->guild_id;
         // Add this audio stream to the array of audio streams
         $audioStreams[$guildID] = $vc;
         $vc->setFrameSize(40)->then(function () use($vc, &$audioStreams, $guildID) {
             $vc->setBitrate(128000);
             $number = mt_rand(1, 6);
             $file = __DIR__ . "/../../../sounds/horns/{$number}.mp3";
             $vc->playFile($file, 2)->done(function () use($vc, &$audioStreams, $guildID) {
                 unset($audioStreams[$guildID]);
                 $vc->close();
             });
         });
     });
 }
Example #5
-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);
         }
     }
 }