Allow specification of several messages to choose from

This commit is contained in:
dotnet 2023-10-13 14:36:59 -04:00
parent b6b158580a
commit fade3c20fc
2 changed files with 10 additions and 4 deletions

View File

@ -40,7 +40,7 @@ Usage: python3 gelbooru-bot.py [--gen-config] [--help]
"hololive_images": { "hololive_images": {
"gelbooru_tags": "hololive", "gelbooru_tags": "hololive",
"gelbooru_tags_exclude": "-sky", "gelbooru_tags_exclude": "-sky",
"bot_message": "Hololive Image", "bot_message": ["Hololive Image", "Uooooh"],
"bot_hashtags": "#hololive", "bot_hashtags": "#hololive",
"misskey_token": "uuuu0hOhrrrlrlrP8888uquqaaaaAUAU", "misskey_token": "uuuu0hOhrrrlrlrP8888uquqaaaaAUAU",
"max_page_number": 200, "max_page_number": 200,

View File

@ -158,7 +158,10 @@ class BotInstance:
post_json = post_request.json() post_json = post_request.json()
if 'id' in post_json: if 'id' in post_json:
# Submit a /notes/create request to Misskey # Submit a /notes/create request to Misskey
msg = self.bot_message if isinstance(self.bot_message, list):
msg = random.choice(self.bot_message)
else:
msg = self.bot_message
if random.randint(0, 100) < 5: if random.randint(0, 100) < 5:
msg += " " + self.bot_hashtags msg += " " + self.bot_hashtags
create_note_request = requests.post(self.misskey_url + "notes/create", json = {"renoteId": post_json['id'], "text": "%s\n[Source](%s)\n" % (msg, image_src), "i": self.misskey_token}) create_note_request = requests.post(self.misskey_url + "notes/create", json = {"renoteId": post_json['id'], "text": "%s\n[Source](%s)\n" % (msg, image_src), "i": self.misskey_token})
@ -168,7 +171,10 @@ class BotInstance:
return True return True
# Submit a /notes/create request to Misskey # Submit a /notes/create request to Misskey
msg = self.bot_message if isinstance(self.bot_message, list):
msg = random.choice(self.bot_message)
else:
msg = self.bot_message
if random.randint(0, 100) < 5: if random.randint(0, 100) < 5:
msg += " " + self.bot_hashtags msg += " " + self.bot_hashtags
create_note_request = requests.post(self.misskey_url + "notes/create", json = {"fileIds": [file_id], "text": "%s\n[Source](%s)\n" % (msg, image_src), "i": self.misskey_token}) create_note_request = requests.post(self.misskey_url + "notes/create", json = {"fileIds": [file_id], "text": "%s\n[Source](%s)\n" % (msg, image_src), "i": self.misskey_token})
@ -218,7 +224,7 @@ def generate_defaults():
config['gelbooru_tags'] = 'rating:safe' config['gelbooru_tags'] = 'rating:safe'
config['gelbooru_tags_exclude'] = '' config['gelbooru_tags_exclude'] = ''
config['bot_message'] = 'Random image from Gelbooru' config['bot_message'] = ['Random image from Gelbooru']
config['bot_hashtags'] = '#gelbooru #random' config['bot_hashtags'] = '#gelbooru #random'
config['misskey_url'] = 'https://misskey.example.com/' config['misskey_url'] = 'https://misskey.example.com/'
config['misskey_token'] = '' config['misskey_token'] = ''