2022-12-15 19:31:12 -05:00
|
|
|
#!/usr/bin/python3
|
|
|
|
import argparse
|
|
|
|
import pyszuru
|
|
|
|
import requests
|
|
|
|
import random
|
|
|
|
from misskey import Misskey
|
2023-01-27 19:04:22 -05:00
|
|
|
from misskey import NoteVisibility
|
2022-12-15 19:31:12 -05:00
|
|
|
|
|
|
|
# arguments
|
|
|
|
parser = argparse.ArgumentParser(prog='misskey-szuru-bot',
|
|
|
|
description='Bot that posts a link to a random szurubooru image')
|
|
|
|
|
|
|
|
parser.add_argument('-i', '--instance', metavar='instance', type=str,
|
|
|
|
help='Domain of misskey instance i.e: misskey.io', required=True)
|
|
|
|
parser.add_argument('-t', '--token', metavar='token', type=str,
|
|
|
|
help='Token used for posting to misskey instance', required=True)
|
|
|
|
parser.add_argument('-b', '--booru', metavar='booru', type=str,
|
|
|
|
help='Domain of szurubooru instance to query i.e: szurubooru.com', required=True)
|
|
|
|
parser.add_argument('-u', '--username', metavar='username', type=str,
|
|
|
|
help='Username for szurubooru account', required=True)
|
|
|
|
parser.add_argument('-a', '--apiKey', metavar='apiKey', type=str,
|
|
|
|
help='API key for szurubooru account', required=True)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# get truly random post
|
|
|
|
booru = pyszuru.API(f"https://{args.booru}", username=args.username, token=args.apiKey)
|
|
|
|
highest_post = next(booru.search_post("sort:id", page_size=1))
|
|
|
|
post = booru.getPost(random.randint(0, highest_post.id_))
|
|
|
|
|
|
|
|
# compose note
|
|
|
|
text = f"link: {post.content}"
|
|
|
|
if post.safety == "unsafe":
|
|
|
|
text += " (nsfw)"
|
|
|
|
text += f"\nsource: https://{args.booru}/post/{post.id_}"
|
|
|
|
|
|
|
|
# post a note :D
|
2023-01-27 19:04:22 -05:00
|
|
|
Misskey(args.instance, i=args.token).notes_create(
|
|
|
|
text=text,
|
|
|
|
visibility=NoteVisibility.HOME
|
|
|
|
)
|