Created
September 3, 2023 16:00
-
-
Save backgr02/81c5ab6e758f4972c26729062e78a105 to your computer and use it in GitHub Desktop.
Misskey.io で「おはよー!」リアクションの自動実行コード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import os | |
import time | |
from misskey import Misskey | |
from misskey.exceptions import MisskeyAPIException | |
def lambda_handler(event, context): | |
print(json.dumps(event)) | |
print(context) | |
run() | |
return { | |
'statusCode': 200, | |
'body': json.dumps('Hello from Lambda!') | |
} | |
def run(): | |
count = 0 | |
count = count + reactToSearchedNotes(query='ohayo') | |
count = count + reactToSearchedNotes(query='おはよう') | |
count = count + reactToSearchedNotes(query='oyasu') | |
count = count + reactToSearchedNotes(query='おやすみ') | |
print(f"count: {count}") | |
def reactToSearchedNotes(query) -> int: | |
mk = Misskey( | |
address="misskey.io", | |
i=os.environ['MISSKEY_TOKEN'], | |
) | |
notes = mk.notes_search(query=query, limit=100) | |
count = reactToNotes(notes) | |
return count | |
def reactToNotes(notes) -> int: | |
count = 0 | |
for note in notes: | |
if ('myReaction' not in note): | |
if ((':ohayoo@.:' in note['reactions'])): | |
count = count + reactToNote(note, ':ohayoo:') | |
elif ((':oyasumisskey@.:' in note['reactions'])): | |
count = count + reactToNote(note, ':oyasumisskey:') | |
return count | |
def reactToNote(note, reaction) -> int: | |
count = 0 | |
mk = Misskey( | |
address="misskey.io", | |
i=os.environ['MISSKEY_TOKEN'], | |
) | |
# print(json.dumps(note, indent = 2)) | |
try: | |
# print(note['text']) | |
mk.notes_reactions_create(note['id'], reaction) | |
count = count + 1 | |
time.sleep(0.5) | |
except MisskeyAPIException as e: | |
print(f"{type(e)} {e}") | |
return count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment