/** * @param $serverHash * @throws \Discord\Exception\InvalidArgumentException */ public function verify($serverHash) { // Get logged in user information $characterInformation = $this->app->characters->getAllByID($_SESSION["characterID"]); $characterInformation["corporation"] = $this->app->corporations->getAllByID($this->app->characters->getAllByID($_SESSION["characterID"])["corporationID"]); $characterInformation["alliance"] = $this->app->alliances->getAllByID($this->app->characters->getAllByID($_SESSION["characterID"])["allianceID"]); $characterInformation["groups"] = $this->app->UsersGroups->getGroup($this->app->Users->getUserByName($characterInformation["characterName"])["id"]); // Get the discord server information $discordServerInfo = $this->app->discordServers->getAllByServerHash($serverHash); // Allowed Entities $allowedEntities = json_decode($discordServerInfo[0]["allowedEntities"], true); // Is the user allowed on this Discord server? $allowed = false; foreach ($characterInformation["groups"] as $group) { foreach ($allowedEntities as $type => $ent) { if ($type == "corporationID") { if (in_array($group["groupID"], $ent)) { $allowed = true; } } if ($type == "allianceID") { if ($group["groupID"] == $ent) { $allowed = true; } } } } // User is allowed if ($allowed) { $authString = md5($serverHash . md5($characterInformation["characterName"])); $this->app->discordUsers->insertIntoDiscordUsers($this->app->discordServers->getServerIDByServerHash($serverHash), $this->app->Users->getUserByName($characterInformation["characterName"])["id"], $characterInformation["characterID"], $characterInformation["corporationID"], $characterInformation["allianceID"], $authString, date("Y-m-d H:i:s")); $serverName = $this->app->discordServers->getServerNameByServerHash($serverHash); $channelID = $this->discord->api("guild")->channels()->show($this->app->discordServers->getServerIDByServerHash($serverHash))[0]["id"]; $inviteData = $this->discord->api("channel")->invites()->create($channelID, 60 * (mt_rand(1, 500) + 30), 1); // gotta randomize the time, as to create multiple invite links at the same time.. $inviteLink = "https://discord.gg/" . $inviteData["code"]; $authString = "!auth " . $this->db->queryField("SELECT authString FROM discordUsers WHERE serverID = :serverID AND userID = :userID", "authString", array(":serverID" => $this->app->discordServers->getServerIDByServerHash($serverHash), ":userID" => $this->app->Users->getUserByName($characterInformation["characterName"])["id"])); render("discord/authenticated.twig", array("serverName" => $serverName, "inviteLink" => $inviteLink, "authString" => $authString)); } else { $this->app->redirect("/"); } }
* This file is part of cleanse/discord-hypertext package. * * (c) 2015-2015 Paul Lovato <*****@*****.**> * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ error_reporting(-1); require __DIR__ . '/../vendor/autoload.php'; $dotenv = new Dotenv\Dotenv(__DIR__); $dotenv->load(); use Discord\Discord; use Discord\Helpers\Mentions; // Email/Password for Discord $email_address = getenv('DISCORD_EMAIL'); $password = getenv('DISCORD_PASSWORD'); // Try log into Discord! $discord = new Discord($email_address, $password); $channelId = '105775765877989376'; echo '<pre>'; $messages = $discord->api('message')->get($channelId); // Script start $time1 = microtime(true); $mentions = new Mentions($discord); foreach ($messages as $message) { echo '<b>' . $message['author']['username'] . '</b> ' . $mentions->addMentions($message) . '<br>'; } // Script end $time2 = microtime(true); echo "script execution time: " . ($time2 - $time1); //value in seconds
// Try log into Discord! $discord = new Discord($email_address, $password); $permissions = new Permissions(); //pass in null if you want the role to have zero permissions $color = new RoleColors(); /* * By default a role is created with the following permissions: * Read Messages, Send Messages, Send TTS Messages, Embed Links, * Attach Files, Read Message History, Mention Everyone * Voice Connect, Voice Speak, Use Voice Activity * Create Instant Invite * * Let's revoke the user's ability to create instant invites and send TTS messages... */ $permissions->setCreateInstantInvite(false); $permissions->setSendTTSMessages(false); echo '<pre>'; echo 'Look good? <br>'; print_r($permissions->listPermissions()); echo '<br>'; echo 'Here\'s the code we feed to the method: ' . $permissions->finalPermissions() . '<br>'; /* * If that looks good, pass the $permissions var into the create / edit role. */ $guildId = '105775765877989376'; //you need to change this! ## $name = 'Cool Buds'; $color = $color->darkRed; $hoist = true; print_r($discord->api('role')->create($guildId, $name, $permissions->finalPermissions(), $color, $hoist));