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
- 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.
- 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
- Install the required Python libraries:
pip install aiohttp twikit
- Clone the repository or download
main.py
to your local machine.
-
Replace the
USERNAME
,EMAIL
, andPASSWORD
variables inmain.py
with your Twitter account information.USERNAME = "your_twitter_username" EMAIL = "[email protected]" PASSWORD = "your_twitter_password"
-
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)", }
-
Update the
usernames_to_search
list with the Twitter usernames you want to search and reply to.usernames_to_search = ["username1", "username2", "username3"]
-
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 👶
-
Run the bot by executing the following command in your terminal:
python3 main.py
-
The bot will start searching for tweets from the specified usernames and reply to them with AI-generated responses.
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.
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.
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.
The bot can also like and retweet tweets for increased engagement. It includes functions like_tweet()
and retweet_tweet()
to facilitate this functionality.
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.
This project is open-source and available under the MIT License.
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.