grapemane 1 年之前
父節點
當前提交
6ba075987b
共有 1 個文件被更改,包括 15 次插入16 次删除
  1. 15 16
      masto.py

+ 15 - 16
masto.py

@@ -24,26 +24,31 @@ 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)
 
     cleanMention = re.compile('@developer(@noc\.social)*')
     tweetWithoutMention = re.sub(cleanMention, '', tweetWithoutTags)
     
     cleanTweet = re.sub(r'[^a-zA-Z0-9 ]', '', tweetWithoutMention)
 
-
     rawInput = cleanTweet.strip()[:45]
 
     print(rawInput)
@@ -55,17 +60,11 @@ 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)
 
     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)