2 Commits ed2c214d42 ... 5ffe527b72

Auteur SHA1 Message Date
  grapemane 5ffe527b72 Merge branch 'master' of git.teets.us:grapemane/MastodonDreamBot il y a 1 an
  grapemane 6ba075987b refactor il y a 1 an
1 fichiers modifiés avec 15 ajouts et 16 suppressions
  1. 15 16
      masto.py

+ 15 - 16
masto.py

@@ -24,19 +24,25 @@ mastodon.log_in(
 
 mastodon = Mastodon(access_token = 'grapeapp_usercred.secret')
 
-mostRecentMentionRepliedTo = ''
+mostRecentlyHandledMention = ''
 
 while True:
-    mostRecentMention = mastodon.notifications(types = "mention")[0].status.content
+    mostRecentMention = mastodon.notifications(types = "mention")[0]
 
-    if mostRecentMention == mostRecentMentionRepliedTo:
+    if mostRecentMention.status.content == mostRecentlyHandledMention:
         time.sleep(15)
         continue
 
-    mostRecentMentionRepliedTo = mostRecentMention
+    mostRecentlyHandledMention = mostRecentMention.status.content
+
+    if mostRecentMention.status.in_reply_to_id != None:
+        time.sleep(15)
+        continue
+    
+    mostRecentMentionContent = mostRecentMention.status.content
 
     cleanTags = re.compile('<.*?>')
-    tweetWithoutTags = re.sub(cleanTags, '', mostRecentMention)
+    tweetWithoutTags = re.sub(cleanTags, '', mostRecentMentionContent)
 
     #put your bot's name and domain on the next line
     cleanMention = re.compile('@developer(@noc\.social)*')
@@ -45,7 +51,6 @@ while True:
     
     cleanTweet = re.sub(r'[^a-zA-Z0-9 ]', '', tweetWithoutMention)
 
-
     rawInput = cleanTweet.strip()[:45]
 
     print(rawInput)
@@ -57,18 +62,12 @@ while True:
 
     print(folderName)
 
-
-    mentionerUrl = mastodon.notifications(types = "mention")[0].status.account.url
-    cleanProtocol = re.compile('https*:\/\/')
-    cleanedUrl = re.sub(cleanProtocol, '', mentionerUrl)
-    urlParts = cleanedUrl.split("/")
-    mentionTag = urlParts[1] + '@' + urlParts[0]
-    print(mentionTag)
+    mentionerTag = '@' + mostRecentMention.status.account.acct
+    print(mentionerTag)
 
     #put the file path for your stable diffusion output on the next line
     mediaId = mastodon.media_post(media_file = 'C:\\Users\\bigd\\Downloads\\stable-diffusion-main\\stable-diffusion-main\\outputs\\txt2img-samples\\' + folderName + '\\seed_28_00000.png', mime_type = 'image/png')
 
+    message = mentionerTag + ' mentioned me and said: "' + tweetWithoutMention.strip() + '". Here\'s my dream about that!'
 
-    message = mentionTag + ' mentioned me and said: "' + tweetWithoutMention.strip() + '". Here\'s my dream about that!'
-
-    mastodon.status_post(status = message, media_ids = mediaId)
+    mastodon.status_post(in_reply_to_id = mostRecentMention.status, status = message, media_ids = mediaId)