Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
Improved command detection
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisMayo committed Jul 3, 2021
1 parent d1c895e commit beb5539
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ def postVideoTweet(reply_id, filename):
def check_mentions():
global lastId
global mention_queue
global render_regex
while True:
try:
mentions = api.mentions_timeline(count='200', tweet_mode="extended") if lastId == None else api.mentions_timeline(since_id=lastId, count='200', tweet_mode="extended")
if len(mentions) > 0:
lastId = mentions[0].id_str
for tweet in mentions[::-1]:
if 'render' in tweet.full_text:
if re.search(render_regex, tweet.full_text) is not None:
mention_queue.put(tweet)
print(mention_queue.qsize())
if 'delete' in tweet.full_text:
Expand Down Expand Up @@ -106,7 +107,7 @@ def process_tweets():
try:
current_tweet = api.get_status(current_tweet.in_reply_to_status_id_str or current_tweet.quoted_status_id_str, tweet_mode="extended")
# Refusing to render zone
if 'render' in current_tweet.full_text and any(user['id_str'] == me for user in current_tweet.entities['user_mentions']):
if re.search(render_regex, current_tweet.full_text) is not None and any(user['id_str'] == me for user in current_tweet.entities['user_mentions']):
api.update_status('@' + tweet.author.screen_name + ' I\'m sorry. Calling the bot several times in the same thread is not allowed', in_reply_to_status_id=tweet.id_str)
break
if sanitize_tweet(current_tweet):
Expand Down Expand Up @@ -199,7 +200,9 @@ def clean(thread, output_filename, files):
auth = tweepy.OAuthHandler(keys['consumerApiKey'], keys['consumerApiSecret'])
auth.set_access_token(keys['accessToken'], keys['accessTokenSecret'])
api = tweepy.API(auth)
me = api.me().id_str
me_response = api.me()
render_regex = f'^@{me_response.screen_name} render ?$'
me = me_response.id_str
producer = threading.Thread(target=check_mentions)
consumer = threading.Thread(target=process_tweets)
threading.Thread(target=process_tweets).start()
Expand Down

0 comments on commit beb5539

Please sign in to comment.