Misskey WebsocketAPI wrapper.
Project description
BromineCore
MisskeyのWebsocketAPI単体の実装です。
ノートを講読したり、通知を取得したり。リバーシbotも頑張れば実装できます。
Example
簡単なタイムライン閲覧クライアントです。
トークン無しでタイムラインをリアルタイムで閲覧できます。
import asyncio
from brcore import Bromine, enum
INSTANCE = "misskey.io"
TL = enum.MisskeyChannelNames.LOCAL_TIMELINE
TL_ARGS = enum.MisskeyChannelArgs.LocalTimeline()
brm = Bromine(instance=INSTANCE)
def note_printer(note: dict) -> None:
"""ノートの情報を受け取って描画する関数"""
NOBASIBOU_LENGTH = 20
user = note["user"]
username = user["name"] if user["name"] is not None else user["username"]
print("-"*NOBASIBOU_LENGTH)
if note.get("renoteId") and note["text"] is None:
# リノートのときはリノート先だけ書く
print(f"{username}がリノート")
note_printer(note["renote"])
# リノートはリアクション数とか書きたくないので
# ここで返す
print("-"*NOBASIBOU_LENGTH)
return
else:
# 普通のノート
print(f"{username}が投稿しました。 noteid: {note['id']}")
if note.get("reply"):
# リプライがある場合
print("リプライ:")
note_printer(note["reply"])
if note.get("text"):
# 本文
print("テキスト:")
print(note["text"])
if note.get("renoteId"):
# 引用
print("引用:")
note_printer(note["renote"])
if len(note["files"]) != 0:
# ファイルがある時
print(f"ファイル数: {len(note['files'])}")
# リアクションとかを書く
print(f"リプライ数: {note['repliesCount']}, リノート数: {note['renoteCount']}, リアクション数: {note['reactionCount']}")
reactions = []
for reactionid, val in note["reactions"].items():
if reactionid[-3:] == "@.:":
# ローカルのカスタム絵文字のidはへんなのついてるので消す
reactionid = reactionid[:-3] + ":"
reactions.append(f"({reactionid}, {val})")
if len(reactions) != 0:
print("リアクション: ", ", ".join(reactions))
print("-"*NOBASIBOU_LENGTH)
@brm.ws_connect_deco(TL, **TL_ARGS)
async def note_async(note: dict) -> None:
note_printer(note["body"])
print() # 空白をノート後に入れておく
# デコレータを使わない場合は、下のように書くこともできる
# brm.ws_connect(TL, note_async, **TL_ARGS)
if __name__ == "__main__":
try:
print("start...")
asyncio.run(brm.main())
except KeyboardInterrupt:
print("fin")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
brominecore-1.2.tar.gz
(11.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
brominecore-1.2-py3-none-any.whl
(11.9 kB
view details)
File details
Details for the file brominecore-1.2.tar.gz.
File metadata
- Download URL: brominecore-1.2.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2131b0b47c3d2a1c4b48c0bc427b55abcd288e8f880b7860bb1bb1e2e0b876a3
|
|
| MD5 |
262fc0ab817d69cceba2a42d4f72b701
|
|
| BLAKE2b-256 |
9b60ecf9d25a34eb8588a08ed52cc40a2d086ada87d90b108ec9194e319b0f41
|
File details
Details for the file brominecore-1.2-py3-none-any.whl.
File metadata
- Download URL: brominecore-1.2-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8619e7b5842078aa40b3204db917119905822b37ef5634d1e0756e1b502d1e6e
|
|
| MD5 |
766ea0c2233046aa6538b5bccd99c924
|
|
| BLAKE2b-256 |
34cc81092ef18e799fedb91cdcf9429c3bf5501fbdf02ced5b8eacc774f0b290
|