from mastodon import Mastodon import re import os import time # Register your app! This only needs to be done once (per server, or when # distributing rather than hosting an application, most likely per device and server). # Uncomment the code and substitute in your information: ''' Mastodon.create_app( 'grapeapp', api_base_url = 'https://YOUR_MASTODON_BASE_URL/', to_file = 'grapeapp_clientcred.secret' ) ''' mastodon = Mastodon(client_id = 'grapeapp_clientcred.secret',) mastodon.log_in( 'ENTER_YOUR_MASTODON_USERNAME', 'ENTER_YOUR_MASTODON_PASSWORD', to_file = 'grapeapp_usercred.secret' ) mastodon = Mastodon(access_token = 'grapeapp_usercred.secret') mostRecentlyHandledMention = '' while True: mostRecentMention = mastodon.notifications(types = "mention")[0] if mostRecentMention.status.content == mostRecentlyHandledMention: time.sleep(15) continue 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, '', mostRecentMentionContent) #put your bot's name and domain on the next line 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) os.system('python stable.py "' + rawInput + '"') cleanSpaces = re.compile(' ') folderName = re.sub(cleanSpaces, '_', rawInput) print(folderName) 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!' mastodon.status_post(in_reply_to_id = mostRecentMention.status, status = message, media_ids = mediaId)