You are viewing our Forum Archives. To view or take place in current topics click here.
Trolling Twitter Bot
Posted:

Trolling Twitter BotPosted:

CoNdEmR
  • Retired Staff
Status: Offline
Joined: Apr 29, 200915Year Member
Posts: 4,420
Reputation Power: 1211
Status: Offline
Joined: Apr 29, 200915Year Member
Posts: 4,420
Reputation Power: 1211
So, i got this idea after browsing through CLK's github. He wrote a ruby bot script to troll @gabe_k. So i thought i'd take a swing and see if i could make my own version, only in PHP.

The following could do with a lot of cleaning up, and lacks some functionality that you'll see in CLK's original. But it works. Have a gander and see what you guys can come up with.

<?php
error_reporting(E_ALL);
require 'tmhOAuth.php'; // require twitter auth file

# Use the data from http://dev.twitter.com/apps to fill out this info
# Notice the slight name difference in the last two items)

$connection = new tmhOAuth(array(
  'consumer_key' => '', # Your consumer key
   'consumer_secret' => '', # Your consumer secret
   'user_token' => '', # Access token
   'user_secret' => '' # Access token secret
));

# Set up parameters to pass
$parameters = array();
$funnies = array(
      "#gay",
      "#GodILoveMyself",
      "#****",
      "#IHateDrinking",
      "#ImTerribleAtCoding",
      "#damn",
      "#IrXXCONDEMRXX",
      "#BotsAreMyLife",
      "#CianIsGod",
      "#SoSexy"
   );

# Limit the number of tweets we want to GET
if (!isset($_GET['count'])) {
   $parameters['count'] = 50;
}

# Set the account we want to get them from
if (!isset($_GET['screen_name'])) {
   $parameters['screen_name'] = '_broconut';
}

if ($_GET['twitter_path']) { $twitter_path = $_GET['twitter_path']; }  else {
   $twitter_path = '1.1/statuses/user_timeline.json';
}

$http_code = $connection->request('GET', $connection->url($twitter_path), $parameters );

if ($http_code === 200) { // if everything's good
   $response = $connection->response['response'];

   $data = json_decode($response);
   # Randomize the tweets so we're not always getting the most recent one
   shuffle($data);

   /* Dev Shit
      echo '<pre>';
      print_r($data);
      echo '</pre>';
   */
   $text = $data[0]->text;
   $string = $data[0]->id . "\n";
   $file = 'tweet_log.txt';
   $id = 0;

   if(file_exists($file)){
      # Store the last tweet ID
      $data = fopen($file, 'w') or die('Can\'t open file');
      # Write it to our file
      fwrite($data, $string);
      fclose($data);
   }

   if(filesize($file) == 0){
      $tweet_id = fopen($file, 'w');
      fwrite($tweet_id, '339831779923988480');
      fclose($tweet_id);
   } else {
      $tweet = fopen($file, 'r');
      $id = fread($tweet, 18);
      fclose($tweet);
   }

   if($string > $id && mb_strlen($text) < 115){
      # Check for the length of the text of the tweet
      $tweet_text = "As @_broconut would say, " . $text;
      shuffle($funnies);
      $max_string = mb_strlen($text);
      $max_string = $max_string - 115;
      echo 'Max String' . $max_string . '<br />';
      if(mb_strlen($tweet_text) < 140){
         echo $tweet_text . " " . $funnies[0];

         if(!empty($tweet_text)){
            if (!isset($_GET['status'])) {
               $parameters['status'] = $tweet_text. " " . $funnies[0];
            }

            $twitter_path = '1.1/statuses/update.json';
            
            # Ensure your application has both read and write access
            $http_code = $connection->request('POST', $connection->url($twitter_path), $parameters );

            if ($http_code === 200) { // if everything's good
               $response = $connection->response['response'];
               echo '<br>Sent';
            } else {
               echo '<br />';
               echo "Error ID: ",$http_code, "<br>\n";
               echo "Error: ",$connection->response['error'], "<br>\n";
               echo 'Not Sent';

            }
         }

      } else {
         $other_tweet = "@_broconut " . $text . " " . $funnies[0];
      }



} else {
   echo '<br />';
   echo "Error ID: ",$http_code, "<br>\n";
   echo "Error: ",$connection->response['error'], "<br>\n";

   }

}


[ Register or Signin to view external links. ]

The following 1 user thanked CoNdEmR for this useful post:

Scizor (08-03-2013)
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.