├── .gitignore ├── DevRant.php ├── LICENSE.md ├── README.md ├── index.php ├── newYear.php ├── newYearBot.php ├── quoteids.json ├── quotes.json └── randomQuoteBot.php /.gitignore: -------------------------------------------------------------------------------- 1 | # Storing which quotes have already been sent. Useless to upload because it will be created automatically 2 | quoteids.json 3 | 4 | # Ugly written quote scraper 5 | scrapeQuotes.php 6 | 7 | # All quotes. Won't upload to GitHub 8 | quotes.json 9 | 10 | # IDEs (switched to PHPStorm afterwards lol) 11 | .vscode 12 | .idea 13 | -------------------------------------------------------------------------------- /DevRant.php: -------------------------------------------------------------------------------- 1 | 3, 12 | "plat" => 3, 13 | "username" => $username, 14 | "password" => $password 15 | ]; 16 | 17 | // Make data useable for request 18 | $postdata = http_build_query($postdata); 19 | 20 | $url = 'https://devrant.com/api/users/auth-token'; 21 | 22 | // Curl options 23 | $curl = curl_init($url); 24 | curl_setopt($curl, CURLOPT_POST, 1); 25 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); 26 | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); 27 | curl_setopt($curl, CURLOPT_HEADER, 0); 28 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 29 | 30 | // Execute curl and get response 31 | $response = json_decode(curl_exec($curl), true); 32 | curl_close($curl); 33 | 34 | $this->token_id = $response["auth_token"]["id"]; 35 | $this->token_key = $response["auth_token"]["key"]; 36 | $this->user_id = $response["auth_token"]["user_id"]; 37 | 38 | return $response; 39 | } 40 | 41 | function postRant($msg, $tags) { 42 | // The data to send 43 | $postdata = [ 44 | "app" => 3, 45 | "rant" => $msg, 46 | "tags" => $tags, 47 | "token_id" => $this->token_id, 48 | "token_key" => $this->token_key, 49 | "user_id" => $this->user_id 50 | ]; 51 | 52 | // Make data useable for request 53 | $postdata = http_build_query($postdata); 54 | $url = 'https://devrant.com/api/devrant/rants'; 55 | 56 | // Curl options 57 | $curl = curl_init($url); 58 | curl_setopt($curl, CURLOPT_POST, 1); 59 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); 60 | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0); 61 | curl_setopt($curl, CURLOPT_HEADER, 0); 62 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 63 | 64 | // Execute curl and get response 65 | $response = curl_exec($curl); 66 | curl_close($curl); 67 | return $response; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Skayo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # random-quote-bot 2 | 3 | [![License](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE.md) 4 | [![Quotes](http://skayo.lima-city.de/Shields/devRantBot.php?type=quotes)](https://www.devrant.io/users/RandomQuote) 5 | [![Score](http://skayo.lima-city.de/Shields/devRantBot.php?type=score)](https://www.devrant.io/users/RandomQuote) 6 | 7 | A devRant bot that posts random quotes every day! 8 | 9 | > **Note** 10 | > This project was originally created by [@skayo](https://github.com/skayo), but he has decided to transfer it to the devRant-Community organization. 11 | 12 | 13 | ## Requirements 14 | 15 | - PHP 5.6 16 | - A lot of energy and willpower 17 | 18 | 19 | ## Directory Structure 20 | 21 | . 22 | ├── DevRant.php # Little helper class for accessing the devRant API 23 | ├── index.php # Executes random quote bot, used by cronjob 24 | ├── newYear.php # Executes new year bot, used by cronjob (new year message from @RandomQuote user) 25 | ├── newYearBot.php # Class for the new year bot (new year message from @RandomQuote user) 26 | ├── randomQuoteBot.php # Class for the random quote bot 27 | ├── .gitignore 28 | ├── LICENSE.md 29 | └── README.md 30 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | run(); 9 | 10 | ?> 11 | -------------------------------------------------------------------------------- /newYear.php: -------------------------------------------------------------------------------- 1 | run(); 9 | 10 | ?> 11 | -------------------------------------------------------------------------------- /newYearBot.php: -------------------------------------------------------------------------------- 1 | devRant = new DevRant(); 18 | 19 | // Login 20 | $this->devRant->login($username, $password); 21 | } 22 | 23 | function run() { 24 | /* Main function */ 25 | 26 | // Post quote 27 | $this->devRant->postRant($this->newYearMsg, "New Year"); 28 | } 29 | } -------------------------------------------------------------------------------- /quoteids.json: -------------------------------------------------------------------------------- 1 | [] 2 | -------------------------------------------------------------------------------- /randomQuoteBot.php: -------------------------------------------------------------------------------- 1 | store); 22 | $this->quoteids = json_decode($json, true); 23 | 24 | // Get all quotes 25 | $this->quotes = json_decode(file_get_contents($this->quotesFile), true); 26 | 27 | // New DevRant object 28 | $this->devRant = new DevRant(); 29 | 30 | // Login 31 | $this->devRant->login($username, $password); 32 | } 33 | 34 | function run() { 35 | /* Main function */ 36 | 37 | // Get quote 38 | $quote = $this->getQuotes(); 39 | 40 | // Post quote 41 | $this->devRant->postRant($quote, "Random Quote"); 42 | } 43 | 44 | function getQuotes() { 45 | // Get the next quote 46 | $quoteNum = $this->nextQuote(); 47 | $quotedata = $this->quotes[$quoteNum]; 48 | 49 | // Save quote ID 50 | array_push($this->quoteids, $quoteNum); 51 | $this->saveRespostIDs(); 52 | 53 | // Clean quote 54 | $quotedata["quote"] = str_replace(['“', '”', '"'], "'", $quotedata["quote"]); 55 | 56 | // Format the quote 57 | $quotemsg = "\"{$quotedata["quote"]}\" - {$quotedata["author"]}"; 58 | 59 | // Return the data 60 | return $quotemsg; 61 | } 62 | 63 | function nextQuote() { 64 | return count($this->quoteids); 65 | } 66 | 67 | function saveRespostIDs() { 68 | // Encode to JSON 69 | $json = json_encode($this->quoteids); 70 | 71 | // Save to file 72 | file_put_contents($this->store, $json); 73 | } 74 | } 75 | 76 | ?> 77 | --------------------------------------------------------------------------------