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') mostRecentMentionRepliedTo = '' while True: mostRecentMention = mastodon.notifications(types = "mention")[0].status.content if mostRecentMention == mostRecentMentionRepliedTo: time.sleep(15) continue mostRecentMentionRepliedTo = mostRecentMention cleanTags = re.compile('<.*?>') tweetWithoutTags = re.sub(cleanTags, '', mostRecentMention) #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) 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) #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 = mentionTag + ' mentioned me and said: "' + tweetWithoutMention.strip() + '". Here\'s my dream about that!' mastodon.status_post(status = message, media_ids = mediaId)