Skip to content

A Python script enabling intelligent Twitter interactions through advanced AI models, utilizing the Twikit library for seamless integration with Twitter's API. Enhance engagement with contextually relevant responses, leveraging the latest AI advancements for effective automation.

License

Notifications You must be signed in to change notification settings

lord-dubious/Twitter-AI-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Twitter-AI-BOT

Introduction

Twitter AI Twikit Bot is a Python script enabling intelligent interactions on Twitter by leveraging advanced AI models. It utilizes the Twikit library for seamless integration with Twitter's API, allowing users to enhance engagement through contextually relevant responses generated by cutting-edge AI technologies. gimme a star

Features

  • Automated replies to tweets from specified usernames.
  • AI-generated responses for contextually relevant interactions.
  • Rate limit handling to avoid exceeding Twitter API limits.
  • State persistence for tracking replied tweets and the current user.
  • Cookie-based authentication for efficient session management.
  • Ability to like and retweet tweets for increased engagement.

Prerequisites

  • Python 3.8 or higher
  • aiohttp library
  • twikit library
  • Access to an AI endpoint for response generation (e.g., OpenAI's GPT-3.5)
  • Twitter developer account for API access

Installation

  1. Install the required Python libraries:
    pip install aiohttp twikit
  2. Clone the repository or download main.py to your local machine.

Configuration

  1. Replace the USERNAME, EMAIL, and PASSWORD variables in main.py with your Twitter account information.

    USERNAME = "your_twitter_username"
    EMAIL = "[email protected]"
    PASSWORD = "your_twitter_password"
  2. Customize the AI endpoint request headers with your API key and host information. You can also modify the payload data and endpoint to use different AI models. Here's an example:

    # Example 1:
    headers = {
        "content-type": "application/json",
        "X-RapidAPI-Key": "your_api_key",
        "X-RapidAPI-Host": "your_api_host"
    }
    
    # Example 2:
    data = {
        "model": "gpt-3.5-turbo",
        "temperature": 0.7,
        "max_tokens": 100,
        "messages": [
            {"role": "system", "content": instructions},
            {"role": "user", "content": tweet_content}
        ],
    }
    
    endpoint = "https://app.oxyapi.uk/v1/chat/completions"
    
    headers = {
        "Content-Type": "application/json",
        "Authorization": "Bearer your_api_token",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)",
    }
  3. Update the usernames_to_search list with the Twitter usernames you want to search and reply to.

    usernames_to_search = ["username1", "username2", "username3"]
  4. Modify the instructions.txt file to hold any instructions or guidelines for AI-generated responses. For example:

    - Reply to every tweet with emojis 😄🚀🎉
    - Talk like a baby 👶
    

Usage

  1. Run the bot by executing the following command in your terminal:

    python3 main.py
  2. The bot will start searching for tweets from the specified usernames and reply to them with AI-generated responses.

Rate Limit Handling

The script includes a rate limit handling mechanism that checks if the number of requests made to a particular endpoint has reached the limit. If so, it will wait until the rate limit is reset before continuing.

State Persistence

The bot saves its state to a JSON file (state.json) to keep track of which tweets have been replied to and which user is currently being processed. This allows the bot to resume where it left off in case of a restart or crash.

Cookie-based Authentication

The bot uses cookie-based authentication to avoid repeated logins. It saves the cookies to a file (cookies.json) after the first successful login and reuses them for subsequent sessions.

Liking and Retweeting

The bot can also like and retweet tweets for increased engagement. It includes functions like_tweet() and retweet_tweet() to facilitate this functionality.

Contributing

Contributions to the bot are welcome! If you have any suggestions for improvements or encounter any issues, please open an issue or submit a pull request.

License

This project is open-source and available under the MIT License.

Disclaimer

This bot uses an unofficial Twitter API. Please use it responsibly and in compliance with Twitter's terms of service. Excessive use may lead to your account being banned.

About

A Python script enabling intelligent Twitter interactions through advanced AI models, utilizing the Twikit library for seamless integration with Twitter's API. Enhance engagement with contextually relevant responses, leveraging the latest AI advancements for effective automation.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages