Misskey websocketAPI wrapper.
Project description
BromineCore
ぶろみねくんのコア部分の実装、misskeyのwebsocketAPI単体の実装です。
ローカルのノートを講読したり、通知を取得したり。リバーシbotも頑張れば実装できます。
何か問題が発生したり追加してほしい機能があったらissueに書いてください
頑張って実装したり解決します
Example
簡単なタイムライン閲覧クライアントです。
トークン無しでタイムラインをリアルタイムで閲覧できます。
import asyncio
from brcore import Bromine, enum
INSTANCE = "misskey.io"
TL = enum.MisskeyChannelNames.LOCAL_TIMELINE
TL_ARGS = enum.MisskeyChannelArgs.LocalTimeline() # 実際のところ引数はいらないので、空の辞書になっている
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}がノート ノートid: {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)
async def note_async(note: dict) -> None:
"""上のprinterの引数を調整するやつ
asyncにするのはws_connectでは非同期関数が求められるので(見た目非同期っていう体にしているだけ)"""
note_printer(note["body"])
print() # 空白をノート後に入れておく
async def main() -> None:
brm = Bromine(instance=INSTANCE)
brm.ws_connect(TL, note_async, **TL_ARGS)
print("start...")
await brm.main()
if __name__ == "__main__":
try:
asyncio.run(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.1.tar.gz
(11.9 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.1-py3-none-any.whl
(12.2 kB
view details)
File details
Details for the file brominecore-1.1.tar.gz.
File metadata
- Download URL: brominecore-1.1.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bddfb9d5f3e8918c16a8d06be9e2fdafad5ac9aa95fdc1b6b8fdfee8a38a7bb3
|
|
| MD5 |
e63260eaa5e943cb99f0e0ae14a9edf9
|
|
| BLAKE2b-256 |
a8c8090f2e8f05a1280aab515db3bb24580b8563509126891d5a0ff56c0ca4aa
|
File details
Details for the file brominecore-1.1-py3-none-any.whl.
File metadata
- Download URL: brominecore-1.1-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9592d46ed3a0967ea1fea872131e27eef16376ebccbca98025ca0cc7785b9d7c
|
|
| MD5 |
e442624ee86699c437bc2876ab1050a2
|
|
| BLAKE2b-256 |
26ede14a56094aa5ee6971a0c1c3ff6deff82baa8d59d28cc3e8ae9a57b41743
|