Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Respond to replies when the bot is mentioned (asyncio introduction) #7

Open
n0toose opened this issue Apr 11, 2020 · 4 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@n0toose
Copy link
Owner

n0toose commented Apr 11, 2020

Currently, the bot only posts tweets every once in a while and does not interact with any users in any capacity.

Wouldn't it be a great idea for people to be able to get their virtual flowers whenever they need them? The bot should monitor and detect replies and then react to them by responding with a newly generated flower bed.

Here's some documentation on how to update your status on Twitter. Take note of the optional in_reply_to_status_id parameter!

However, that's the easy part. The harder part would be finding the status IDs (the large numbers that appear in the URL bar when opening tweets) that correspond to the replies that the bot gets. Wouldn't it be simpler if there was a way to just fetch all the tweets in your notifications or maybe search for those that contain the username of the bot?

Well, I guess that there's a way. With tweepy, you can use the Stream API of Twitter. You can just create a listener that tracks for specific words and the bot will be able to respond to requests for flower beds across the Twitterverse!

Before you proceed with this issue, here are a few things to note:

  • Make sure to use the asynchronous version of the listener. That way, the part of the bot that responds to replies can run simultaneously with that part that waits for a specific time interval before making the next tweet!

  • There's a problem with the current version of the bot. The bot is not currently meant to be running asynchronously! However, due to the way that the bot is structured, it should be quite easy to rewrite the parts that cannot possibly support that, so that they can run simulatenously with other processes. Also, the function time.sleep() will block the execution of the bot entirely, so for example, if you set a listener to run alongside the part that waits for a few days before tweeting again, time.sleep() will block the listener! Here's a great introductory tutorial that may help you out:

  • Python sleep(): How to Add Time Delays to Your Code - Mike Driscoll

  • Getting Started With Async Features in Python - Doug Farroll

  • Async IO in Python: A Complete Walkthrough - Brad Solomon

  • Since these changes are going to be relatively large, it would be a very good idea to create an entirely separate Twitter account for this and test it out for yourself. You will need a Twitter account with developer privileges on it-- you can use your main account and then create a throwaway one after you get accepted, it doesn't matter. You can gain access to Twitter's developer platform here. There's also a tutorial by Ian Anderson Gray which can be found here.

If you do make some progress with this, feel free to open a pull request before finishing it for good, in order for me to be able to provide feedback and any necessary corrections. Don't worry about the number of commits-- I will squash all your changes before merging them to the upstream version of the project.

@n0toose n0toose added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Apr 11, 2020
@n0toose
Copy link
Owner Author

n0toose commented Apr 11, 2020

@fantoro You may be interested in taking this one. :D

@Shankhanil
Copy link
Contributor

This seems pretty cool. Can I give it a try? @AlwaysLivid

@n0toose
Copy link
Owner Author

n0toose commented Apr 15, 2020

Can I give it a try?

Hey @Shankhanil, excuse me for the delay, but please give me some time to work on the other issue first. I'll try my best to give you the green light until tomorrow.

@Shankhanil
Copy link
Contributor

Shankhanil commented Apr 15, 2020 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants