This commit is contained in:
commit
9bb2964032
6
.dockerignore
Normal file
6
.dockerignore
Normal file
@ -0,0 +1,6 @@
|
||||
.drone.yml
|
||||
.gitignore
|
||||
.tool-versions
|
||||
crontab
|
||||
crontab.example
|
||||
docker-compose.yml
|
44
.drone.yml
Normal file
44
.drone.yml
Normal file
@ -0,0 +1,44 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: misskey-szuru-bot
|
||||
|
||||
steps:
|
||||
- name: build and publish stable
|
||||
image: thegeeklab/drone-docker-buildx
|
||||
privileged: true
|
||||
settings:
|
||||
repo: shibaobun/misskey-szuru-bot
|
||||
purge: true
|
||||
compress: true
|
||||
platforms: linux/amd64,linux/arm/v7
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
tags: latest
|
||||
when:
|
||||
branch:
|
||||
- stable
|
||||
|
||||
- name: build and publish tagged version
|
||||
image: thegeeklab/drone-docker-buildx
|
||||
privileged: true
|
||||
settings:
|
||||
repo: shibaobun/misskey-szuru-bot
|
||||
purge: true
|
||||
compress: true
|
||||
platforms: linux/amd64,linux/arm/v7
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
tags:
|
||||
- ${DRONE_TAG}
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
|
||||
volumes:
|
||||
- name: docker_sock
|
||||
host:
|
||||
path: /var/run/docker.sock
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
crontab
|
1
.tool-versions
Normal file
1
.tool-versions
Normal file
@ -0,0 +1 @@
|
||||
python 3.11.1
|
9
Dockerfile
Normal file
9
Dockerfile
Normal file
@ -0,0 +1,9 @@
|
||||
FROM python:3.11.1-alpine3.17
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
COPY . .
|
||||
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
RUN chmod +x entrypoint.sh
|
||||
ENTRYPOINT ["./entrypoint.sh"]
|
1
crontab.example
Normal file
1
crontab.example
Normal file
@ -0,0 +1 @@
|
||||
0 * * * * cd /usr/src/app && /usr/local/bin/python misskey-szuru-bot.py --instance misskey.io --booru szurubooru.com --username my-username --apiKey my-api-key --token token >/proc/1/fd/1 2>&1
|
9
docker-compose.yml
Normal file
9
docker-compose.yml
Normal file
@ -0,0 +1,9 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
misskey-szuru-bot:
|
||||
image: shibaobun/misskey-szuru-bot
|
||||
container_name: misskey-szuru-bot
|
||||
restart: always
|
||||
volumes:
|
||||
- ./crontab:/usr/src/app/crontab
|
4
entrypoint.sh
Normal file
4
entrypoint.sh
Normal file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
set -ou pipefail
|
||||
|
||||
crontab ./crontab && crond -f
|
37
misskey-szuru-bot.py
Normal file
37
misskey-szuru-bot.py
Normal file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/python3
|
||||
import argparse
|
||||
import pyszuru
|
||||
import requests
|
||||
import random
|
||||
from misskey import Misskey
|
||||
|
||||
# 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
|
||||
Misskey(args.instance, i=args.token).notes_create(text=text)
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Misskey.py
|
||||
requests
|
||||
pyszuru
|
Loading…
Reference in New Issue
Block a user